[![NPM version](https://img.shields.io/npm/v/excel4node.svg)](https://www.npmjs.com/package/excel4node)
[![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
[![npm](https://img.shields.io/npm/dt/excel4node.svg)](https://www.npmjs.com/package/excel4node)
[![node](https://img.shields.io/node/v/excel4node.svg)](https://nodejs.org/en/download/)
[![Build Status](https://travis-ci.org/natergj/excel4node.svg?branch=master)](https://travis-ci.org/natergj/excel4node)
[![dependencies Status](https://david-dm.org/natergj/excel4node/status.svg)](https://david-dm.org/natergj/excel4node)
[![devDependency Status](https://david-dm.org/natergj/excel4node/dev-status.svg)](https://david-dm.org/natergj/excel4node#info=devDependencies)
# excel4node
A full featured xlsx file generation library allowing for the creation of advanced Excel files.
excel4node conforms to the ECMA-376 OOXML specification 2nd edition
REFERENCES
[OpenXML White Paper](http://www.ecma-international.org/news/TC45_current_work/OpenXML%20White%20Paper.pdf)
[ECMA-376 Website](http://www.ecma-international.org/publications/standards/Ecma-376.htm)
[OpenOffice Excel File Format Reference](http://www.openoffice.org/sc/excelfileformat.pdf)
[OpenOffice Anatomy of OOXML explanation](http://officeopenxml.com/anatomyofOOXML-xlsx.php)
[MS-XSLX spec (pdf)](http://download.microsoft.com/download/D/3/3/D334A189-E51B-47FF-B0E8-C0479AFB0E3C/%5BMS-XLSX%5D.pdf)
Code references specifications sections from ECMA-376 2nd edition doc
ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference.pdf
found in ECMA-376 2nd edition Part 1 download at [http://www.ecma-international.org/publications/standards/Ecma-376.htm](http://www.ecma-international.org/publications/standards/Ecma-376.htm)
### Basic Usage
```javascript
// Require library
var xl = require('excel4node');
// Create a new instance of a Workbook class
var wb = new xl.Workbook();
// Add Worksheets to the workbook
var ws = wb.addWorksheet('Sheet 1');
var ws2 = wb.addWorksheet('Sheet 2');
// Create a reusable style
var style = wb.createStyle({
font: {
color: '#FF0800',
size: 12,
},
numberFormat: '$#,##0.00; ($#,##0.00); -',
});
// Set value of cell A1 to 100 as a number type styled with paramaters of style
ws.cell(1, 1)
.number(100)
.style(style);
// Set value of cell B1 to 200 as a number type styled with paramaters of style
ws.cell(1, 2)
.number(200)
.style(style);
// Set value of cell C1 to a formula styled with paramaters of style
ws.cell(1, 3)
.formula('A1 + B1')
.style(style);
// Set value of cell A2 to 'string' styled with paramaters of style
ws.cell(2, 1)
.string('string')
.style(style);
// Set value of cell A3 to true as a boolean type styled with paramaters of style but with an adjustment to the font size.
ws.cell(3, 1)
.bool(true)
.style(style)
.style({font: {size: 14}});
wb.write('Excel.xlsx');
```
## excel4node
excel4node comes with some generic functions and types
xl.getExcelRowCol(cellRef)
Accepts cell reference (i.e. 'A1') and returns object with corresponding row and column
```javascript
xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
```
xl.getExcelAlpha(column)
Accepts column as integer and returns corresponding column reference as alpha
```javascript
xl.getExcelAlpha(10);
// returns 'J'
```
xl.getExcelCellRef(row, column)
Accepts row and column as integers and returns Excel cell reference
```javascript
xl.getExcelCellRef(5, 3);
// returns 'C5'
```
xl.getExcelTS(date)
Accepts Date object and returns an Excel timestamp
```javascript
var newDate = new Date('2015-01-01T00:00:00.0000Z');
xl.getExcelTS(newDate);
// Returns 42004.791666666664
```
xl.PAPER_SIZE
## Workbook
An instance of the Workbook class contains all data and parameters for the Excel Workbook.
#### Constructor
Workbook constructor accepts an optional configuration object.
```javascript
var xl = require('excel4node');
var wb = new xl.Workbook({
jszip: {
compression: 'DEFLATE',
},
defaultFont: {
size: 12,
name: 'Calibri',
color: 'FFFFFFFF',
},
dateFormat: 'm/d/yy hh:mm:ss',
workbookView: {
activeTab: 1, // Specifies an unsignedInt that contains the index to the active sheet in this book view.
autoFilterDateGrouping: true, // Specifies a boolean value that indicates whether to group dates when presenting the user with filtering options in the user interface.
firstSheet: 1, // Specifies the index to the first sheet in this book view.
minimized: false, // Specifies a boolean value that indicates whether the workbook window is minimized.
showHorizontalScroll: true, // Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
showSheetTabs: true, // Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
showVerticalScroll: true, // Specifies a boolean value that indicates whether to display the vertical scroll bar.
tabRatio: 600, // Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
visibility: 'visible', // Specifies visible state of the workbook window. ('hidden', 'veryHidden', 'visible') (§18.18.89)
windowHeight: 17620, // Specifies the height of the workbook window. The unit of measurement for this value is twips.
windowWidth: 28800, // Specifies the width of the workbook window. The unit of measurement for this value is twips..
xWindow: 0, // Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
yWindow: 440, // Specifies the Y coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
},
logLevel: 0, // 0 - 5. 0 suppresses all logs, 1 shows errors only, 5 is for debugging
author: 'Microsoft Office User', // Name for use in features such as comments
});
```
#### Methods
wb.addWorksheet(name, options);
Adds a new Worksheet to the Workbook
Accepts name of new Worksheet and options object (see Worksheet section)
Returns a Worksheet instance
wb.setSelectedTab(id);
Sets which tab will be selected when the Workbook is opened
Accepts Sheet ID (1-indexed sheet in order that sheets were added)
wb.createStyle(opts);
Creates a new Style instance
Accepts Style configuration object (see Style section)
Returns a new Style instance
wb.write();
The write() method can accept a single filename, a filename with callback function or an HTTP response object.
```javascript
var xl = require('excel4node');
var wb = new xl.Workbook();
wb.write('ExcelFile.xlsx'); // Writes the file ExcelFile.xlsx to the process.cwd();
```
```javascript
wb.write('ExcelFile.xlsx', function(err, stats) {
if (err) {
console.error(err);
} else {
console.log(stats); // Prints out an instance of a node.js fs.Stats object
}
});
```
```javascript
// sends Excel file to web client requesting the / route
// server will respond with 500 error if excel workbook cannot be generated
var express = require('express');
var app = express();
app.get('/', function(req, res) {
wb.write('ExcelFile.xlsx', res);
});
app.listen(3000, function() {
console.log('Example app listening on port 3000!');
});
```
wb.writeToBuffer();
The writeToBuffer() method access no parameters and returns a promise that resolves with the nodebuffer generated by the JSZip library. This buffer can then be sent to other streams.
```javascript
var xl = require('excel4node');
var wb = new xl.Workbook();
wb.writeToBuffer().then(function(buffer) {
// Do something with buffer
});
```
## Worksheet
An instance of the Worksheet class contains all information specific to that worksheet
#### Constructor
Worksheet constructor is called via Workbook class and accepts a name and configuration object
```javascript
var xl = require('excel4node');
var wb
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
Nodejs导出Excel带图片,Nodejs后台导出带图片Excel (211个子文件)
mime.cmd 170B
说明.doc 181KB
thumbsUp.jpg 48KB
thumbs-up.jpg 28KB
builder.js 26KB
builder.js 26KB
worksheet.test.js 23KB
builder.js 21KB
builder.js 21KB
sample.js 20KB
worksheet.js 20KB
worksheet.js 17KB
style.test.js 15KB
index.js 14KB
workbook.js 13KB
index.js 12KB
style.js 12KB
workbook.js 11KB
style.js 10KB
picture.js 10KB
dataValidation.js 9KB
row.js 9KB
test.js 9KB
fill.js 8KB
dataValidation.js 8KB
utils.js 7KB
picture.js 7KB
row.js 7KB
utils.js 7KB
alignment.js 7KB
border.js 7KB
fill.js 7KB
font.js 7KB
drawing.js 6KB
optsValidator.js 6KB
alignment.js 6KB
font.js 5KB
optsValidator.js 5KB
paperSize.js 5KB
paperSize.js 5KB
border.js 5KB
column.js 5KB
definedNameCollection.js 5KB
drawing.js 4KB
emu.js 4KB
dataValidations.test.js 4KB
column.js 4KB
definedNameCollection.js 3KB
cell.test.js 3KB
hyperlink.js 3KB
cell.js 3KB
excelColor.js 3KB
excelColor.js 3KB
library.test.js 3KB
sheet_default_params.js 3KB
ctColor.js 3KB
sheet_default_params.js 3KB
emu.js 3KB
Mime.js 3KB
ctMarker.js 3KB
cf_rule.js 3KB
dxfCollection.js 3KB
image.test.js 2KB
alignment.js 2KB
alignment.js 2KB
cf_rules_collection.js 2KB
logger.js 2KB
hyperlink.js 2KB
index.js 2KB
cell.js 2KB
numberFormat.js 2KB
build.js 2KB
ctColor.js 2KB
unicodestring.test.js 2KB
cf_rule.js 2KB
ctMarker.js 2KB
mediaCollection.js 1KB
index.js 1KB
index.js 1KB
row.test.js 1KB
dxfCollection.js 1KB
workbook.test.js 1KB
cf_rule.test.js 1KB
comment.js 1KB
column.test.js 1023B
fillPattern.js 997B
cf_rules_collection.js 976B
cf_rule_types.js 929B
fillPattern.js 910B
fontFamily.js 889B
borderStyle.js 874B
cf_rule_types.js 873B
comment.js 866B
fontFamily.js 850B
colorScheme.js 837B
borderStyle.js 832B
numberFormat.js 816B
colorScheme.js 813B
hyperlink.test.js 775B
index.js 714B
共 211 条
- 1
- 2
- 3
慕云枫
- 粉丝: 274
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mmqrcode1714153659780.png
- Screenshot_2024-04-27-06-08-58-486_com.baidu.xin.aiqicha.jpg
- 基于Javaweb+Tomcat+MySQL的大学生公寓管理系统+sql文件.zip
- 实训作业基于javaweb的订单管理系统源码+数据库+实训报告.zip
- 多机调度问题贪心算法基于最小堆和贪心算法求解多机调度问题.zip
- 基于同态加密技术的匿名电子投票系统源码.zip
- Pyqt5项目框架-PyQt项目开发实践
- 基于C通过MQTT的智能农业大棚管理系统(本科毕业设计)
- python+CNN的网络入侵检测算法源码.zip
- js 实现记住密码功能 js.cookie.min.js
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0