在将数据写入excel时,无论是使用绑定还是使用当前选择,都需要根据内容语言使用正确的数字格式。
因此,如果内容语言为英语,则以下代码将失败。
const options = { cellFormat: [{cells: {row: 1}, format: { numberFormat: '#.###,00'}}] }; Office.context.document.setSelectedDataAsync(tableData, options);
例如,一个丑陋的解决方案是
const options = { cellFormats: [{ cells: { column: 3 }, format: { numberFormat: Office.context.contentLanguage.startsWith('de')? '#.###,00': '#,###.00' } }]; }; Office.context.document.setSelectedDataAsync(tableData, options);
有没有像currency、number这样的抽象格式,或者像用户熟悉的excel用户界面那样的抽象格式?
发布于 2017-02-24 04:11:50
我不是百分之百确定,但如果你尝试使用“新”(Office 2016)浪潮的API会怎么样呢?类似于:
Excel.run(function (ctx) {
var sheetName = "Sheet1";
var rangeAddress = "F5:G7";
var numberFormat = [[null, "d-mmm"], [null, "d-mmm"], [null, null]]
var values = [["Today", 42147], ["Tomorrow", "5/24"], ["Difference in days", null]];
var formulas = [[null,null], [null,null], [null,"=G6-G5"]];
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
range.numberFormat = numberFormat;
range.values = values;
range.formulas= formulas;
range.load('text');
return ctx.sync().then(function() {
console.log(range.text);
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});https://stackoverflow.com/questions/42421696
复制相似问题