excel导出js代码

html页面
<INPUT onclick="javascrīpt:methodPrintExcels();" type=button value=Excel导出 >

js方法:
function methodPrintExcels() {//整个表格拷贝到EXCEL中
var curTbl = document.getElementById('eGridHead');
var oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel
var oWB = oXL.Workbooks.Add(); //获取workbook对象
var oSheet = oWB.ActiveSheet; //激活当前sheet
var Lenr = curTbl.rows.length; //取得表格行数

oSheet.Range("A1:H1").MergeCells=true;
oSheet.Cells(1).Font.Name = "黑体";
oSheet.Cells(1).HorizontalAlignment = 3;
oSheet.Cells(1).value = '人民币对外汇期权交易风险状况情景分析';

oSheet.Range("A2:A4").MergeCells=true;
oSheet.Cells(2,1).value = '美元对人民币升贬值幅度';
oSheet.Range("B2:B4").MergeCells=true;
oSheet.Cells(2,2).value = 'Delta';
oSheet.Range("C2:C4").MergeCells=true;
oSheet.Cells(2,3).value = 'Vega';
oSheet.Range("D2:G2").MergeCells=true;
oSheet.Cells(2,4).value = '价内期权合约本金额(万美元)';
oSheet.Range("D3:E3").MergeCells=true;
oSheet.Cells(3,4).value = '买入期权';
oSheet.Range("F3:G3").MergeCells=true;
oSheet.Cells(3,6).value = '卖出期权';

oSheet.Cells(4,4).value = '看涨';
oSheet.Cells(4,5).value = '看跌';
oSheet.Cells(4,6).value = '看涨';
oSheet.Cells(4,7).value = '看跌';

oSheet.Range("H2:H4").MergeCells=true;
oSheet.Cells(2,8).value = '期权组合整体损益(万美元)';

for (var i = 3; i < Lenr; i++) {
var Lenc = curTbl.rows(i).cells.length; //取得每行的列数
for (var j = 0; j < Lenc; j++) {
oSheet.Cells(i + 2, j + 1).value = curTbl.rows(i).cells(j).innerText; //赋值
}
}
oSheet.Columns("A").ColumnWidth = 23;
oSheet.Columns("H").ColumnWidth = 24;
oXL.Visible = true; //设置excel可见属性
}

你可能感兴趣的:(JavaScript,Excel)