Microsoft.Office.Interop.Excel:如何将边框应用于ONE CELL

Van*_*rad 7 c# excel border cell excel-interop

我想使用Microsoft.Office.Interop.Excel库将边框应用于一个单元格.

我正在运行一个while循环,它在某个列中搜索一个空单元格,一旦找到单元格,我想对它应用边框.

我知道有很多关于这个使用Ranges的论坛,但我不能使用范围功能,因为我不知道它正在应用于哪个单元格.

我的想法是:

(Excel.Range)xlWS.Cells [row,1] .Borders.LineStyle =(Whatever Value);

有什么建议?(除了链接到其他论坛,我已经看过很多表格)?

Van*_*rad 14

            Excel.Range range = xlWS.UsedRange;
            Excel.Range cell = range.Cells[row,column];
            Excel.Borders border = cell.Borders;

            border.LineStyle = Excel.XlLineStyle.xlContinuous;
            border.Weight = 2d;
Run Code Online (Sandbox Code Playgroud)

希望这有助于某人!在单元格[行,列]周围放置细线边框!


jiv*_*son 11

    Microsoft.Office.Interop.Excel.Range range = sheet.UsedRange;
    Microsoft.Office.Interop.Excel.Range cell = range.Cells[1][1];
    Microsoft.Office.Interop.Excel.Borders border = cell.Borders;
    border[XlBordersIndex.xlEdgeLeft].LineStyle =
        Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
    border[XlBordersIndex.xlEdgeTop].LineStyle =
        Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
    border[XlBordersIndex.xlEdgeBottom].LineStyle =
        Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
    border[XlBordersIndex.xlEdgeRight].LineStyle =
        Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅此答案.