HTML table 转化成 Excel电子表格? 请高手帮忙 :(
苏丹-陈 2002-07-24 11:05:01 怎样才能让IE自动打开Excel,加载内容。
或者怎么才能直接保存数据到本地硬盘,提示用户输入文件名?
function tableToExcel(o,table){
o.document.write("<html xmlns:o='urn:schemas-microsoft-com:office:office'");
o.document.write("xmlns:x='urn:schemas-microsoft-com:office:excel'");
o.document.write("xmlns='http://www.w3.org/TR/REC-html40'>");
o.document.write("<head>");
o.document.write("<meta http-equiv=Content-Type content='text/html; charset=GB2312'>");
o.document.write("<meta name=ProgId content=Excel.Sheet>");
o.document.write("<meta name=Generator content='Microsoft Excel 9'>");
o.document.write("<xml>");
o.document.write(" <x:ExcelWorkbook>");
o.document.write(" <x:ExcelWorksheets>");
o.document.write(" <x:ExcelWorksheet>");
o.document.write(" <x:Name>导出表格数据</x:Name>");
o.document.write(" <x:WorksheetOptions>");
o.document.write(" <x:DefaultRowHeight>285</x:DefaultRowHeight>");
o.document.write(" <x:Print>");
o.document.write(" <x:ValidPrinterInfo/>");
o.document.write(" <x:PaperSizeIndex>9</x:PaperSizeIndex>");
o.document.write(" <x:HorizontalResolution>600</x:HorizontalResolution>");
o.document.write(" <x:VerticalResolution>600</x:VerticalResolution>");
o.document.write(" </x:Print>");
o.document.write(" <x:Selected/>");
o.document.write(" <x:ProtectContents>False</x:ProtectContents>");
o.document.write(" <x:ProtectObjects>False</x:ProtectObjects>");
o.document.write(" <x:ProtectScenarios>False</x:ProtectScenarios>");
o.document.write(" </x:WorksheetOptions>");
o.document.write(" </x:ExcelWorksheet>");
o.document.write(" </x:ExcelWorksheets>");
o.document.write(" <x:WindowHeight>7965</x:WindowHeight>");
o.document.write(" <x:WindowWidth>13905</x:WindowWidth>");
o.document.write(" <x:WindowTopX>360</x:WindowTopX>");
o.document.write(" <x:WindowTopY>1830</x:WindowTopY>");
o.document.write(" <x:ProtectStructure>False</x:ProtectStructure>");
o.document.write(" <x:ProtectWindows>False</x:ProtectWindows>");
o.document.write(" </x:ExcelWorkbook>");
o.document.write("</xml>");
o.document.write("</head>");
o.document.write("<body>");
o.document.write(table);
o.document.write("</body>");
o.document.write("</html>");
}
function exportToExcel(){
var win;
win = window.open("")
tableToExcel(win,printContent.outerHTML)
}