在Word中显示Base64图像 [英] Displaying Base64 Images in Word
问题描述
我正在使用Office.js构建一个Word加载项。有一个Web应用程序,用户可以在其中插入base64图像和一些文本来创建文章。所以这个加载项用于在Word中显示文章。我可以毫无问题地显示文本,但是b $ b图像被破坏了。 Word无法显示base64图像吗?如果是这样,有没有办法正确地将图像转换为可显示格式并将它们插回Word?
I am using Office.js to build a Word add-in. There's a web app where users can insert base64 images along with some text to create an article. So this the add-in is used to display the article in Word. I can get to display the text without a problem, however the images are broken. Can't Word display base64 images? If so is there a way to correctly convert the images into a displayable format and insert them back to Word?
感谢任何帮助。谢谢。
推荐答案
您好
Immysl,
您可以尝试使用"insertInlinePictureFromBase64"。
you can try to use "insertInlinePictureFromBase64".
示例:
var img = '' //a base64 encoded string
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy object for the document body.
var body = context.document.body;
// Queue a command to insert the image.
body.insertInlinePictureFromBase64(img, 'End');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
app.showNotification('Image inserted successfully.');
});
})
.catch(function (error) {
app.showNotification("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
app.showNotification("Debug info: " + JSON.stringify(error.debugInfo));
}
});
参考:
其他参考:
InlinePicture对象(适用于Word的JavaScript API)
问候
Deepak
这篇关于在Word中显示Base64图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!