Google Docs Apps脚本-以doc / docx文件的形式获取base64数据

问题描述

如何获取doc / docx格式的活动文档文件数据? 我可以毫无问题地获取PDF格式的内容。 我在下面的应用脚本代码中进行了尝试,但未以doc / docx格式返回base64字符串。

var doc = DocumentApp.getActiveDocument();

function doPostRequest(){
  
  var newblob = doc.getBlob();  
  newblob.setContentType("application/msword");
  newblob.setName("sample.doc");
  
  var dataObj = {
    date : new Date(),subject : "sample file data",comment : "this is a test comment",attachment : newblob
  }; 

  var options = {
    method : 'POST',payload: dataObj
  };
  
  var response = UrlFetchApp.fetch('https://postman-echo.com/post',options);
  console.log(response.getContentText());
  return response.getContentText();
}

输出

enter image description here

尽管它说“ sample.doc”,但是当我复制粘贴并从base64字符串(使用C#)生成文件时,它以PDF文件形式打开。

enter image description here

如何将文件数据转换为doc / docx格式并将文件数据另存为doc / docx文件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)