简体   繁体   中英

Outline border for a range of cells in exceljs?

I come across this use case where I have to give outline borders for a range of cells (Start: A1 to C5 and End: A4 to C5) and I searched google for results but not getting properly. I want an outer border for a particular range and I used the below snippet code but not working

Code:
const workbook = new Workbook();    
      const loeTermsandConditionsWorksheet1 = workbook.addWorksheet('(dummy) page',{views:[
        {activeCell: 'A1', showGridLines:true}
        ]})
 //OUTER BRODER STARTS
      const createOuterBorder = (loeTermsandConditionsWorksheet1, start = {row: 1, col: 5}, end = {row: 4, col: 5}, borderWidth = 'medium') => {
        const borderStyle = {
            style: borderWidth
        };
        for (let i = start.row; i <= end.row; i++) {
            const leftBorderCell = loeTermsandConditionsWorksheet1.getCell(i, start.col);
            const rightBorderCell = loeTermsandConditionsWorksheet1.getCell(i, end.col);
            leftBorderCell.border = {
                ...leftBorderCell.border,
                left: borderStyle
            };
            rightBorderCell.border = {
                ...rightBorderCell.border,
                right: borderStyle
            };
        }
    
        for (let i = start.col; i <= end.col; i++) {
            const topBorderCell = loeTermsandConditionsWorksheet1.getCell(start.row, i);
            const bottomBorderCell = loeTermsandConditionsWorksheet1.getCell(end.row, i);
            topBorderCell.border = {
                ...topBorderCell.border,
                top: borderStyle
            };
            bottomBorderCell.border = {...bottomBorderCell.border, bottom: borderStyle};
        }
      
    };
    
    //OUTER BRODER END

this is what I am expecting:

示例图片

but not getting the correct result.

I don't know what your incorrect result is. But i use this for outer borders and it works as well! ExcelJS Outline border issue

Greetings, Florian

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM