You are on page 1of 2

How to copy a Dynamic content of webtable into to EXCEL sheet

Note: You can use webelement objects to recognize webtables, if the data is not dynamic

'creating a general description object
Set mypage=browser("name:=.*").page("title:=.*")

'Creating a general description obect for table

Set table_desc=Description.Create()
table_desc("html tag").value="TABLE" 'for all tables
'table_desc("column names").value="Hello.*" for all tables with column names starting with hello


'All tables matching above will be returned into all_tables()
Set all_tables=mypage.childobjects(table_desc)

table_count=cint(all_tables.count) 'Get total count of tables

msgbox "we have "& table_count &" tables in the open browser"


Set oXl=createobject("Excel.application")
'oxl.Workbooks.add "C:\webtable.xlsx"
oxl.Workbooks.Open "C:\webtable.xlsx"
Set sheet=oxl.ActiveWorkbook.Worksheets("sheet1")

xl_row=1 'set excel row

For icount = 0 To table_count-1 Step 1
sheet.cells(xl_row, 1).value="Table No:"&icount+1 ' Insert a header before a table

For irowcount = 1 To all_tables(icount).rowcount 'for every row in each webtable
For icolcount= 1 To all_tables(icount).columncount(irowcount) 'for every column in each web table
get cellvalue
cell_value=all_tables(icount).getcelldata(irowcount, icolcount)
sheet.cells(irowcount+xl_row, icolcount).value=cell_value
'msgbox cellvalue

Next
Next
xl_row=irowcount+xl_row+1 'increase the row count for next table
Next


oxl.ActiveWorkbook.save
oxl.ActiveWorkbook.Close
oxl.application.Quit

You might also like