hello experts,
I am creating x++ code for updating specific data in table from excel...bt it gives error...my code as follows..
static void TableUpdate(Args _args)
{
AsciiIO asciiIO;
Filename filename;
NoYesId skipFirstLine;
Container line;
Dialog dialog;
DialogField dialogFileName, dialogSkipFirstLine;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Name name;
ProjInvoiceItem projInvoiceItem;
//ProjInvoiceId _ProjInvoiceId;
//ItemId _ItemId;
int row;
str _ITNO;
str _ProjInvoiceId;
str _ItemId;
;
dialog = new Dialog("Import file");
dialogFileName = dialog.addField(TypeId(Filenameopen), "File name");
dialog.run();
if (dialog.run())
{
filename = dialogFileName.value();
}
asciiIO = new AsciiIO(filename, 'R');
if (!asciiIO || asciiIO.status() != IO_Status::Ok )
{
throw error (strfmt("No Path Specified",filename));
}
ttsbegin;
asciiIO.inRecordDelimiter('\r\n');
asciiIO.inFieldDelimiter(',');
while (asciiIO.status() == IO_status::Ok)
{
line = asciiIO.read();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = dialogFileName.value();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1); //worksheet Number
cells = worksheet.cells();
do
{
row++;
_ProjInvoiceId = any2str(cells.item(row, 1).value().toString());
_ItemId = any2str(cells.item(row, 2).value().toString());
_ITNO = cells.item(row, 3).value().bStr();
// select forupdate projInvoiceItem where projInvoiceItem.ProjInvoiceId == ProjInvoiceId
// && projInvoiceItem.ItemId == ItemId;
projInvoiceItem.ProjInvoiceId = _ProjInvoiceId;
projInvoiceItem.ItemId = _ItemId;
projInvoiceItem.ITNO = _ITNO;
projInvoiceItem.update();
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
ttscommit;
}