如何使用JavaScript创建.docx文件而不是.doc单词

如何使用JavaScript创建.docx文件而不是.doc单词,javascript,ms-word,docx,Javascript,Ms Word,Docx,我正在使用: var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' "+ "xmlns:w='urn:schemas-microsoft-com:office:word' "+ "xmlns='http://www.w3.org/TR/REC-html40'>"+ "<head><meta

我正在使用:

var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' "+
    "xmlns:w='urn:schemas-microsoft-com:office:word' "+
    "xmlns='http://www.w3.org/TR/REC-html40'>"+
    "<head><meta charset='utf-8'><title>Export HTML to Word Document with JavaScript</title></head><body>";
    var footer = "</body></html>";
    //@ts-ignore
    if(ev.target.id === "screenword"){
      this.setState({
        typeOfPrint: "screenword",
      }, () => {
        var sourceHTML1 = header+document.getElementById("spage").innerHTML+footer;
        var source1 = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML1);
        var fileDownload1 = document.createElement("a");
        document.body.appendChild(fileDownload1);
        fileDownload1.href = source1;
        fileDownload1.download = this.state.PPName+'.doc';
        fileDownload1.click();
        document.body.removeChild(fileDownload1);
var header=“”+
“使用JavaScript将HTML导出到Word文档”;
var footer=“”;
//@ts忽略
如果(ev.target.id==“屏幕字”){
这是我的国家({
打印类型:“屏幕字”,
}, () => {
var sourceHTML1=header+document.getElementById(“spage”).innerHTML+footer;
var source1='data:application/vnd.ms word;charset=utf-8',+encodeURIComponent(sourceHTML1);
var fileDownload1=document.createElement(“a”);
document.body.appendChild(fileDownload1);
fileDownload1.href=source1;
fileDownload1.download=this.state.PPName+'.doc';
fileDownload1.click();
document.body.removeChild(文件下载1);
要创建文档文件,但要创建docx。我已搜索,找不到有关如何更新此代码的任何指导。
我尽量避免外部的库。

我会考虑使用外部库,例如为此。
上面的页面包括从网页使用此功能的示例。

您是从节点应用程序、网页或其他平台创建此功能的吗?嗨,John-这是SharePoint框架。如果有帮助,它使用React作为框架。嗨,John-是的,我发现了,但我正在尽可能避免使用外部库。我将更新我的问题。