我需要使用Java脚本更改Word 97文档中的文本。是否与Word 97的docx.js或doxctemplater类似?
谢谢
您可以使用正确的标头将HTML转换为.doc文件。
function exportHTML(){
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>";
var sourceHTML = header+document.getElementById("source-html").innerHTML+footer;
var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);
var fileDownload = document.createElement("a");
document.body.appendChild(fileDownload);
fileDownload.href = source;
fileDownload.download = 'document.doc';
fileDownload.click();
document.body.removeChild(fileDownload);
}
在此示例中,从phppot开始,带有id="source-html"
的HTML对象包含您要在.doc中编写的HTML。该脚本将创建一个指向您新生成的.doc文件的下载链接。