How to create an Excel File with Nodejs?

前端 未结 10 890
攒了一身酷
攒了一身酷 2020-11-30 17:17

I am a nodejs programmer . Now I have a table of data that I want to save in Excel File format . How do I go about doing this ?

I found a few Node libraries . But m

10条回答
  •  时光取名叫无心
    2020-11-30 17:27

    Use msexcel-builder. Install it with:

    npm install msexcel-builder
    

    Then:

    // Create a new workbook file in current working-path 
    var workbook = excelbuilder.createWorkbook('./', 'sample.xlsx')
    
    // Create a new worksheet with 10 columns and 12 rows 
    var sheet1 = workbook.createSheet('sheet1', 10, 12);
    
    // Fill some data 
    sheet1.set(1, 1, 'I am title');
    for (var i = 2; i < 5; i++)
      sheet1.set(i, 1, 'test'+i);
    
    // Save it 
    workbook.save(function(ok){
      if (!ok) 
        workbook.cancel();
      else
        console.log('congratulations, your workbook created');
    });
    

提交回复
热议问题