有没有什么方法可以让它在点击链接/锚标记时,使用office js重定向到Word加载项中页面/图像的某个部分



打开演示图像的链接

const[tableRow,setTableRow]=useState([["ID","图像URL","摄影师"]](

constinsertTable=async(响应(=>{

Word.run(async (context) => {
const photographer = response.photographer;
const img_id = response.id;
const img_url = response.url;
const arr = [img_id, img_url, photographer]
table_array = [...tableRow, arr]    
setTableRow(table_array)    
const row_length = table_array.length;
const body = context.document.body
body.clear()
//insert Table
body.insertTable(row_length, 3, "End", table_array);
await context.sync();
})
.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});

}

是的,您可以通过将超链接添加到同一文档中的某个位置来实现这一点。有关详细信息,请参阅此处:https://support.microsoft.com/en-us/office/add-hyperlinks-to-a-location-within-the-same-document-1f24fc4f-7ccd-4c5f-87e1-9ddefb672e0e

并且这种超链接完全由JavaScript API支持,例如range.hyperlink="书签1";;

以下示例在文档的开头添加一个书签,然后设置当前选择的超链接以重定向到作为文档开头的书签。

await Word.run(async (context) => {
const body = context.document.body.getRange().insertBookmark("Bookmark1");
context.document.getSelection().hyperlink = "#Bookmark1";
await context.sync();
});

最新更新