答案 0 :(得分:1)
当然,您可以获得图像的base64,这是您需要做的。 这只是访问图像集合以供选择,只需在context.document.getSelection()上进行.inlinePictures.getFirst()
async function getImage() {
try {
Word.run(async (context) => {
const firstPicture = context.document.body.inlinePictures.getFirst();
context.load(firstPicture);
await context.sync();
const base64 = firstPicture.getBase64ImageSrc();
await context.sync();
console.log(base64.value);
})
}
catch (exception) {
OfficeHelpers.Utilities.log(exception);
}
}
答案 1 :(得分:0)
您可以使用getBase64ImageSrc的Word API方法检索图像的Base64编码版本。
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);
})