各位大侠们 如何利用 js 将一个完整的html页面导入到word.页面中有图片 并且不只一个表格。求高手帮助;
像下面这样的代码没用function AllAreaWord()
{
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
//window.close();
}
像下面这样的代码没用function AllAreaWord()
{
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
//window.close();
}
直接用word打开,然后存成.doc文件就可以了。 protected void ConvertToHtml(string SrcFilePath,string TargetFilePath)
{
Word.Application app=new Word.Application();
app.Visible=false;
Object o=Missing.Value;
object docFile=SrcFilePath;
_Document doc=app.Documents.Open(ref docFile,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
object fileName=TargetFilePath;
object format=Word.WdSaveFormat.wdFormatDocument; //word format
doc.SaveAs(ref fileName,ref format,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
object t=true;
app.Quit(ref t,ref o,ref o);
}
用POI包可以编码操作word表格
var f = document.createElement('iframe');
f.style.display = 'none';
document.appendChild(f);
window[window.length - 1].document.write(content);
window[window.length - 1].document.execCommand('saveas', true, name);
document.removeChild(f);
};save('<html>' + document.documentElement.innerHTML + '</html>', document.title + '.doc');