JavaScript 如何实现导出excel文件
js-xlsx
比较难用,代码比较混乱,而且导出带样式的也比较麻烦,最近写了一个,导出还算方便,项目地址:https://github.com/d-band/bet...
附一个简单的 Demo:
const fs = require('fs');
const xlsx = require('better-xlsx');
const file = new xlsx.File();
const sheet = file.addSheet('Sheet1');
const row = sheet.addRow();
const cell = row.addCell();
cell.value = 'I am a cell!';
cell.hMerge = 2;
cell.vMerge = 1;
const style = new xlsx.Style();
style.fill.patternType = 'solid';
style.fill.fgColor = '00FF0000';
style.fill.bgColor = 'FF000000';
style.align.h = 'center';
style.align.v = 'center';
cell.style = style;
file
.saveAs()
.pipe(fs.createWriteStream(__dirname + '/simple.xlsx'))
.on('finish', () => console.log('Done.'));
可以借助 SpreadJS 表格控件来实现。无需任何后台代码和第三方组件!SpreadJS 可直接在浏览器中完成 Excel、CSV、JSON 等文件的导入导出、PDF 导出、打印及预览操作.
SpreadJS 支持在线导入和导出 Excel (.xlsx),使用该功能,用户可在浏览器中加载并修改各种 Excel 文档,并将修改后的数据保存到数据库中。
13 回答12.9k 阅读
7 回答2.1k 阅读
3 回答1.3k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
6 回答1.2k 阅读✓ 已解决
6 回答1.1k 阅读
3 回答1.3k 阅读✓ 已解决
js-xlsx
xlsx
Parser and writer for various spreadsheet formats. Pure-JS cleanroom
implementation from official specifications and related documents.
Supported read formats:
Supported write formats:
Demo: http://oss.sheetjs.com/js-xlsx
Source: http://git.io/xlsx