private void
exportToExcel()
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
str filePathName;
SysExcelWorkSheet xlsWorkSheet;
str dateString;
ProdTable prodtable;
InventDim inventdim;
ProdId prodidchk;
ProdBOM prodBOM;
boolean filerecexists;
;
row = 1;
while(queryRun.next())
{
prodtable = queryRun.get(tableNum(ProdTable));
inventdim = queryRun.get(tableNum(InventDim));
if(filePathName
&& prodidchk !=prodtable.ProdId)
{
if(WinApi::fileExists(filePathName))
WinApi::deleteFile(filePathName);
//Save Excel
document
xlsWorkbook.saveAs(filePathName);
filerecexists = false;
//
okv, 06/27/2016 -->
xlsWorkbook.comObject().save();
xlsWorkbook.saved(true);
xlsApplication.quit();
//
okv, 06/27/2016 <--
}
if(prodidchk
== "" || prodidchk
!=prodtable.ProdId)
{
row = 1;
filerecexists = true;
prodidchk =
prodtable.ProdId;
dateString ="@CIT354"+"_"+prodtable.ProdId+"_"+date2Str(today(),321,DateDay::Digits2,DateSeparator::None,
DateMonth::Digits2,DateSeparator::None,DateYear::Digits4)+"_"+inventdim.inventSerialId;
filePathName = exportFilePath+"\\"+dateString +".xlsx";
xlsApplication =
SysExcelApplication::construct();
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet =
xlsWorkSheetCollection.itemFromNum(1);
xlsWorkSheet.cells().item(row,1).value("@CIT355");
xlsWorkSheet.cells().item(row,2).value("@CIT356");
xlsWorkSheet.cells().item(row,3).value("@CIT343");
xlsWorkSheet.cells().item(row,4).value("@CIT357");
xlsWorkSheet.cells().item(row,5).value("@CIT358");
xlsWorkSheet.cells().item(row,6).value("@CIT359");
xlsWorkSheet.cells().item(row,7).value("@CIT360");
xlsWorkSheet.cells().item(row,8).value("@CIT361");
xlsWorkSheet.cells().item(row,9).value("@CIT362");
xlsWorkSheet.cells().item(row,10).value("@CIT363");
xlsWorkSheet.cells().item(row,11).value("@CIT364");
xlsWorkSheet.cells().item(row,12).value("@CIT365");
xlsWorkSheet.cells().item(row,13).value("@CIT366");
xlsWorkSheet.cells().item(row,14).value("@CIT367");
row++;
}
while
select
ProdId,ItemId,dataAreaId,BOMQty,BOMQtySerie from prodBOM
where
prodBOM.ProdId == prodtable.ProdId
{
if(InventItemSetupSupplyType::find(prodBOM.ItemId,prodBOM.dataAreaId).DefaultOrderType
== ReqPOType::Production)
{
xlsWorkSheet.cells().item(row,1).value("\'"+inventdim.inventSerialId); // okv, 06/27/2016
xlsWorkSheet.cells().item(row,2).value(InventTable::find(prodtable.ItemId).inventUnitId());
xlsWorkSheet.cells().item(row,3).value("");
xlsWorkSheet.cells().item(row,4).value(prodtable.RealDate);
xlsWorkSheet.cells().item(row,5).value("\'"+prodbom.ItemId); // okv, 06/27/2016
xlsWorkSheet.cells().item(row,6).value("");
xlsWorkSheet.cells().item(row,7).value("");
xlsWorkSheet.cells().item(row,8).value("");
xlsWorkSheet.cells().item(row,9).value(0);
xlsWorkSheet.cells().item(row,10).value("");
xlsWorkSheet.cells().item(row,11).value("");
xlsWorkSheet.cells().item(row,12).value(prodBOM.UnitId);
xlsWorkSheet.cells().item(row,13).value("");
xlsWorkSheet.cells().item(row,14).value("");
row++;
this.insertLines(prodBOM.ItemId, prodtable.RealDate, xlsWorkSheet, 1);
}
else
if
(InventItemSetupSupplyType::find(prodBOM.ItemId,prodBOM.dataAreaId).DefaultOrderType
== ReqPOType::Purch)
{
xlsWorkSheet.cells().item(row,1).value("\'"+inventdim.inventSerialId); // okv, 06/27/2016
xlsWorkSheet.cells().item(row,2).value(InventTable::find(prodtable.ItemId).inventUnitId());
xlsWorkSheet.cells().item(row,3).value("");
xlsWorkSheet.cells().item(row,4).value(prodtable.RealDate);
xlsWorkSheet.cells().item(row,5).value("\'"+prodbom.ItemId); // okv, 06/27/2016
xlsWorkSheet.cells().item(row,6).value("");
xlsWorkSheet.cells().item(row,7).value("");
xlsWorkSheet.cells().item(row,8).value("");
xlsWorkSheet.cells().item(row,9).value(prodbom.BOMQty/(prodBOM.BOMQtySerie
? prodBOM.BOMQtySerie : 1));
xlsWorkSheet.cells().item(row,10).value("");
xlsWorkSheet.cells().item(row,11).value("");
xlsWorkSheet.cells().item(row,12).value(prodBOM.UnitId);
xlsWorkSheet.cells().item(row,13).value("");
xlsWorkSheet.cells().item(row,14).value("");
row++;
}
}
}
if(filerecexists)
{
if(WinApi::fileExists(filePathName))
WinApi::deleteFile(filePathName);
//Save
Excel document
xlsWorkbook.saveAs(filePathName);
filerecexists = false;
// okv,
06/27/2016 -->
xlsWorkbook.comObject().save();
xlsWorkbook.saved(true);
xlsApplication.quit();
// okv,
06/27/2016 <--
}
}
|