javascriptnode.jsxlsx-populate

Merge cells together in 'xlsx-populate' module for node js


I am using xlsx-populate module for making excel file, but I need merged some row and column together and set value to this. Anyone help to me for making this excel file?

for example merge merge(A1, C3) and add my value into big row.


Solution

  • Here's an example of creating merged cells using the xlsl-populate module.

    We create 2 sets of merged cells, I think this give you a good idea of how to proceed:

    const XlsxPopulate = require('xlsx-populate');
    
    async function testMerge() {
        let workbook = await XlsxPopulate.fromBlankAsync();
    
        // Create a range of merged cells.
        const range = workbook.sheet(0).range("A1:C3");
        range.value("We are merged!!");
        range.style({horizontalAlignment: "center", verticalAlignment: "center", })
        range.merged(true);
    
        // Create another range of merged cells.
        const range2 = workbook.sheet(0).range("D1:F3");
        range2.value("We are also merged!!");
        range2.style({horizontalAlignment: "center", verticalAlignment: "center", })
        range2.merged(true);
    
        // Write to the output file.
        await workbook.toFileAsync("./out.xlsx");
    }
    
    testMerge();