Jump to content

excel read and write function?


Recommended Posts

My version does exactly what you ask for. Can you run this modified version and post the result?

#include <Excel.au3>
#include <IE.au3>
#include <string.au3>

Global $excelfile = "C:\Users\joesoef pc\Desktop\autoit\twitter.xlsx"
Global $oExcel = _ExcelBookOpen($excelfile)

_ExcelWriteCell($oExcel, "username", 1, 1)
_ExcelWriteCell($oExcel, "followers", 1, 4)
_ExcelWriteCell($oExcel, "following", 1, 8)
_ExcelWriteCell($oExcel, "followbacklist3", 3, 1)

Global $aArray1 = _ExcelReadArray($oExcel, 3, 1, 7,1)
ConsoleWrite("Elements: " & $aArray1[0] & @CRLF)
For $i = 1 to $aArray1[0]
    ConsoleWrite("Element: " & $i & @CRLF)
    ConsoleWrite("  User: " & $aArray1[$i] & @CRLF)
    ConsoleWrite("  Row: " & $i & @CRLF)
    _Volgend($aArray1[$i], $i + 2) ;_volgend?
Next
Exit

Func _Volgend($sUser, $iRow)   ;_volgend?

    $oIE = _IECreate("https://twitter.com/" & $sUser)
    $oInput2s = _IETagNameGetCollection($oIE, "a")
    For $oInput2 In $oInput2s
        If $oInput2.className() = "js-nav" Then
            If StringInStr($oInput2.innerHTML(), 'Volgend') Then
                ConsoleWrite(_StringBetween($oInput2.innerHTML(),'>','<')[0] & @CRLF)
                ExitLoop ; I chanced it from "loop" to exitloop
            EndIf
        EndIf
    Next
    $numbvolgers = (_StringBetween($oInput2s.innerHTML(),'>','<')[0] & @CRLF)
    $numbvolgend = (_StringBetween($oInput2.innerHTML(),'>','<')[0] & @CRLF)
    ConsoleWrite(" Value: " & $numbvolgend & @CRLF)
    _ExcelWriteCell ($oExcel, $numbvolgend, $iRow, 3)
EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

 

My version does exactly what you ask for. Can you run this modified version and post the result?

#include <Excel.au3>
#include <IE.au3>
#include <string.au3>

Global $excelfile = "C:\Users\joesoef pc\Desktop\autoit\twitter.xlsx"
Global $oExcel = _ExcelBookOpen($excelfile)

_ExcelWriteCell($oExcel, "username", 1, 1)
_ExcelWriteCell($oExcel, "followers", 1, 4)
_ExcelWriteCell($oExcel, "following", 1, 8)
_ExcelWriteCell($oExcel, "followbacklist3", 3, 1)

Global $aArray1 = _ExcelReadArray($oExcel, 3, 1, 7,1)
ConsoleWrite("Elements: " & $aArray1[0] & @CRLF)
For $i = 1 to $aArray1[0]
    ConsoleWrite("Element: " & $i & @CRLF)
    ConsoleWrite("  User: " & $aArray1[$i] & @CRLF)
    ConsoleWrite("  Row: " & $i & @CRLF)
    _Volgend($aArray1[$i], $i + 2) ;_volgend?
Next
Exit

Func _Volgend($sUser, $iRow)   ;_volgend?

    $oIE = _IECreate("https://twitter.com/" & $sUser)
    $oInput2s = _IETagNameGetCollection($oIE, "a")
    For $oInput2 In $oInput2s
        If $oInput2.className() = "js-nav" Then
            If StringInStr($oInput2.innerHTML(), 'Volgend') Then
                ConsoleWrite(_StringBetween($oInput2.innerHTML(),'>','<')[0] & @CRLF)
                ExitLoop ; I chanced it from "loop" to exitloop
            EndIf
        EndIf
    Next
    $numbvolgers = (_StringBetween($oInput2s.innerHTML(),'>','<')[0] & @CRLF)
    $numbvolgend = (_StringBetween($oInput2.innerHTML(),'>','<')[0] & @CRLF)
    ConsoleWrite(" Value: " & $numbvolgend & @CRLF)
    _ExcelWriteCell ($oExcel, $numbvolgend, $iRow, 3)
EndFunc

its really strange it works when you run it and if i it doesn't

 

33p6edu.jpg

these are the results , it does show the names and all ( thats how i saved it) but i doesn't automaticly  tracks the followers and following

if this does works when you run, than that woul be very strange, How can that be possible are there any special plugins you need to instal or anything like that ?

Link to comment
Share on other sites

I was not very clear in my last post, sorry.

I haven't tested my script, just put your script into a function and added some debugging code.

I was interested in the output to the SciTE console pane. If you press F5 in SciTE what do you get?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I was not very clear in my last post, sorry.

I haven't tested my script, just put your script into a function and added some debugging code.

I was interested in the output to the SciTE console pane. If you press F5 in SciTE what do you get?

i hope that this is what you mean

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\joesoef pc\Desktop\autoit\excel.au3" /UserParams    
+>23:36:12 Starting AutoIt3Wrapper v.2.1.4.4 SciTE v.3.3.7.0 ;  Keyboard:00020409  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0413  Keyboard:00020409  OS:WIN_81/  CPU:X64 OS:X64)
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3
+>23:36:12 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\joesoef pc\Desktop\autoit\excel.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
Elements: followbacklist3
+>23:36:16 AutoIt3.exe ended.rc:0
+>23:36:16 AutoIt3Wrapper Finished..
>Exit code: 0    Time: 4.366

this is what i get, i dont really see any errors, but i see it is getting stuck at the element: "followbacklist3" when it suppose read all of the 7 username's, i think the code isnt complete correctly

Edited by Arclite86
Link to comment
Share on other sites

Seems to be an error on my side :mad2:

Element 0 of the array doesn't contain the element count.

So this should work now:

#include <Excel.au3>
#include <IE.au3>
#include <string.au3>

Global $excelfile = "C:\Users\joesoef pc\Desktop\autoit\twitter.xlsx"
Global $oExcel = _ExcelBookOpen($excelfile)

_ExcelWriteCell($oExcel, "username", 1, 1)
_ExcelWriteCell($oExcel, "followers", 1, 4)
_ExcelWriteCell($oExcel, "following", 1, 8)
_ExcelWriteCell($oExcel, "followbacklist3", 3, 1)

Global $aArray1 = _ExcelReadArray($oExcel, 3, 1, 7,1)
ConsoleWrite("Elements: " & $aArray1[0] & @CRLF)
For $i = 0 to UBound($aArray1, 1) - 1
    ConsoleWrite("Element: " & $i & @CRLF)
    ConsoleWrite("  User: " & $aArray1[$i] & @CRLF)
    ConsoleWrite("  Row: " & $i & @CRLF)
    _Volgend($aArray1[$i], $i + 3) ;_volgend?
Next
Exit

Func _Volgend($sUser, $iRow)   ;_volgend?

    $oIE = _IECreate("https://twitter.com/" & $sUser)
    $oInput2s = _IETagNameGetCollection($oIE, "a")
    For $oInput2 In $oInput2s
        If $oInput2.className() = "js-nav" Then
            If StringInStr($oInput2.innerHTML(), 'Volgend') Then
                ConsoleWrite(_StringBetween($oInput2.innerHTML(),'>','<')[0] & @CRLF)
                ExitLoop ; I chanced it from "loop" to exitloop
            EndIf
        EndIf
    Next
    $numbvolgers = (_StringBetween($oInput2s.innerHTML(),'>','<')[0] & @CRLF)
    $numbvolgend = (_StringBetween($oInput2.innerHTML(),'>','<')[0] & @CRLF)
    ConsoleWrite(" Value: " & $numbvolgend & @CRLF)
    _ExcelWriteCell ($oExcel, $numbvolgend, $iRow, 3)
EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

the number still dont show up but i see improvement

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\joesoef pc\Desktop\autoit\excel.au3" /UserParams    
+>11:36:15 Starting AutoIt3Wrapper v.2.1.4.4 SciTE v.3.3.7.0 ;  Keyboard:00020409  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0413  Keyboard:00020409  OS:WIN_81/  CPU:X64 OS:X64)
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3
+>11:36:15 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\joesoef pc\Desktop\autoit\excel.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
Elements: followbacklist3
Element: 0
  User: followbacklist3
  Row: 0
1.187
"C:\Program Files (x86)\AutoIt3\Include\string.au3" (42) : ==> Subscript used on non-accessible variable.:
Func _StringBetween($sString, $sStart, $sEnd, $fCase = False)
Func _StringBetween($sString, $sStart, $sEnd, $fCase = False)^ ERROR
->11:36:20 AutoIt3.exe ended.rc:1
+>11:36:20 AutoIt3Wrapper Finished..
>Exit code: 1    Time: 5.564

i see that the script has located the username in the excel script, and has tracket the people i followed : 1.187

but it didn't paste the result "1.187" intro a excel cell,and it only located the first username : "followbacklist3"

maybe if there was no error it would continue

Link to comment
Share on other sites

Add some error checking after the _IE* calls.

Check the value of $oInput2.innerHTML() and $oInput2s.innerHTML().

If _StringBetween is unseccessfull it doesn't return an array. I would suggest to do it in two steps.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Add some error checking after the _IE* calls.

Check the value of $oInput2.innerHTML() and $oInput2s.innerHTML().

If _StringBetween is unseccessfull it doesn't return an array. I would suggest to do it in two steps.

i cannot figure out how to make this run, can you try it please

Link to comment
Share on other sites

Come on, that's not too hard :)

Every function returns a value or sets @error. Check this two to see if the function was called successfully. The help file is your friend ;)

Write $oInput2.innerHTML() and $oInput2s.innerHTML() to the Console to check if they return the proper value.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Can't test here because in my office Twitter is locked and at home I have no Excel available.

And your search strings seem to be language dependant.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...