- function exportToWord(id) {
- //Scripting.FileSystemObject (FSO 文本文件读写)被关闭了,
- //开启FSO功能即可,在"运行"中执行regsvr32 scrrun.dll即可
- try {
- varoElement = document.getElementById(id);
- varword =newActiveXObject("Word.Application");
- vardoc = word.Documents.Add("", 0, 1);//不打开模版直接加入内容
- varRange = doc.Range();
- varsel = document.body.createTextRange();
- sel.moveToElementText(oElement);
- sel.select();
- sel.execCommand("Copy");
- Range.Paste();
- word.Application.Visible =true;
- }
- catch (e) {
- alert("无法启动Excel!\n\n" + e.message +
- "\n\n如果您确信您的电脑中已经安装了Excel," +
- "那么请调整IE的安全级别。\n\n具体操作:\n\n" +
- "工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
- }
- }
- function exportToExcel(id) {
- //Scripting.FileSystemObject (FSO 文本文件读写)被关闭了,
- //开启FSO功能即可,在"运行"中执行regsvr32 scrrun.dll即可
- try {
- varoElement = document.getElementById(id);
- varoRangeRef = document.body.createTextRange();
- oRangeRef.moveToElementText(oElement);
- oRangeRef.execCommand("Copy");
- varoXL =newActiveXObject("Excel.Application")
- varoWB = oXL.Workbooks.Add;
- varoSheet = oWB.ActiveSheet;
- oSheet.Paste();
- oSheet.Cells.NumberFormatLocal = "@";
- oXL.Selection.ColumnWidth = 8;
- oXL.Visible =true;
- oSheet =null;
- oWB =null;
- appExcel =null;
- } catch (e) {
- alert("无法启动Excel!\n\n" + e.message +
- "\n\n如果您确信您的电脑中已经安装了Excel," +
- "那么请调整IE的安全级别。\n\n具体操作:\n\n" +
- "工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
- }
来源: http://www.bubuko.com/infodetail-2120139.html