Saturday, November 3, 2012

How to work with Datatables - Part1

In this video i will demonstrate how to work with Datatables.

Following topics are covered:
How to retrieve a cell value from a Data Table.
How to set a value into a Data Table.
How to import data from an Excel file.
How to export data to an Excel File.
How we can use Excel formulas in Data Table.
What are the general guidelines and few other concepts.


Here is the sample code used in the above video:

'The statement is mandatory to set/get any value, because setCurrentRow is not associated with any row we use GetSheet to make sure that we are pointing to the the right sheet.
Datatable.GetSheet(1)
'GetCurrentRow retrieves the number of rows existing in the Data Table.
RowCount=Datatable.GetRowCount
For i=1 to RowCount
    'setCurrentRow points to the row in a Datatable before we get/set value.
    Datatable.SetCurrentRow(i)
    'Value method is used to get/set value where first parameter is "ColumnName/ColumnId" and the second   parameter is "SheetId/SheetName/dtGlobalSheet"
    ip1=Datatable.Value(1,1)
    ip2=Datatable.Value(2,1)
    Datatable.Value(3,1)=cint(ip1)+cint(ip2)
Next
'Export method exports the data in Excel sheet to the Excel file specified.
Datatable.Export("E:\TempData.xls")

1 comment: