js wps excel导出

js wps excel

function makeexcel(pasteobj){
  window.clipboardData.setData("Text",pasteobj.outerHTML);
  try{
  var ExApp;
try {
ExApp = new ActiveXObject("ET.Application");
} catch(e) {
try {
        ExApp = new ActiveXObject("Excel.Application");
        //var ExApp = new ActiveXObject("Excel.Application");
var ExWBk = ExApp.workbooks.add();
var ExWSh = ExWBk.worksheets(1);
ExApp.DisplayAlerts = false;
ExApp.visible = true;
} catch(e) {
        alert( "您的电脑没有安装Microsoft Excel软件! ");
        return;
}
ExWBk.worksheets(1).Paste;
}
var curTbl = document.getElementById("tab1");
var oXL = ExApp;
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
//在此进行样式控制  
oSheet.Rows(1+":"+1).RowHeight =20;//定义行高  
oSheet.Rows(2+":"+2).RowHeight =20;  
//定义列宽  
oSheet.Columns('A:A').ColumnWidth = 50;  
oSheet.Columns('B:B').ColumnWidth = 20;  
oSheet.Columns('C:C').ColumnWidth = 10;  
oSheet.Columns('D:D').ColumnWidth = 10;  
oSheet.Columns('E:E').ColumnWidth = 10;  
oSheet.Columns('F:F').ColumnWidth = 10;  
oSheet.Columns('G:G').ColumnWidth = 10;  
oSheet.Columns('H:H').ColumnWidth = 10;  
oSheet.Rows(1).HorizontalAlignment=3;  
var sel = document.body.createTextRange();
sel.moveToElementText(curTbl);
//sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
  }catch(e){
alert("您的电脑没有安装Microsoft Excel软件!");
return false;
  }
  //ExWBk.worksheets(1).Paste;
}

  <table align=center width=80% cellspacing=0 id="tab">
 
  <tr><td align=right><button onClick="makeexcel(document.all('tab1'))" accesskey="X"><a href=" http://www.50xiao.com">生成EXCEL(X)</a></button></td></tr>
  </table>
50校招生网  http://www.50xiao.com

你可能感兴趣的:(JavaScript)