如何使用Office.js获取单元格的格式 [英] How to get the formatting of a Cell using Office.js

查看:153
本文介绍了如何使用Office.js获取单元格的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Excel插件,它提取单元格A1的文本,包括其格式,并在其自己的区域显示文本。所以添加包含这个(见下面的屏幕截图):
•显示格式化文本的区域
•开始提取的按钮
请点击查看图片

I am developing an Excel Add-In that extracts the text of cell A1 INCLUDING its format and display the text in its own area. So the add in contains this (see screenshot below): • Area to display the formatted text • Button to start the extraction Please Click to view image

bellow是我用来获取文本的代码

bellow is the code that i am using to get the text

function displaySelectedCells() {
    Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
        function (result) {
            if (result.status === Office.AsyncResultStatus.Succeeded) {
                showNotification('The selected text is:', '"' + result.value + '"');
            } else {
                showNotification('Error', result.error.message);
            }
        });
}

上面的代码使用CoercionType作为文本。我已经尝试了很多找到解决方案来获取格式化在Sheet单元格中的文本。我得到的答复是只有飞机文本:(请帮我解决问题

The above code is using "CoercionType" as "Text" . I have tried a lot to find the solution to get the text as formatted written in a Sheet Cell. The Response i am getting is plane text only :( Please help me to solve the probelm

推荐答案

添加到迈克尔·桑德的答案:而您可以使用 myRange.format.font.load(['bold','color','italic','name','size','underline']),如果格式在单元格中和在myRange对象所表示的整个范围内是一致的,那么这只会使您得到字体,粗体,斜体等。单细胞的格式,它听起来不像后者适用于你(它只是一个单元格),但是示例图像在单元格中显示不同的粗体,斜体,颜色等等。您将不会的API可以获取此信息。

To add to Michael Saunder's answer: while you can use myRange.format.font.load(['bold','color','italic','name','size','underline']), this will only get you the font, bold, italic, etc. if the formatting is consistent within the cell and in the entire range represented by the myRange object. Since you're only looking for a single cell's format, it doesn't sound like the latter applies to you (it's only a single cell), but the example image you have shows different words within the cell having different bold, italic, color, and so on. With the current APIs you will not be able to get this information.

这听起来像您要求的是某种HTML或图像我鼓励你把这个提交给我们的UserVoice( https://officespdev.uservoice.com/ ),以及您需要的实际情况描述

It sounds like what you're asking is some sort of HTML or image-like representation of the cell. I encourage you to file this as a suggestion on our UserVoice (https://officespdev.uservoice.com/), along with a description of real-world the use-case that you need this for.

〜Michael Zlatkovsky,MSFT开发人员Office扩展性小组

~ Michael Zlatkovsky, developer on Office Extensibility team, MSFT

这篇关于如何使用Office.js获取单元格的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆