在左侧,右侧,底部和顶部更改Excel中的边框

首先,我把我的纸的彩色边框改为白色,因为我想要一张白纸。 然后我做了一些标题,并想围绕它的边界。 问题是它使标题中的值之间的边界,但顶部,下来是不可见的。

我的代码:

xlWorkSheet5.Columns.Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White); // Color Sheet5 to white, BusLoad xlWorkSheet5.Columns.NumberFormat = "@"; Excel.Range rng = (Excel.Range)xlWorkSheet5.get_Range("A7","J7"); rng.RowHeight = 25.5; rng.BorderAround2(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic); rng.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; rng.Borders.Weight = 1d; rng.Font.Bold = true; rng.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; rng.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray); 

好的,我find了解决办法,这是我的代码:

 xlWorkSheet5.Cells[7,1].Borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = 1d; xlWorkSheet5.Cells[7, 1].Borders[Excel.XlBordersIndex.xlEdgeRight].Weight = 1d; xlWorkSheet5.Cells[7,1].Borders[Excel.XlBordersIndex.xlEdgeTop].Weight = 1d; xlWorkSheet5.Cells[7,1].Borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = 1d; 

如果你想使用边界[索引]属性,然后使用的东西沿线:

 rng.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlContinuous; rng.Borders[XlBordersIndex.xlEdgeLeft].ColorIndex = <COLOR THAT YOU WANT> rng.Borders[XlBordersIndex.xlEdgeTop]... rng.Borders[XlBordersIndex.xlEdgeBottom]... rng.Borders[XlBordersIndex.xlEdgeRight]... 

Border.Weight属性

XlBorderWeight可以是这些XlBorderWeight常量之一:xlHairline xlThin xlMedium xlThick。

从Bx到Mx的单元格上创build连续线的示例,其中x是行数

 using Excel = Microsoft.Office.Interop.Excel; Excel.Range line = (Excel.Range)excelWorksheet.Rows[1]; line.Insert(); excelWorksheet.Range[$"B{1}:M{1}"].Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous; excelWorksheet.Range[$"B{1}:M{1}"].Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin;