Office js getSelectedDataAsync和getHtml无法在word的桌面应用程序中获取base64
共享api和word api的getSelectedDataAsync和getHtml分别无法在word的桌面应用程序中获取图像的base64编码?请建议如何在word的桌面应用程序中获取所选图像的base64编码。您可以使用的方法检索图像的base64编码版本Office js getSelectedDataAsync和getHtml无法在word的桌面应用程序中获取base64,office-js,Office Js,共享api和word api的getSelectedDataAsync和getHtml分别无法在word的桌面应用程序中获取图像的base64编码?请建议如何在word的桌面应用程序中获取所选图像的base64编码。您可以使用的方法检索图像的base64编码版本 当然,您可以获得图像的base64,这是您需要做的。 这只是访问要选择的图像集合,只需在context.document.getSelection().inlinePictures.getFirst()上执行即可 异步函数getIma
当然,您可以获得图像的base64,这是您需要做的。 这只是访问要选择的图像集合,只需在context.document.getSelection().inlinePictures.getFirst()上执行即可 异步函数getImage(){ 试一试{ Word.run(异步(上下文)=>{ const firstPicture=context.document.body.inlinePictures.getFirst(); 加载(第一张图片); wait context.sync(); const base64=firstPicture.getBase64ImageSrc(); wait context.sync(); console.log(base64.value); }) } 捕获(例外){ OfficeHelpers.Utilities.log(异常); } }
Word.run(function (context) {
var base64Image;
var range = context.document.getSelection(); // Get selection
var images = range.inlinePictures; // Get images from selection
context.load(images); // Load images from document
return context.sync()
.then(function () {
// Make sure we have at least 1 image
if (images.items.length > 0)
// grab the base64 encoded image
image = images.getFirst().getBase64ImageSrc();
else
console.log("No images selected");
})
.then(context.sync)
.then(function () {
// image.value now contains the base64 encoded image
console.log(image.value);
})
.then(context.sync);
})