我正在使用iceblue Spire.XLS
dll
使用C#创建和生成Excel文档
我想知道如何设置特定单元格或单元格范围的边框样式(只是左边或右边的样式!)。
在上面的代码中,我设法设置了字体和对齐方式 但我不知道如何设置左右边框样式:
Workbook workbook = new Workbook();
workbook.LoadFromStream(templateDocument);
Worksheet sheet = workbook.Worksheets["sheet_name"];
sheet.Range[row, 1, row, 4].Merge();
sheet.Range[row, 1, row, 4].Style.HorizontalAlignment = HorizontalAlignType.Center;
sheet.Range[row, 1, row, 4].Style.VerticalAlignment = VerticalAlignType.Center;
sheet.Range[row, 1, row, 4].Style.Font.Size = 14;
sheet.Range[row, 1, row, 4].Style.Font.Color =Color.White;
sheet.Range[row, 1, row, 4].Style.Interior.Color = Color.Gray;
// syntax to achive styling border ??
//sheet.Range[row, 1, row, 4].Borders. = ?
问候。
答案 0 :(得分:4)
是的,你可以这样做:
适用于所有国家/地区:
一个单元格:
sheet.Range[row,col].Style.Borders.LineStyle = LineStyleType.Thin;
sheet.Range[row,col].Style.Borders.Color = Color.Black;
细胞范围:
sheet.Range[beginRow, beginCol, endRow, endCol].Style.Borders.LineStyle =LineStyleType.Thin;
sheet.Range[beginRow, beginCol, endRow, endCol].Style.Borders.Color = Color.Black;
对于特定边框边缘:(左上方顶部):
一个单元格:
//right border
sheet.Range[row,col].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;
sheet.Range[row,col].Style.Borders[BordersLineType.EdgeRight].Color = Color.Black;
//left border
sheet.Range[row,col].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;
sheet.Range[row,col].Style.Borders[BordersLineType.EdgeLeft].Color = Color.Black;
细胞范围:
//right border
sheet.Range[beginRow, beginCol, endRow, endCol].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;
sheet.Range[beginRow, beginCol, endRow, endCol].Style.Borders.Color = Color.Black;
//left border
sheet.Range[beginRow, beginCol, endRow, endCol].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;
sheet.Range[beginRow, beginCol, endRow, endCol].Style.Borders.Color = Color.Black;