ms-word - 检查文本选择是否在页眉/页脚中
问题描述
我们创建的 Word 插件允许向文本选择添加自定义注释。Word 不允许在页眉/页脚中添加注释。Because of that, users should get warned when text in a header/footer is selected.
- 正文中的文本和标题中的文本的选择的 OOXML 结构是相同的。
- 选择页脚/页眉文本时,Word UI 本身禁用了审阅评论部分。
- 将文本选择对象转储到控制台时,没有任何对象字段指向页眉/页脚中的选择。
如何以编程方式发现在页眉/页脚中选择了文本?
解决方案
您可以通过查看parentBody
选择范围的属性来实现这一点。上的type
属性parentBody
将显示选择是在“标题”中还是在其他地方(请参阅文档)。
例子
function determineSelectionInHeader() {
Word.run(function (context) {
const HEADER_TYPE = "Header";
// Retrieve and load 'type' of selection.
var selection = context.document.getSelection();
var parentBody = selection.parentBody;
parentBody.load("type");
context
.sync()
.then(function () {
if (parentBody.type === HEADER_TYPE) {
console.log("This is the header");
}
});
});
}
推荐阅读
- node.js - 当我尝试运行任何 npm 命令时,我正在生成 bash ENOENT
- python - Python:在绘图中编辑大小字体的问题
- python - 如何将列表与用户输入匹配
- javascript - 关闭标签页后如何在IOS中保存PWA状态?
- laravel - Laravel Nova 重置密码问题
- c - 结构元素的初始化
- javascript - 如何在自动增长的textarea中设置scrollHeight?
- html - CSS 媒体查询在 5 个特定的分辨率大小处中断....什么?
- ios - 如何使用 RxSwift 从网络请求中获取错误
- c# - WPF OnPreviewKeyDown 在只读时不能与 Textblock 或 Textbox 一起使用