How can a border be set around multiple cells in excel using C#

后端 未结 8 1515
无人共我
无人共我 2020-12-18 22:18

I am working on a project that creates excel files.

I am having trouble placing a border on multiple cells to organize the excel file.

Let\'s say I want a b

8条回答
  •  青春惊慌失措
    2020-12-18 22:53

    This code puts a border around the area from (row1,col1) to (row2,col2). Individual cells do not get a border. The variable color is an integer color index number. See http://www.databison.com/excel-color-palette-and-color-index-change-using-vba/ for a list of index numbers and their corresponding colors.

        Range cell1 = worksheet.Cells[row1,col1];
        Range cell2 = worksheet.Cells[row2,col2];
        Range range = worksheet.get_Range(cell1,cell2);
        range.BorderAround(
            Type.Missing, XlBorderWeight.xlThick, (XlColorIndex)color, Type.Missing );
    

提交回复
热议问题