function ExportToExcel() {
//Start Excel and get Application object
var oXLS = new ActiveXObject("Excel.Application");
//新增工作簿
var oWB = oXLS.Workbooks.Add();
if(document.getElementById("report2")!=null)
{
var excelTable = document.getElementById("report2");
//创建工作表
var oSheet1 = oWB.Worksheets(1);
// 设置列宽
oSheet1.Columns("A:F").ColumnWidth = 18;
//合并单元格
oXLS.Range("A2:A6").MergeCells = true;
oXLS.Range("A7:A8").MergeCells = true;
//循环添加数据
for (var i=0;i<excelTable.rows.length;i++) //行
{
for (var j=0;j<excelTable.rows(i).cells.length;j++) //列
{
if(i<=1){
//设置单元格内容
oSheet1.Cells(i+1,j+1).Value = excelTable.rows(i).cells(j).innerText;
}
if(i>1 && i<6){
oSheet1.Cells(i+1,j+2).Value = excelTable.rows(i).cells(j).innerText;
}
if(i==6) {
oSheet1.Cells(i+1,j+1).Value = excelTable.rows(i).cells(j).innerText;
}
if(i==7) {
oSheet1.Cells(i+1,j+2).Value = excelTable.rows(i).cells(j).innerText;
}
}
}
oSheet1.Name = "访问量统计报表";
}
oXLS.Visible = true;
oXLS.UserControl = true;
}
JavaScript导出excel
最新推荐文章于 2022-07-11 15:40:39 发布