我可以使用 Base64 中的 body.insertFileFromBase64 字符串来自 doc 文件而不是 docx

can I used body.insertFileFromBase64 from Base64String comes from doc file not docx

我有网络服务,它读取 .doc 或 .docx 并通过 ajax 将它的 Base64String 发送到我的插件中 这是网络服务的代码

public string ReadDocument(string path)
        {

            FileStream fsStream = null;
            BinaryReader objReader = null;
            try
            {


                ////////////////////////

                // Now, read binary file
                //path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Copy.docx";
                fsStream = new FileStream(path, FileMode.Open, FileAccess.Read);
                byte[] fileContent = new byte[fsStream.Length];
                objReader = new BinaryReader(fsStream);
                objReader.Read(fileContent, 0, fileContent.Length);
                //toRet.FileContent = fileContent;
                //toRet.FileName = "Test.doc";
                string StrBase64 = Convert.ToBase64String(fileContent);
                string _Document = StrBase64 ;
                return _Document;
                // FlushResponse(_Document, "application/pdf");
            }
            catch (Exception ex)
            {
                // FlushResponse("error");
                return "Error " + ex.Message;
            }
            finally
            {
                if (objReader != null) objReader.Close();
                if (fsStream != null) fsStream.Close();
            }
        }

我的 body.insertFileFromBase64 有问题,当我的 Base64String 来自 .docx 时它可以工作,但是当 Base64String 来自 .doc 时它不工作 这是我在我的插件中的代码我发送结果参数它是 Base64String 来自 ajax

function InsertDocument(result) {
    Word.run(function (context) {

        // Create a proxy object for the document body.
        var body = context.document.body;
        body.clear();
        // Queue a commmand to insert base64 encoded .docx at the beginning of the content body.
        // You will need to implement getBase64() to pass in a string of a base64 encoded docx file.
        body.insertFileFromBase64(result, Word.InsertLocation.start);

        // Synchronize the document state by executing the queued commands,
        // and return a promise to indicate task completion.
        return context.sync().then(function () {
            console.log('Added base64 encoded text to the beginning of the document body.');
            $("#loading").hide();
        });
    })

有什么想法可以通过 office.js 或任何其他功能

将 .doc 插入 office 2016

body.insertFileFromBase64 方法的参考暗示第一个参数必须是 docx 文件:

base64File string Required. The base64 encoded content of a .docx file

.