使用IE的ActiveXObject对象导出
使用IE的ActiveXObject对象
js:
try{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel=document.body.createTextRange();
sel.moveToElementText(obj);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
//以下是设置excel单元格宽度
oSheet.Columns(1).ColumnWidth =3;
oSheet.Columns(2).ColumnWidth =15;
oSheet.Columns(3).ColumnWidth =20;
oSheet.Columns(4).ColumnWidth =3;
oSheet.Columns(5).ColumnWidth =50;
oSheet.Columns(6).ColumnWidth =4;
oSheet.Columns(7).ColumnWidth =15;
oSheet.Columns(8).ColumnWidth =5;
oSheet.Rows.AutoFit;
oSheet.Rows.Font.Size=8;
//oSheet.Rows.RowHeight = 30
//xlsSheet.Rows(2).WrapText=true; //自动换行
//oWB.ActiveSheet.Cells(row,col).WrapText=true;
oXL.Visible = true;
}catch(e){
alert("请确定已安装Excel2000(或更高版本)!");
return;
}