我做了一个自定义的X ++代码,用于将数据从Excel导入到总帐,但是导入在服务器上直接运行良好,但在从最终用户(客户端)运行时,它会导入几条记录(如24条记录)然后抛出错误
the number of argument provided is different from the number of argument provided to the method
很明显,错误与连接问题有关,因为我在服务器上尝试了相同的Excel文件并成功导入。
为了防止这个问题,我正在考虑替代解决方案,而不是循环通过excel文件并执行业务并插入记录,相反,我认为如果我直接保存文件/大量保存可能会有用表或其他东西,然后尝试循环表,以防止连接问题。
注意:Google提供了几种解决方案,例如Windows重影,但没有一种适用于我
任何人都可以提供相关建议或建议合适的解决方案
答案 0 :(得分:2)
我建议您将Excel文件另存为制表符分隔文本,然后使用TextIO类进行导入。
您还将受益于性能提升+10倍!
static void ExcelTest(Args _args)
{
#Excel
FilePath excelFile = @'C:\Users\user\Documents\MyExcelFile.xlsx';
FilePath textFile = @'C:\Users\user\Documents\MyTextFile.txt';
Microsoft.Office.Interop.Excel.Application application = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbooks workBooks = application.get_Workbooks();
Microsoft.Office.Interop.Excel.Workbook workBook;
// Save the excel file as tab-separated text
application.set_DisplayAlerts(false);
application.set_Visible(false);
new FileIOPermission(excelFile, 'r').assert();
workBooks.Open(excelFile, 0, true, 5, '', '', true, #xlWindows, '', false, false, 1, false, false, 1);
CodeAccessPermission::revertAssert();
workBook = workBooks.get_Item(1);
new FileIOPermission(textFile, 'w').assert();
CodeAccessPermission::revertAssert();
workBook.SaveAs(textFile, #xlTextWindows, '', '', false, false, null, #xlLocalSessionChanges, false, null, null, false);
workBooks.Close();
application.Quit();
// Now read the text file
new FileIOPermission(textFile, 'r').assert();
io = new TextIo(textFile, 'r');
if (!io)
throw error("@SYS18447");
io.inFieldDelimiter('\t');
for (con = io.read(); io.status() == IO_Status::Ok; con = io.read())
{
info(con2str(con));
}
}