Dynamics Ax Excel导入错误!!!SysExcelWorksheet

Dynamics Ax Excel导入错误!!!SysExcelWorksheet,excel,class,microsoft-dynamics,Excel,Class,Microsoft Dynamics,我想将Excel数据导入Microsoft Dynamics Ax。我使用了这个网站上的代码: 但当我尝试运行时,会出现以下错误: SysExcellworksheet could not start (C)\Classes\SysExcellWorksheets\cells(C)\Jobs\ProductType (line 35) 我是新手,你能帮我吗 static void ProductType(Args _args) { SysExcelApplication applicati

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

但当我尝试运行时,会出现以下错误:

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();
}

您可能翻译了错误,当我测试时,确切的错误是:

SysExcelWorksheet object not initialized.
这可能是因为在下一行中,您试图检索excel的第四个工作表,但excel文件的内容较少:

worksheet = worksheets.itemFromNum(4);
如果您的数据在第一张工作表上,请使用“1”而不是“4”:

worksheet = worksheets.itemFromNum(1);