1

有人可以给我一个线索,我怎样才能快速访问 Excel 数据。目前,excel 包含超过 20 万条记录,当我从 X++ 代码中检索时,检索所有记录需要花费大量时间。

以下是我用来检索数据的类。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

如果需要在这里设置任何特殊属性,请告诉我。

4

3 回答 3

2

如果您可以使用CSV 文件,整体性能会好很多(巨大!)。如果您被迫使用 Excel 文件,您可以简单直接地将这个 excel文件转换为 csv 文件,然后读取 csv 文件。如果您不能那样工作,您可以通过ODBC(使用查询字符串,如连接到数据库)读取 excel 文件,这将比 Office API 执行得更好。

于 2013-04-29T17:37:36.860 回答
0

首先,读取 Excel 文件(和任何其他文件)需要一段时间才能读取 20 万条记录。

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

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

  1. 将您的 Excel 文件转换为 CSV 文件,然后使用CommaIo读取。
  2. 使用 C# 读取 Excel 文件,然后调用 X++
  3. 接受事实并花时间
于 2013-04-21T20:49:06.583 回答
0

使用 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');
}
于 2013-04-23T04:35:45.437 回答