For Vue programmers, a great excel file creation library with full format is required. It's Excel4node.

Excel4node is a node.js module that allows you to create and manipulate Microsoft Excel spreadsheets.

It's easy to use as generating Excel files with complex formatting, formulas, and charts, hide sheet, protection sheet,...


1. Simple: it is simple to makes it easy to generate Excel files in just a few lines of code.
2. Formulas: can add and edit formulas in your spreadsheet.
3. Charts: can create charts and graphs in your Excel files.
4. Flexibility: allows to create and modify Excel files with a variety of formatting options, including cell alignment, font style and color, and background color.


1. Read: don't support function read file in lib, must use other lib to read.
2. Environment: some time, when export at other environment and get it to read have problem.


I would like to show you how to use it in Vuejs.

The first : We need to install package excel4node

+ Open cmd of windows and go to project: I use project Demo in here D:\.

cmd : D:\Demo\web>npm i excel4node

+ Import the library into the project : To use this library, We need import it to project.

// Require library
var xl = require('excel4node');

+  Create file excel with sheet name [sheet 1] with 5 column and 3 row have special template

+ Create css common apply for excel : border color 000000, style thin , font-size = 11, font family MS PGothic

+ Apply column B to column F , Line 2 to line 5 

// Apply

ws1.cell(2, 2, 5, 6, false).style(styleBorder)

+ Add data to column 

B2 :
. have text : Text demo 1
. (text bold) : text is bold
. text red) : text is red color
C2 :
. have text : Text demo 2
. (text bold) : text is bold
. text red) : text is red color

D2 :
. have text : Text demo 3
E2 :
. have text : Text demo 4
F2 :
. have text : Text demo 5

+ Finally we will get the excel file as expected : 

  1. Column B to column F , line 2 to line 5 : have border
  2. Column B to column E , line 2 to line 5 : have background #fcd5b4
  3. Column B and column C , line 2 have text data as format

[Reference Source]

Leave a comment