快速访问X ++中的Excel数据

有人能给我一个线索,我怎么能得到Excel数据的快速访问。 目前,excel包含超过200K条logging,当我从X ++代码中检索时,需要花费大量时间来检索所有logging。

以下是我用来检索数据的类。 1 – SysExcelApplication,SysExcelWorksheet和SysExcelCells。

我正在使用下面的代码来检索单元格。

excelApp.workbooks().open(filename); excelWorksheet = excelApp.worksheets().itemFromName(itemName); excelCells = excelWorkSheet.cells(); ///pseudo code loop excelCells.item(rowcounter, column1); similar for all columns; end of loop 

如果需要在这里设置任何特殊的财产,请告诉我。

如果您可以使用CSV文件,整体性能会更好(巨大!)。 如果你不得不使用Excel文件,你可以简单而直接地把这个excel文件转换成一个csv文件,然后读取csv文件。 如果你不能这样工作,你可以通过ODBC读取excel文件(使用连接到数据库的查询string),这样可以更好地执行Office API。

首先,读取Excel文件(和任何其他文件)将需要一段时间的200 Klogging。

您可以使用ExcelIo读取Excel文件,但是没有性能保证:)

正如我所看到的,你有3个选项(首先列出最佳性能):

  1. 将您的Excel文件转换为CSV文件,然后用CommaIo读取。
  2. 使用C#读取Excel文件,然后callback到X ++
  3. 接受事实并花时间

使用CSV,速度更快,下面是代码示例:

  /* Excel Import*/ #AviFiles #define.CurrentVersion(1) #define.Version1(1) #localmacro.CurrentList #endmacro FilenameOpen filename; CommaIo file; Container con; /* File Open Dialog */ Dialog dialog; dialogField dialogFilename; dialogField dialogSiteID; dialogField dialogLocationId; DialogButton dialogButton; InventSite objInventSite; InventLocation objInventLocation; InventSiteID objInventSiteID; InventLocationId objInventLocationID; int row; str sSite; NoYes IsCountingFound; int iQty; Counter insertCounter; Price itemPrice; ItemId _itemid; EcoResItemColorName _inventColorID; EcoResItemSizeName _inventSizeID; dialog = new Dialog("Please select file"); dialogSiteID = dialog.addField(extendedTypeStr(InventSiteId), objInventSiteId); dialogLocationId = dialog.addField(extendedTypeStr(InventLocationId), objInventLocationId); dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen)); dialog.filenameLookupFilter(["@SYS100852","*.csv"]); dialog.filenameLookupTitle("Please select file"); dialog.caption("Please select file"); dialogFilename.value(filename); if(!dialog.run()) return; objInventSiteID = dialogSiteID.value(); objInventLocationID = dialogLocationId.value(); /*----- validating warehouse*/ while select maxof(InventSiteId) from objInventLocation where objInventLocation.InventLocationId == objInventLocationId { If(objInventLocation.InventSiteID != objInventSiteID) { warning("Warehouse not belongs to site. Please select valid warehouse." ,"Counting lines import utility"); return; } } filename = dialogFilename.value(); file = new commaIo(filename,'r'); file.inFieldDelimiter(','); try { if (file) { ttsbegin; while(file.status() == IO_Status::OK) { con = file.read(); if (con) { row ++; if(row == 1) { if( strUpr(strLtrim(strRtrim( conpeek(con,1) ))) != "ITEM" || strUpr(strLtrim(strRtrim( conpeek(con,2) ))) != "COLOR" || strUpr(strLtrim(strRtrim( conpeek(con,3) ))) != "SIZE" || strUpr(strLtrim(strRtrim( conpeek(con,4) ))) != "PRICE" ) { error("Imported file is not according to given format."); ttsabort; return; } } else { IsCountingFound = NoYes::No; _itemid = ""; _inventColorID = ""; _inventSizeID = ""; _itemid = strLtrim(strRtrim(conpeek(con,1) )); _inventColorID = strLtrim(strRtrim(conpeek(con,2) )); _inventSizeID = strLtrim(strRtrim(conpeek(con,3) )); itemPrice = any2real(strLtrim(strRtrim(conpeek(con,4) ))); } } } if(row <= 1) { ttsabort; warning("No data found in excel file"); } else { ttscommit; } } } catch { ttsabort; Error('Upload Failed'); }