惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

皮皮赖's Blog

Script @php think service:discover handling the post-autoload-dump event returned with error code 255 Centos7 网卡型号 网卡硬件型号 网卡芯片型号支持列表 - 皮皮赖's Blog uniapp IOS15、16 uni.scanCode 扫码后页面跳转卡死 - 皮皮赖's Blog PHP导出数据至Excel PHPExcel库使用方法 例子 示例 - 皮皮赖's Blog golang 实现 SD-WAN IWAN 例子 简单例子 示例 宝塔面板邮局管理器Postfix无法启动,重装后不能正常运行Postfix修复 - 皮皮赖's Blog idea goland phpstorm pycharm IntelliJ 打开项目后,只显示文件,项目中的目录不显示 《掌上 WeGame》宣布退市,9月8日正式停运 - 皮皮赖's Blog 常见内网IP段,不跟公网冲突的内网IP段有那些? - 皮皮赖's Blog
Javascript导出数据至Excel JS导出数据至Excel - 皮皮赖's Blog
博主: Reaper · 2023-02-20 · via 皮皮赖's Blog

要将数据从JavaScript导出到Excel,您可以使用JavaScript库或原生JavaScript。以下是使用原生JavaScript的简单示例:

<!-- 创建一个按钮并添加单击事件 -->
<button onclick="exportToExcel()">导出到Excel</button>

<script>
function exportToExcel() {
  // 获取要导出的数据
  const data = [
    ['姓名', '年龄', '性别'],
    ['张三', '25', '男'],
    ['李四', '30', '女'],
    ['王五', '28', '男']
  ];

  // 创建一个新的Excel文档
  const wb = new ExcelJS.Workbook();
  const ws = wb.addWorksheet('Sheet1');

  // 将数据添加到工作表中
  data.forEach((row) => {
    ws.addRow(row);
  });

  // 将工作表保存为Excel文件
  wb.xlsx.writeBuffer().then((buffer) => {
    const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'data.xlsx';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
  });
}
</script>

在此示例中,我们使用了ExcelJS库来创建Excel文件。首先,我们创建一个包含数据的数组。然后,我们创建一个新的工作簿并将数据添加到名为“Sheet1”的工作表中。最后,我们将工作表保存为Excel文件并将其提供给用户进行下载。

赞赏作者

您的赞赏是对我最大的支持。