Ar *_* Es 2 excel office-addins office365 office-js
我肯定错过了什么:
[问题]:
我有一个二维数据数组,我想从单元格A1开始插入当前工作表.我还必须格式化这些数据.当前文档可能是空的或不是.我无法控制这一点.
稍后,我需要从文档中删除数据并插入新数据.这组新数据可能具有不同的维度.
使用Office JavaScript Api似乎无法做到这一点.
我尝试使用TableBindings等所有事情都失败了.在许多情况下,应该根据MSDN工作的功能失败,给我一些神秘的错误消息,例如"内部错误"(代码5001)或不支持的绑定操作(3010).我必须使用tablebindings,因为我无法根据MSDN文档将格式应用于其他任何内容.
以下解决方案是不可接受的:
从可用性的角度来看,所有这些都是噩梦般的解决方案.
我可以从命名项创建一个绑定,并通过计算列和行来构建范围,并构建一个类似于"A1:C232"的字符串,但这只能工作一次,因为:
我希望微软的某位读者能够读到这一点并指出我正确的方向.我真的希望!因为我开始担心这实际上是设计的.(在最后几周的斗争之后,我对office.js感到非常沮丧,我很难不咆哮,所以我会在这里停下来......不要让我开始使用ui面料)
小智 5
使用Office 2016引入的新Excel Javascript API(很快可在Office Online中使用),可以使用新的Range对象轻松操作工作表数据.下面的代码段不需要范围选择或用户方面的任何其他操作.
var data = [
[1,2,3],
[2,6,7]
]
Excel.run(function (ctx) {
// make space for the data to be inserted
var sheet1 = ctx.workbook.worksheets.getItem("Sheet1");
var firstCell = sheet1.getCell(0,0);
var lastCell = sheet1.getCell(data.length - 1, data[0].length - 1);
var range = firstCell.getBoundingRect(lastCell).insert('down');
range.values = data; // insert data
range.format.font.bold = true;
range.delete('up'); // erase data, shift up
return ctx.sync();
}).catch(function(error) {
console.log(error);
})
Run Code Online (Sandbox Code Playgroud)
在Office JS Snippet资源管理器中试用它,看看下面链接的博客文章了解更多信息!
https://github.com/OfficeDev/office-js-snippet-explorer
https://dev.office.com/blogs/Office-js-Public-Preview
归档时间: |
|
查看次数: |
773 次 |
最近记录: |