nodejs操作Excel表格


//1 .安裝exceljs
npm i exceljs -D 

var Excel = require('exceljs');
var start_time = new Date();
var workbook = new Excel.stream.xlsx.WorkbookWriter({
    filename: './streamed-workbook.xlsx'
});
var worksheet = workbook.addWorksheet('Sheet');

worksheet.columns = [
    { header: 'userId', key: 'userId' },
    { header: 'prizeDesc', key: 'prizeDesc' }
];
var tempdata = [{
    "prizeDesc": "0",
    "activityKey": "0",
    "nickName": "0",
    "prizeType": 2,
    "userId": "0",
    "prizeId": 92,
    "status": 1,
    "goodsType": 0
}];
var data = require("./data.js").data;

var length = data.length;

// 當前進度
var current_num = 0;
var time_monit = 400;
var temp_time = Date.now();

console.log('開始添加數據');
// 開始添加數據
for(let i in data) {
    worksheet.addRow(data[i]).commit();
    current_num = i;
    if(Date.now() - temp_time > time_monit) {
        temp_time = Date.now();
        console.log((current_num / length * 100).toFixed(2) + '%');
    }
}
console.log('添加數據完畢:', (Date.now() - start_time));
workbook.commit();

var end_time = new Date();
var duration = end_time - start_time;

console.log('用時:' + duration);
console.log("程序執行完畢");






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM