JavaScript 如何实现导出excel文件
黄舟
黄舟 2017-04-10 15:32:45
[JavaScript讨论组]

JavaScript 如何实现导出excel文件

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(3)
伊谢尔伦

js-xlsx

xlsx

Parser and writer for various spreadsheet formats. Pure-JS cleanroom
implementation from official specifications and related documents.

Supported read formats:

  • Excel 2007+ XML Formats (XLSX/XLSM)
  • Excel 2007+ Binary Format (XLSB)
  • Excel 2003-2004 XML Format (XML "SpreadsheetML")
  • Excel 97-2004 (XLS BIFF8)
  • Excel 5.0/95 (XLS BIFF5)
  • OpenDocument Spreadsheet (ODS)

Supported write formats:

  • XLSX
  • CSV (and general DSV)
  • JSON and JS objects (various styles)

Demo: http://oss.sheetjs.com/js-xlsx

Source: http://git.io/xlsx

PHP中文网

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.'));
黄舟

可以使用phpExcel
https://phpexcel.codeplex.com/

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号