[英]Javascript API for Office: How Can I Manually Trigger MS Office's AutoFormat Functionality?
I'm building a web app inside MS Excel using the Javascript API for Office. 我正在使用Office的Javascript API在MS Excel中构建一个Web应用程序。 One functionality that I'm adding to the app is the ability to edit data from the app. 我要添加到应用程序中的一项功能是能够从应用程序中编辑数据。 That data gets send to the Excel document via the setDataAsync
function in the API. 该数据通过API中的setDataAsync
函数发送到Excel文档。 It works for plain text. 它适用于纯文本。
I'm running into an odd problem with email addresses. 我的电子邮件地址遇到了一个奇怪的问题。 When I manually enter an email address into a cell, Excel auto formats it into a mailto:
hyperlink. 当我在单元格中手动输入电子邮件地址时,Excel会自动将其格式化为mailto:
超链接。 This doesn't happen when I set the data with Javascript. 当我使用Javascript设置数据时,不会发生这种情况。 I need to figure out a way to force Excel to AutoFormat it. 我需要找出一种方法来强制Excel自动格式化它。
One alternative idea I've had is to preformat the data myself into a link, using: 我所拥有的另一种想法是使用以下方法将数据本身预先格式化为链接:
=HYPERLINK("mailto:person@website.com","person@website.com")
However, when someone looks into the cell manually, they will see that long formula rather than just the address. 但是,当有人手动查看该单元格时,他们将看到该长公式,而不仅仅是地址。 And reading it back in to the web app will be a nightmare. 并将其读回Web应用程序将是一场噩梦。
function writeData(bindingID,newData,row,col) {
var newTable = new Office.TableData();
newTable.rows = [[newData]];
Office.select("bindings#"+bindingID).setDataAsync(newTable, {coercionType: "table", startRow: row, startColumn: col}, function (asyncResult) {
if (asyncResult.status == "failed") {
display('Error: ' + asyncResult.error.message);
}
});
}
Is it possible to cause Excel to autoformat? 是否有可能导致Excel自动格式化?
I asked this question over on the MS forums as well, and got an answer which I'd like to post here in case anyone else is having the same problem. 我也在MS论坛上也提出了这个问题,并得到了我想在这里发布的答案,以防其他人遇到同样的问题。
After testing and researching, I'm afraid there is no method or property in JavaScript for Office provided to automatically set mailto link for the text of cells after checking. 经过测试和研究后,恐怕Office的JavaScript中没有提供任何方法或属性来检查后自动为单元格的文本设置mailto链接。
We need to reformat the cells manually after inserting with SetDataAsync method. 使用SetDataAsync方法插入后,我们需要手动重新格式化单元格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.