Excel Online中的Excel外接程序中的GeneralException

我们正在使用office.js和Excel.runfunction。 目的是点击表格中的单个单元格并捕获该表格中的所有数据。 在Visual Studio 2015运行Excel 2016和Excel API v1.3中成功地进行了testing。

但是,在Excel Online上运行相同时,会在行return ctx.sync().then(function () {创build一个exception。

例外:

 GeneralException: An internal error has occurred. Debug info: {"code":"GeneralException","message":"An internal error has occurred."} 

这个问题发生在所有浏览器中。 目前使用的是Chrome版本63.0.3239.18(官方版本)testing版(64位)。

我们正试图理解为什么它只在Excel Online中失败,而不是在Excel 2016 for Windows中。

这里是没有Office 2013范例的代码。 不幸的是,它会导致相同的错误。 我注意到堆栈跟踪提到了'Promise rejected(async)'。

注意:代码没有被优化。 只是修剪显示数据访问。

 // read data from the sheet function readDataExportConfirm() { Excel.run(function (ctx) { // Create a proxy object for the active worksheet var sheet = ctx.workbook.worksheets.getActiveWorksheet(); // auto select entire sheet var range = sheet.getUsedRange(); // fill proxy objects range.load('values'); console.log("fill proxy objects"); // sync on the request context synchronizes the state between // proxy objects and objects in Excel doc return ctx.sync().then(function () { var selectedData = range.values; console.log('data length: ' + selectedData.length + ' rows'); console.log('for row ' + 0 + ', got: ' + selectedData[0].length + ' columns'); // get rows var rows = selectedData.length; for (var row = 0; row < rows; row++) { var cols = selectedData[row].length; for (var col = 0; col < cols; col++) { console.log(' for row ' + row + ', col ' + col + ' = ' +selectedData[row][col].toString()); } } }); }) .catch(function (error) { // Always be sure to catch any accumulated errors that bubble up from the Excel.run execution console.error("Error: " + error); console.error("Error stack: " + error.stack); if (error instanceof OfficeExtension.Error) { console.error("Debug info: " + JSON.stringify(error.debugInfo)); } }); } 

然后使用https://dev.office.com/docs/add-ins/excel/excel-add-ins-ranges中的“获取完整范围”一节中的“使用Excel JavaScript API处理范围”页面中的代码和与堆栈跟踪中的'Promise rejected(async)'相同的错误。 在Visual Studio 2015 / Excel 2016中运行良好。

你在解决这个问题上的帮助非常感谢。

此代码至less有一个问题:您将Office 2013范例(“getSelectedDataAsync”)与Office 2016+范例(“Excel.run(batch)”)混合使用。 如果您使用新的2016+范例,您的代码将更有效率。 而且它也可以解决你的“GeneralException”问题(在混合这两个范例时,你有一定的时机问题)。

如果仍然不能解决您的问题,请发布更新。

花了很多时间检查代码,使用Visual Studio Enterprise 2015版本14.0.25431 Update 3创build一个新的Excel加载项,并在Excel中在线testing和testing后,我找出了导致问题的原因。 这是清单中的一行!

清单中版本从1.0.0.0更改为版本1.0。 改变这一点解决了“GeneralException”的问题。 现在加载项按预期在Excel在线运行。