jsp生成word文档格式数据代码
一、把jsp页面数据复制到word文档
var table=document.getElementById(printTable);
row=table.rows.length;
column=table.rows(1).cells.length;
var word = new ActiveXObject("Word.Application");
word.Application.Visible = true;
word.Selection.Text ="<%=reportTitle%>";
var mydoc=word.Documents.Add(,0,0);
myRange =mydoc.Range(0,1);
var sel=document.body.createTextRange();
sel.moveToElementText(table);
sel.select();
sel.execCommand(Copy);
myRange.Paste();
二、把jsp页面数据写入word文档
var table=document.getElementById(printTable);
row=table.rows.length;
column=table.rows(1).cells.length;
var wdapp=new ActiveXObject("Word.Application");
wdapp.visible=true;
wddoc=wdapp.Documents.Add(); //添加新的文档
thearray=new Array();
//将页面中表格的内容存放在数组中
for(i=0;i<row;i ){
thearray[i]=new Array();
for(j=0;j<column;j ){
thearray[i][j]=table.rows(i).cells(j).innerHTML;
}
}
var range = wddoc.Range(0,0);
range.Text="<%=reportTitle%>" " ";
wdapp.Application.Activedocument.Paragraphs.Add(range);
wdapp.Application.Activedocument.Paragraphs.Add();
rngcurrent=wdapp.Application.Activedocument.Paragraphs(3).Range;
var objTable=wddoc.Tables.Add(rngcurrent,row,column) //插入表格
for(i=0;i<row;i ){
for(j=0;j<column;j ){
objTable.Cell(i 1,j 1).Range.Text = thearray[i][j].replace(" ","");
}
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>