Hướng dẫn excel4node read-excel file - excel4node đọc tệp excel

Useful link

https://ciphertrick.com/read-excel-files-convert-json-node-js/

 var express = require('express'); 
    var app = express(); 
    var bodyParser = require('body-parser');
    var multer = require('multer');
    var xlstojson = require("xls-to-json-lc");
    var xlsxtojson = require("xlsx-to-json-lc");
    app.use(bodyParser.json());
    var storage = multer.diskStorage({ //multers disk storage settings
        destination: function (req, file, cb) {
            cb(null, './uploads/')
        },
        filename: function (req, file, cb) {
            var datetimestamp = Date.now();
            cb(null, file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1])
        }
    });
    var upload = multer({ //multer settings
                    storage: storage,
                    fileFilter : function(req, file, callback) { //file filter
                        if (['xls', 'xlsx'].indexOf(file.originalname.split('.')[file.originalname.split('.').length-1]) === -1) {
                            return callback(new Error('Wrong extension type'));
                        }
                        callback(null, true);
                    }
                }).single('file');
    /** API path that will upload the files */
    app.post('/upload', function(req, res) {
        var exceltojson;
        upload(req,res,function(err){
            if(err){
                 res.json({error_code:1,err_desc:err});
                 return;
            }
            /** Multer gives us file info in req.file object */
            if(!req.file){
                res.json({error_code:1,err_desc:"No file passed"});
                return;
            }
            /** Check the extension of the incoming file and 
             *  use the appropriate module
             */
            if(req.file.originalname.split('.')[req.file.originalname.split('.').length-1] === 'xlsx'){
                exceltojson = xlsxtojson;
            } else {
                exceltojson = xlstojson;
            }
            try {
                exceltojson({
                    input: req.file.path,
                    output: null, //since we don't need output.json
                    lowerCaseHeaders:true
                }, function(err,result){
                    if(err) {
                        return res.json({error_code:1,err_desc:err, data: null});
                    } 
                    res.json({error_code:0,err_desc:null, data: result});
                });
            } catch (e){
                res.json({error_code:1,err_desc:"Corupted excel file"});
            }
        })
    }); 
    app.get('/',function(req,res){
        res.sendFile(__dirname + "/index.html");
    });
    app.listen('3000', function(){
        console.log('running on 3000...');
    });

1.8.0 & nbsp; • & nbsp; public & nbsp; • & nbsp; xuất bản 4 tháng trướcPublic • Published 4 months ago

  • Readme
  • Khám phá BetaBETA
  • 11 phụ thuộc
  • 97 người phụ thuộc
  • 76 phiên bản

Hướng dẫn excel4node read-excel file - excel4node đọc tệp excel

Excel4Node

Một thư viện tạo tệp XLSX đầy đủ tính năng cho phép tạo các tệp Excel nâng cao.

Excel4Node phù hợp với đặc tả ECMA-376 OOXML Phiên bản thứ 2

TÀI LIỆU THAM KHẢO OpenXML Giấy trắng ECMA-376 Trang web OpenOffice excel Định dạng tệp tham chiếu OpenOffice Anatomy of OoxML Giải thích MS-XSLX Spec (PDF)
OpenXML White Paper
ECMA-376 Website
OpenOffice Excel File Format Reference
OpenOffice Anatomy of OOXML explanation
MS-XSLX spec (pdf)

Mã tài liệu tham khảo Thông số kỹ thuật Phần từ ECMA-376 Phiên bản thứ 2 DOC ECMA-376, Phiên bản thứ hai, Phần 1-Nguyên tắc cơ bản và tham chiếu ngôn ngữ đánh dấu.pdf được tìm thấy trong ECMA-376 Phiên bản thứ 2 Phần 1 Tải xuống tại http://www.ecma-International.org /publications/standards/ecma-376.htm
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

Cách sử dụng cơ bản

// 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 đi kèm với một số chức năng và loại chung

xl.getexcelrowcol (cellref) chấp nhận tham chiếu ô (tức là 'a1') và trả về đối tượng với hàng và cột tương ứng
Accepts cell reference (i.e. 'A1') and returns object with corresponding row and column

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}

xl.getexcelalpha (cột) chấp nhận cột là số nguyên và trả về tham chiếu cột tương ứng là alpha
Accepts column as integer and returns corresponding column reference as alpha

xl.getExcelAlpha(10);
// returns 'J'

xl.getexcelcellref (hàng, cột) chấp nhận hàng và cột làm số nguyên và trả về tham chiếu ô Excel
Accepts row and column as integers and returns Excel cell reference

xl.getExcelCellRef(5, 3);
// returns 'C5'

xl.getexcelts (ngày) chấp nhận đối tượng ngày và trả về dấu thời gian excel
Accepts Date object and returns an Excel timestamp

var newDate = new Date('2015-01-01T00:00:00.0000Z');
xl.getExcelTS(newDate);
// Returns 42004.791666666664

xl.PAPER_SIZE

Sách bài tập

Một thể hiện của lớp sổ làm việc chứa tất cả dữ liệu và tham số cho sổ làm việc Excel.

Người xây dựng

Trình xây dựng sổ làm việc chấp nhận một đối tượng cấu hình tùy chọn.

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
});

Phương pháp

wb.addworksheet (tên, tùy chọn); Thêm một bảng tính mới vào sổ làm việc chấp nhận tên của bảng tính mới và đối tượng tùy chọn (xem phần bảng tính) Trả về một phiên bản bảng tính
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); Các bộ tab nào sẽ được chọn khi sổ làm việc được mở ADE
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); Tạo một thể hiện kiểu mới chấp nhận đối tượng cấu hình kiểu (xem phần kiểu) Trả về một thể hiện kiểu mới
Creates a new Style instance
Accepts Style configuration object (see Style section) Returns a new Style instance

wb.write (); Phương thức write () có thể chấp nhận một tên tệp, tên tệp có hàm gọi lại hoặc đối tượng phản hồi HTTP.
The write() method can accept a single filename, a filename with callback function or an HTTP response object.

var xl = require('excel4node');
var wb = new xl.Workbook();
wb.write('ExcelFile.xlsx'); // Writes the file ExcelFile.xlsx to the process.cwd();

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
  }
});

// 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 (); Phương thức WritetObuffer () không có tham số và trả về một lời hứa giải quyết với NodeBuffer được tạo bởi thư viện JSZIP. Bộ đệm này sau đó có thể được gửi đến các luồng khác.
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.

// 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');
0

Bảng tính

Một thể hiện của lớp bảng tính chứa tất cả thông tin cụ thể cho bảng tính đó

Người xây dựng

Trình xây dựng sổ làm việc chấp nhận một đối tượng cấu hình tùy chọn.

// 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');
1

Phương pháp

// 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');
2

wb.addworksheet (tên, tùy chọn); Thêm một bảng tính mới vào sổ làm việc chấp nhận tên của bảng tính mới và đối tượng tùy chọn (xem phần bảng tính) Trả về một phiên bản bảng tính headerFooter strings accept Dynamic Formatting Strings. i.e. '&L&A&C&BCompany, Inc. Confidential&B&RPage &P of &N'

Phương pháp

wb.addworksheet (tên, tùy chọn); Thêm một bảng tính mới vào sổ làm việc chấp nhận tên của bảng tính mới và đối tượng tùy chọn (xem phần bảng tính) Trả về một phiên bản bảng tính

wb.setselectedtab (id); Các bộ tab nào sẽ được chọn khi sổ làm việc được mở ADE
Accepts a validation options object with these available options. All options are optional with exception of sqref.

WB.CreateStyle (OPTS); Tạo một thể hiện kiểu mới chấp nhận đối tượng cấu hình kiểu (xem phần kiểu) Trả về một thể hiện kiểu mới

// 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');
4

wb.write (); Phương thức write () có thể chấp nhận một tên tệp, tên tệp có hàm gọi lại hoặc đối tượng phản hồi HTTP.

wb.writetobuffer (); Phương thức WritetObuffer () không có tham số và trả về một lời hứa giải quyết với NodeBuffer được tạo bởi thư viện JSZIP. Bộ đệm này sau đó có thể được gửi đến các luồng khác.
Formatting rules apply at the worksheet level.
The following example will highlight all cells between A1 and A10 that contain the string "ok" with bold, green text:

// 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');
5

Bảng tính
When the formula returns zero, conditional formatting is NOT displayed. When the formula returns a nonzero value, conditional formatting is displayed.

Một thể hiện của lớp bảng tính chứa tất cả thông tin cụ thể cho bảng tính đó

Trình xây dựng bảng tính được gọi qua lớp sổ làm việc và chấp nhận đối tượng tên và cấu hình

Tùy chọn bảng tính đầy đủ. Tất cả các tùy chọn là tùy chọn.

// 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');
6

Lưu ý: Chuỗi tiêu đề Chấp nhận chuỗi định dạng động. tức là '& l & a & c & bcompany, Inc.

Xác nhận dữ liệu bảng tính

ws.adddatavalidation (); Chấp nhận một đối tượng Tùy chọn xác thực với các tùy chọn có sẵn này. Tất cả các tùy chọn là tùy chọn ngoại trừ SQREF.

// 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');
7

// 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');3

Bảng tính định dạng có điều kiện

// 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');
8

Định dạng có điều kiện thêm các định dạng tùy chỉnh để đáp ứng với trạng thái tham chiếu ô. Một tập hợp con của các tính năng định dạng có điều kiện hiện được hỗ trợ bởi Excel4Node. Quy tắc định dạng áp dụng ở cấp bảng tính. Ví dụ sau đây sẽ làm nổi bật tất cả các ô giữa A1 và A10 có chứa chuỗi "OK" với văn bản màu xanh lá cây, màu xanh lá cây:

// 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');
9

Loại định dạng có điều kiện duy nhất hiện được hỗ trợ là biểu thức. Khi công thức trả về 0, định dạng có điều kiện không được hiển thị. Khi công thức trả về một giá trị khác, định dạng có điều kiện được hiển thị.

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
0

Trang web bị phá vỡ trang

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
1

Có thể thêm các lần ngắt trang trang tính ở hàng và cột

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
2

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
9 trong đó loại là
xl.getExcelAlpha(10);
// returns 'J'
0 hoặc
xl.getExcelAlpha(10);
// returns 'J'
1 và vị trí là hàng/cột cuối cùng trước khi ngắt trang.

Khu vực in bảng tính

Các khu vực in bảng tính có thể được đặt
cell method takes two required parameters and 3 optional parameters
.string() accepts a String or Array. Sending array allows for multiple font formattings within the same cell.
.number(number) accepts a number
.formula(formula) accepts an Excel formula
.date(date) accepts either a date or a date string
.link(url, [displayStr, tooltip]) accepts a URL and optionally a displayStr and hover tooltip
.bool(value) accepts a boolean (true or false)
.style(object) accepts the same object as when creating a new style. When applied to a cell that already has style formatting, the original formatting will be kept and updated with the changes sent to the style function. .comment(comment, options) Add a comment to the particular cell

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
3

Phong cách

Các đối tượng kiểu có thể được áp dụng cho các ô bất kỳ kết hợp các giá trị kiểu nào cũng có thể được đặt tạo ra kiểu đặt trước hiệu quả hơn nhiều so với việc áp dụng các kiểu
Any combination of style values can be set
Creating a preset style is much more efficient than applying styles to individual cells

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
4

Bình luận

Nhận xét có thể được thêm vào các ô với một số tùy chọn

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
5

Hình ảnh

Thêm và hình ảnh vào bảng tính.Hiện tại loại 'Hình ảnh' được hỗ trợ định vị có 3 loại, 'Tuyệt đối'Góc bên trái của bảng tính OneCellanchor và Twocellanchor sẽ lấy các đối tượng vị trí:
currently on 'picture' type is supported
positioning has 3 types, 'absoluteAnchor', 'oneCellAnchor', 'twoCellAnchor'
absoluteAnchor takes two position elements in either EMUs or measurements in cm, mm, or in
x:0, y:0 is top left corner of worksheet
oneCellAnchor and twoCellAnchor types will take positional objects:

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
6

Loại vị trí của OneCellanchor sẽ lấy một "vị trí" vị trí của loại twocellanchor sẽ lấy một vị trí "từ" và "đến" chỉ định một twocellanchor sẽ tự động điều chỉnh hình ảnh để phù hợp với giới hạn của hai mỏ neo.
position type of twoCellAnchor will take a "from" and "to" position
specifying a twoCellAnchor will automatically adjust the image to fit within the bounds of the two anchors.

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
7

Bạn cũng có thể chuyển bộ đệm với hình ảnh được tải vào bộ nhớ:

xl.getExcelRowCol('B5');
// returns { row: 5, col: 2}
8