NODE-SHEET
A simple option based on the exceljs library to create spreadsheets.
Disclaimer
The project is under development and is not fit to be used in real projects.
🚀
Installing node-sheet
To install the node-sheet, simply turn the command:
npm install node-sheet
or
yarn add node-sheet
☕
Using node-sheet
Here's an example of how to create a basic spreadsheet
import { Workbook, Worksheet } from 'node-sheet'
void (async () => {
const workbook = new Workbook();
const worksheet = new Worksheet('Test page');
worksheet.setColumns([
{
key: 'col-a',
},
{
key: 'col-b',
},
{
key: 'col-c',
},
]);
worksheet.addRows([
{
'col-a': 'Column A',
'col-b': 'Column B',
'col-c': 'Column C',
},
{
'col-a': 'Column A',
'col-b': 'Column B',
'col-c': 'Column C',
},
]);
workbook.addWorksheet(worksheet);
await workbook.export('test-sheet.xlsx');
})();
You can insert multiple pages into a worksheet. To create a new page, create a new page instance.
new Worksheet('Page name');
Define the columns that you will use in your worksheet with the setColumns method.
const workbook = new Workbook();
const worksheet = new Worksheet('Page name');
worksheet.setColumns([
{
key: 'col-a',
// You can explore some styles within the object
// but your implementation may contain bugs
},
{
key: 'col-b',
},
{
key: 'col-c',
},
]);
After you define the columns, you can insert columns by setting the keys. Each key represents a cell in a row and is not required making the cell empty.
const workbook = new Workbook();
const worksheet = new Worksheet('Page name');
worksheet.setColumns([
{
key: 'col-a',
// You can explore some styles within the object
// but your implementation may contain bugs
},
{
key: 'col-b',
},
{
key: 'col-c',
},
]);
worksheet.addRows([
{
'col-a': 'Column A',
'col-b': 'Column B',
'col-c': 'Column C',
},
{
'col-a': 'Column A',
'col-b': 'Column B',
'col-c': 'Column C',
},
]);
After you insert all the rows you want, insert the page into the worksheet.
const workbook = new Workbook();
const worksheet = new Worksheet('Page name');
worksheet.setColumns([
{
key: 'col-a',
// You can explore some styles within the object
// but your implementation may contain bugs
},
{
key: 'col-b',
},
{
key: 'col-c',
},
]);
worksheet.addRows([
{
'col-a': 'Column A',
'col-b': 'Column B',
'col-c': 'Column C',
},
{
'col-a': 'Column A',
'col-b': 'Column B',
'col-c': 'Column C',
},
]);
workbook.addWorksheet(worksheet);
// Export the spreadsheet
await workbook.export('test-sheet.xlsx');
📫
Contributing to node-sheet
To contribute node-sheet, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <nome_branch>
. - Make your changes and confirm them:
git commit -m '<mensagem_commit>'
- Climb your changes:
git push
- Create the pull request.
Alternatively, see the GitHub documentation at how to create a pull request.
🤝
Contributors
We thank the following people who contributed to this project:
Pedro Henrique |