Dynamics Axe Excell导入错误! sysexcellworksheet

我想将Excel数据导入到Microsoft Dynamics Ax 。 我从这个网站使用这个代码:

http://axpedia.blogspot.com.tr/2013/02/import-from-excel-file-using-x-in-ax.html

但是当我尝试运行我得到这个错误:

SysExcellworksheet could not start (C)\Classes\SysExcellWorksheets\cells(C)\Jobs\ProductType (line 35) 

我是新手你能帮我一下吗?

 static void ProductType(Args _args) { SysExcelApplication application; SysExcelWorkbooks workbooks; SysExcelWorkbook workbook; SysExcelWorksheets worksheets; SysExcelWorksheet worksheet; SysExcelCells cells; COMVariantType type; Name name; FileName filename; ProductType productType; int row; int _productTypeId; str _productType; str _description; ; application = SysExcelApplication::construct(); workbooks = application.workbooks(); //specify the file path that you want to read filename = "Path\\filename.xlsx"; try { workbooks.open(filename); } catch (Exception::Error) { throw error("File cannot be opened."); } workbook = workbooks.item(1); worksheets = workbook.worksheets(); worksheet = worksheets.itemFromNum(4); //Here 3 is the worksheet Number cells = worksheet.cells(); do { row++; _productTypeId = any2int(cells.item(row, 1).value().toString()); _productType = cells.item(row, 2).value().bStr(); _description = cells.item(row, 3).value().bStr(); productType.ID = _productTypeId; productType.ProductType = _productType; productType.Description = _description; productType.insert(); type = cells.item(row+1, 1).value().variantType(); } while (type != COMVariantType::VT_EMPTY); application.quit(); } 

你可能翻译了错误,当我testing这个错误时,确切的错误是:

 SysExcelWorksheet object not initialized. 

这可能是因为在下面一行中,您正试图检索excel的第四张工作表,但是您的excel文件却less了一些:

 worksheet = worksheets.itemFromNum(4); 

如果您的数据位于第一个工作表上,请使用“1”而不是“4”:

 worksheet = worksheets.itemFromNum(1);