简体   繁体   English

Office Javascript API:如何手动触发MS Office的自动套用格式功能?

[英]Javascript API for Office: How Can I Manually Trigger MS Office's AutoFormat Functionality?

Background: 背景:

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应用程序将是一场噩梦。

Current Code: 当前代码:

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);
        }
    });
}

Question: 题:

Is it possible to cause Excel to autoformat? 是否有可能导致Excel自动格式化?

Answer: It can't be done. 答:不能完成。

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方法插入后,我们需要手动重新格式化单元格。

Luna Zhang - MSFT (Source) 张露娜-MSFT (来源)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Office JavaScript API中获取当前的Excel文件? - How can I get the current Excel file in Office JavaScript API? 如何在Office Javascript API中读取Excel自定义属性? - How can I read Excel custom properties in Office Javascript API? 如何使用 Script Lab 使用 Microsoft Office JavaScript API 创建本地文件 I/O? - How can i make local file I/O with Microsoft Office JavaScript API using Script Lab? 如何确定Office版本号的JavaScript API(适用于Office 2013项目的应用) - How do I determine JavaScript API for Office Version Number (App for Office 2013 Project) Office JavaScript API for Outlook-位置更改时如何刷新我的Web加载项? - Office JavaScript API for Outlook - how can I refresh my web add-in when location changes? 调试Office的JavaScript API - Debugging JavaScript API for Office Office的JavaScript API-如何使用控制台? - JavaScript API for Office - How to use console? 如何在JavaScript中检测MS Office的安装版本? - How to detect installed version of MS Office within javascript? 如何使用IE中的JavaScript检测MS Office的安装版本? - How to detect installed version of MS Office using javascript from IE? 重定向到自动打开的MS Office(word,excel,powerpoint)文档后,如何关闭浏览器窗口? - How can I close the browser window after redirecting to an MS office(word,excel, powerpoint) document automatically opened?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM