Wednesday, November 28, 2012
Reading an Excel file
1. In the AOT, create a new job named ReadExcelFile with the following code
(replace the file name with your own):
static void ReadExcelFile (Args _args)
{
SysExcelApplication excel;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
CustAccount account;
CustName name;
#define.filename(@'C:\temp\customers.xlsx')
excel = SysExcelApplication::construct();
workbooks = excel.workbooks();
try
{
workbooks.open(#filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
type = cells.item(row+1, 1).value().variantType();
while (type != COMVariantType::VT_EMPTY)
{
row++;
account = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
info(strFmt('%1 - %2', account, name));
type = cells.item(row+1, 1).value().variantType();
}
excel.quit();
}
2. Run the job to display the contents of the file in the Infolog, as shown in the
following screenshot:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment