是否可以使用Office 2013 office插入base64的Word文件api
Is it possible to insert a base64 Word file using Office 2013 office api
我有一个成功的 运行 脚本,可以从 SharePoint 加载 Word 文件并将它们插入 Word 2017(Office 365 Word 本地客户端,非在线)
当前脚本使用 Ajax 读取文件并提取 base64 文件并使用
body.insertFileFromBase64(myBase64, end)
我现在需要扩展功能以支持 Word 2013(即使用 Office.js 而不是 Word JavaScript api)。所以代码变成了
Office.context.document.setSelectedDataAsync(file, someCoercionType)
我希望能够使用
的变体
Office.context.document.setSelectedDataAsync(myBase64, {coercionType: Office.CoercionType.Ooxml}, function (
但我收到一个错误 "The Format of the specified data object is invalid",这是正确的,因为 Office API 假定 base64 文件是图像。
Is it possible to convert the Base64 file to XML in JavaScript?(在我的代码的其他地方,我解压了 docx 并提取了书签,但是仅来自缺少所有格式和图像、页脚等的 document.xml)
Base64 只是一种二进制编码,并且完全不知道底层内容类型。因此,如果您的源内容是 OOXML,则对其进行解码会给您返回 OOXML。你不能做的是类型转换。例如,Base64 编码的 JPEG 不能直接解码为 BMP。为此,您需要先解码,然后使用其他工具将 JPEG 格式转换为 BMP 格式。
如果您正在寻求操纵或提取现有文档的内容,您可能需要查看 Aspose.Words. Aspose provides tools that allow you to programmatically work with Word documents (they have similar tools for a flew of other file types as well). Using this, you may be able to extract the OOXML you're looking for so you can then insert it into Word using Office.js。
目前,唯一接受 Base64 编码内容的强制转换类型是 Office.CoercionType.Image。
我有一个成功的 运行 脚本,可以从 SharePoint 加载 Word 文件并将它们插入 Word 2017(Office 365 Word 本地客户端,非在线) 当前脚本使用 Ajax 读取文件并提取 base64 文件并使用
body.insertFileFromBase64(myBase64, end)
我现在需要扩展功能以支持 Word 2013(即使用 Office.js 而不是 Word JavaScript api)。所以代码变成了
Office.context.document.setSelectedDataAsync(file, someCoercionType)
我希望能够使用
的变体Office.context.document.setSelectedDataAsync(myBase64, {coercionType: Office.CoercionType.Ooxml}, function (
但我收到一个错误 "The Format of the specified data object is invalid",这是正确的,因为 Office API 假定 base64 文件是图像。
Is it possible to convert the Base64 file to XML in JavaScript?(在我的代码的其他地方,我解压了 docx 并提取了书签,但是仅来自缺少所有格式和图像、页脚等的 document.xml)
Base64 只是一种二进制编码,并且完全不知道底层内容类型。因此,如果您的源内容是 OOXML,则对其进行解码会给您返回 OOXML。你不能做的是类型转换。例如,Base64 编码的 JPEG 不能直接解码为 BMP。为此,您需要先解码,然后使用其他工具将 JPEG 格式转换为 BMP 格式。
如果您正在寻求操纵或提取现有文档的内容,您可能需要查看 Aspose.Words. Aspose provides tools that allow you to programmatically work with Word documents (they have similar tools for a flew of other file types as well). Using this, you may be able to extract the OOXML you're looking for so you can then insert it into Word using Office.js。
目前,唯一接受 Base64 编码内容的强制转换类型是 Office.CoercionType.Image。