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

后端 未结 8 1499
无人共我
无人共我 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:52

    This is the code that sets a border around each cell:

    xlWS.get_Range("C9", "N9").Cells.Borders.Weight = XL.XlBorderWeight.xlMedium;
    
    0 讨论(0)
  • 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 );
    
    0 讨论(0)
提交回复
热议问题