Hi Friends,
I am reading from a simple excel file into AX table. Here is standard code, my excel file has only one column. The problem I found is that, after I created a test file, it return empty from "cells.item(row, 1).value().bStr()" while reading it. So I tried to add second column, then, it worked.
My version of Office is 2016, so I am not sure that played a role here. My AX is 2009.
===============================
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
Name name;
FileName filename;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "C:\\item.xls";
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();
do
{
row++;
itemId = cells.item(row, 1).value().bStr();
info(strfmt('%1', itemId));
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
*This post is locked for comments
I have the same question (0)