2016-07-22 126 views
0

我知道DOCX文件本质上是一个包含XML文件的zip文件。有没有使用chrome.fileSystem存储API来保存DOCX文件的简单方法,还是我需要手动创建和打包XML文件?Chrome应用程序Javascript:将文本另存为DOCX文件

chrome.fileSystem.chooseEntry({ 
    type: 'saveFile', 
    accepts: [ 
     { extensions: ['docx'] }, 
     { extensions: ['txt'] }, 
    ] 
}, function(writableFileEntry) { 
    var ext = writableFileEntry.name.substr(writableFileEntry.name.lastIndexOf('.') + 1); 
    var text = document.getElementById("textarea").innerText; 

    if(ext == 'docx'){ 
     ... ? 
    } 
    else if(ext == 'txt'){ 
     writableFileEntry.createWriter(function(writer) { 
      writer.write(new Blob([text], {type: 'text/plain'})); 
     }, function(){ 
      window.alert('Saving file failed'); 
     }); 
    } 
}); 

回答

1

fileSystem API无关与特定格式的文件或压缩 - 这是它的范围之外。它提供原始文件访问。

要做任何形式的内容格式化,您需要寻找额外的库或自己做,然后将生成的二进制文件提供给fileSystem

相关问题