posts - 710,  comments - 81,  views - 260万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1>js导出,原理:复制页面中的table,让后粘贴到excle中

复制代码
 1   function exportToWord(id) {
 2             //Scripting.FileSystemObject (FSO 文本文件读写)被关闭了,
 3             //开启FSO功能即可,在“运行”中执行regsvr32 scrrun.dll即可
 4             try {
 5                 var oElement = document.getElementById(id);
 6                 var word = new ActiveXObject("Word.Application");
 7                 var doc = word.Documents.Add("", 0, 1); //不打开模版直接加入内容
 8                 var Range = doc.Range();
 9 
10                 var sel = document.body.createTextRange();
11                 sel.moveToElementText(oElement);
12                 sel.select();
13                 sel.execCommand("Copy");
14                 Range.Paste();
15                 word.Application.Visible = true;
16             }
17             catch (e) {
18 
19                 alert("无法启动Excel!\n\n" + e.message +
20                 "\n\n如果您确信您的电脑中已经安装了Excel," +
21                 "那么请调整IE的安全级别。\n\n具体操作:\n\n" +
22                 "工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
23             }
24         }
25         function exportToExcel(id) {
26             //Scripting.FileSystemObject (FSO 文本文件读写)被关闭了,
27             //开启FSO功能即可,在“运行”中执行regsvr32 scrrun.dll即可
28             try {
29                 var oElement = document.getElementById(id);
30                 var oRangeRef = document.body.createTextRange();
31                 oRangeRef.moveToElementText(oElement);
32                 oRangeRef.execCommand("Copy");
33 
34                 var oXL = new ActiveXObject("Excel.Application")
35                 var oWB = oXL.Workbooks.Add;
36                 var oSheet = oWB.ActiveSheet;
37                 oSheet.Paste();
38                 oSheet.Cells.NumberFormatLocal = "@";
39                 oXL.Selection.ColumnWidth = 8;
40 
41                 oXL.Visible = true;
42                 oSheet = null;
43                 oWB = null;
44                 appExcel = null;
45             } catch (e) {
46                 alert("无法启动Excel!\n\n" + e.message +
47                 "\n\n如果您确信您的电脑中已经安装了Excel," +
48                 "那么请调整IE的安全级别。\n\n具体操作:\n\n" +
49                 "工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
50             }
复制代码

 

 程序员的基础教程:菜鸟程序员

posted on   itprobie-菜鸟程序员  阅读(2135)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示