
function export2Word() {
var html, link, blob, url, css;
css = (
'<style> table { border-collapse: collapse; border-style:none; } .tables td,th{border:1px solid black;}' +
//'@page WordSection1{size: 841.95pt 595.35pt;mso-page-orientation: landscape;}' +
//'div.WordSection1 {page: WordSection1;} ' +
'</style>'
);
html = document.getElementById("tblPrint").outerHTML;
blob = new Blob(['\ufeff', css + html], {
type: 'application/msword'
});
url = URL.createObjectURL(blob);
link = document.createElement('A');
link.href = url;
link.download = 'Document'; // default name without extension
document.body.appendChild(link);
if (navigator.msSaveOrOpenBlob)
navigator.msSaveOrOpenBlob(blob, 'Document.doc'); // IE10-11
else link.click(); // other browsers
document.body.removeChild(link);
};我想导出表格到MS-Word,当我尝试,然后不显示任何表格结构,只显示数据
我在新的滚动中使用了分页符,像<div style="page-break-after:always;"> </div>一样,这也不起作用
我的代码出了什么问题?在ms-word中如何处理分页符?
提前感谢
发布于 2017-02-23 12:28:38
请试一试,这将会起作用
export html table as word file
或
var docDOM = document.getElementById('example');
var docObject = docx.export(docDOM, // required DOM Object
{
creator: "Creator", // optional String
lastModifiedBy: "Last person to modify", // optional String
created: new Date(), // optional Date Object
modified: new Date() // optional Date Object
});
var link = document.createElement('a');
link.appendChild(document.createTextNode("Download Link Text"));
link.title = "Download Title";
link.download = "FilenameHere.docx";
link.href = docObject.href();
document.getElementById("example").appendChild(link);https://stackoverflow.com/questions/42406772
复制相似问题