Skip to content

Commit

Permalink
Added an express example
Browse files Browse the repository at this point in the history
  • Loading branch information
KeeTraxx committed Dec 8, 2015
1 parent a21e3d8 commit da80f72
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Manipulate .xlsx files - easy.
* Support for other spreadsheet cell types (e.g. date, hours, etc.)

## TL;DR Simple Usage Examples

### Create a new .xlsx file from scratch

````javascript
var fs = require('fs');
var kexcel = require('kexcel');
Expand All @@ -37,4 +40,32 @@ kexcel.new().then(function (wb) {
sheet.setCellValue(1, 1, 'Hello world!');
return wb.pipe(fs.createWriteStream('output.xlsx'));
});
````

### Modify an existing .xlsx file and send it through a http response (express)
````javascript
var path = require('path');
var express = require('express');
var app = express();
var kexcel = require('kexcel');

app.get('/', function (req, res) {
kexcel.open(path.join(__dirname, 'example.xlsx')).then(function(workbook) {
var sheet = workbook.getSheet(0);
sheet.setCellValue(1,1,'Hello World!');
sheet.setRow(2, ['Hello', 'even', 'more', 'Worlds']);
sheet.setRow(3, [1, '+', 2, 'equals','=A3+C3']);

res.setHeader('Content-disposition', 'attachment; filename=example.xlsx');
res.setHeader('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
workbook.pipe(res);
});
});

var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;

console.log('KExcel app listening at http://%s:%s', host, port);
});
````

0 comments on commit da80f72

Please sign in to comment.