CharlesStamp Posted May 28, 2015 Posted May 28, 2015 (edited) Hi. I've managed to piece this script together from tutorials and examples I've found, but I've hit a dead-end and could use a little help. I'm trying to create a script that will transfer text from a specific page onto an Excel worksheet. According to what I've read, it should enter 'pizza' into cel A3 of an Excel worksheet, and 'developer' into cel A4.expandcollapse popup#include <Array.au3> #include <Excel.au3> #Include <FF.au3> #include <String.au3> ; Go to page and copy the source to clipboard. If _FFStart("http://ff-au3-example.thorsten-willert.de/") Then $sHTML = _FFReadHTML() If Not @error Then ClipPut($sHTML) EndIf Example() Func Example() ; Declare variables and set to the words surrounding "pizza" and "developer". Local $sWordOne = _StringBetween($sHTML, "hlen Sie eine ", ":</legend>") Local $sWordTwo = _StringBetween($sHTML, "Mozilla ", " center") ; Create application object and create a new workbook Local $oAppl = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oAppl) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oAppl) Exit EndIf ; ***************************************************************************** ; Write a 1D array to the active sheet in the active workbook ; ***************************************************************************** Global $aArray1D = [$sWordOne, $sWordTwo] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray1D, "A3") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "1D array successfully written.") EndFunc ;==>ExampleBut for some reason, the values of variables $sWordOne and $sWordTwo seem to get deleted before it reaches the Excel page, so the cels just wind up blank. I've double (and triple) checked that the _StringBetween variables are correct when used on their own. I've also found that if I change the variables to integers, it copies them to Excel as it should. I've spent a few hours looking at this and getting nowhere. Am I doing something obviously wrong? Edited May 28, 2015 by CharlesStamp
JohnOne Posted May 28, 2015 Posted May 28, 2015 Do excel cells not have specific types associated with them? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
CharlesStamp Posted May 28, 2015 Author Posted May 28, 2015 (edited) They do, but that doesn't seem to be the issue. If I use a string, integer or combination of them for the variables it passes them to Excel. It also seems to work fine with just one variable, too. But if there's more than one they just go blank. As far as I can tell it should work, but I don't have much experience with this. I had a similar problem displaying them in arrays, too. Edited May 28, 2015 by CharlesStamp
JohnOne Posted May 28, 2015 Posted May 28, 2015 I think what you are passing is a map, not an array. Global $aArray1D[2] = [$sWordOne, $sWordTwo] might solve it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
CharlesStamp Posted May 28, 2015 Author Posted May 28, 2015 I haven't heard about maps before now, but I tried making the change you suggested and the problem now is that it copies $sWordOne to both cels. Again, I get a similar problem when I just display the array, so the issue doesn't seem to be related to Excel or its UDF. It seems to be a problem with how _StringBetween variables are managed.
JohnOne Posted May 28, 2015 Posted May 28, 2015 Global $aArray1D = [$sWordOne[0], $sWordTwo[0]]_StringBetween returns an array. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now