WEB页面导出为EXCEL文档的方法(国外英文资料).doc
文本预览下载声明
WEB页面导出为EXCEL文档的方法(国外英文资料)
The WEB page is exported as an EXCEL document (js implementation, done)
! DOCTYPE HTML PUBLIC - / W3C / / DTD XHTML 1.0 Transitional / / EN /TR/xhtml1/DTD/xhtml1-transitional.dtd
HTML XMLNS = /1999/xhtml
The head
meta HTTP - equiv = content-type Content = text/HTML; charset = gb2312 /
The title WEB page is exported as an EXCEL document method / title
The / head
The body
table id = tableExcel width = 60 border = 1 cellspacing = 0 cellpadding = 0
tr
td yufei welcome you / td
/ tr
/ table
input type = button onclick = javascript: method1 ( tableExcel ); Value = first method import to EXCEL
input type = button onclick = javascript: method2 ( tableExcel ); Value = second method imports EXCEL
input type = button onclick = javascript: getXlsFromTbl ( tableExcel , null). Value = the third method is imported into EXCEL
SCRIPT LANGUAGE = javascript
/ / the entire table is copied to EXCEL
The function method1 (tableid) {
Var curTbl = document.getelementbyid (tableid);
Var oXL = new ActiveXObject ( Excel. Application ); / / create a AX object excel
Var oWB = oxl. Workbooks. / / get the workbook object
Var oSheet = owb.activesheet; / / activate the current sheet
Var sel = document.createtextrange ();
Sel. MoveToElementText (curTbl); / / move the contents of the table to the TextRange
Sel. The select (); / / all of the content in TextRange
A. execCommand ( Copy ); / / copy the contents of the TextRange
OSheet. Paste (); / / pasted into active EXCEL
Var XLObj = new ActiveXObject ( Excel. Application );
Var xlBook = XLObj. Workbooks. / / new workbook
Var ExcelSheet = xlbook.worksheets (1); / / create worksheets
2. Save the form
Excels.saveas ( C: \ \ test.xls );
Make Excel visible through the Application object
ExcelSheet.
4. Print
XlBook. PrintOut;
Or:
ExcelSheet. PrintOut;
5. Close the
XlBook. Close (savechanges = false);
Or:
ExcelSheet. Close (savechanges = false);
6. The end of the process
ExcelSheet. Application. The
显示全部