static void LTWeightimport(Args _args)
{
Dialog dialog;
Filename filename;
DialogField dialogFilename;
container conFilter = ["Microsoft Excel 97-2003 Worksheet (.xls)" ,"*.xlsx"];
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row=1;
ItemId itemId; ---- Excell First Column
InventTable inventtable; -----The Table Which was Related in AOT
ItemNetWeight ItemNetWeight; ----- 1st Name
ItemTaraWeight ItemTaraWeight; ----- 2nd Name
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new dialog();
dialog.caption("select a file");
dialogFilename = dialog.addField(typeId(FilenameOpen));
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
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);
cells = worksheet.cells();
do
{
row++;
itemId = cells.item(row,1).value().bStr(); ------Excell Sheet 1st Column
ItemNetWeight = cells.item(row,2).value().double(); ------ Excell Sheet 2nd Column
ItemTaraWeight = cells.item(row,3).value().double(); ------ Excell Sheet 3rd Column
inventtable.reread();
ttsbegin;
select forupdate inventtable
where inventtable.ItemId == itemId; ---------- Checking Inventtable Item id to Excel Seet Item Id.
if(inventtable)
{
inventtable.NetWeight = ItemNetWeight; ------ Insert Netweight to InventTable
inventtable.TaraWeight = ItemTaraWeight; ------ Insert TaraWeight to InventTable
inventtable.doUpdate();
}
ttscommit;
info(strfmt("%1",inventtable.ItemId));
type = cells.item(row+1, 1).value().variantType();
} while(type != COMVariantType::VT_EMPTY);
workbooks.close();
application.quit();
info("Operation/Processing Completed");
}
Comments
Post a Comment