Jump to content
Sign in to follow this  
RickB75

very new guy needing a little help with ExcelWriteCell

Recommended Posts

RickB75

Guys, I'm very, very new to scripting and I need a little help from the experts. I am writing a simple script to find a specific HTML tag on a webpage and Write the inner text to a excel spreadsheet. My script does this but, it keeps looping through and writes the inner text in the entire first column and keeps looping. I need it to write a cell then loop and find the next tag and write that content into a different cell and keep looping through until the end of the page. This is what I have so far. I commented out the message box, but it works pretty good. Once it grabs the inner text, it displays in a message box, I click "OK" and it loops through again and finds the next html tag and so on.

include <IE.au3>

#Include <Excel.au3>

$oIE = _IECreate ("C:\site\changes.html")

$oExcel = _ExcelBookNew()

$HElements = _IETagNameGetCollection($oIE, "H2")

$EMElements = _IETagNameGetCollection($oIE, "EM")

For $HElement In $HElements

_ExcelWriteCell($oExcel,$HElement.innerText,"A:A")

;MsgBox(0, "Element Info", "Tagname: " & $HElement.tagname & @CR & "innerText: " & $HElement.innerText)

Next

Any help you guys can offer is greatly appreciated!!

Share this post


Link to post
Share on other sites
water

You need a counter to define the row where you want to write the content and which is incremented for the next loop.

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

$oIE = _IECreate ("C:sitechanges.html")
$oExcel = _ExcelBookNew()
$HElements = _IETagNameGetCollection($oIE, "H2")
$EMElements = _IETagNameGetCollection($oIE, "EM")
$iCounter = 1
For $HElement In $HElements
    _ExcelWriteCell($oExcel,$HElement.innerText,"A" & $iCounter)
    $iCounter = $iCounter + 1
Next
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
RickB75

Thank you for your help Water! That works perfect. You help is very much greatly appriciated!!

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×