我正在尝试使用closedxml在excel中创建一个表,我希望它的名称是带有空格的列,如图Table with spaces in its column's names所示。在默认情况下,名称不应该有空格,我尝试在创建表后重写这些名称,但即使我确定核心是黑色的,名称也会变得透明。
创建表的脚本是:
public static void CreateTable(IXLWorksheet ws, int beginRow, int beginColumn, List<SitesTableModel> list)
{
ws.Cell(beginRow, beginColumn).InsertTable(list.AsEnumerable());
var range5 = ws.Range(beginRow, beginColumn, beginRow+list.Count, beginColumn+5);
range5.Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
range5.Style.Font.FontColor = XLColor.TealBlue;
range5.Style.Font.FontName = "Arial";
range5.Style.Font.FontSize = 10;
range5.Style.Alignment.WrapText = true;
Cell cell = new Cell
{
fontColor = XLColor.Black,
textValue = "Nom du site",
fontName = "Arial",
bold = false,
fontSize = 10,
alignment = XLAlignmentHorizontalValues.Left,
};
SetCellValue(ws, beginRow, beginColumn, cell);
cell.textValue = "Adresse d'audit";
SetCellValue(ws, beginRow, beginColumn+1, cell);
cell.textValue = "Certifications demandées";
SetCellValue(ws, beginRow, beginColumn+2, cell);
cell.textValue = "Activités du site";
SetCellValue(ws, beginRow, beginColumn+3, cell);
cell.textValue = "Produits du site";
SetCellValue(ws, beginRow, beginColumn+4, cell);
}
答案 0 :(得分:0)
我不是ClosedXML的专家,但看起来你正在创建一个单元并一遍又一遍地使用它。我认为这样的事情会奏效:
public static void CreateTable(IXLWorksheet ws, int beginRow, int beginColumn, List<SitesTableModel> list)
{
var wsTable = ws.Cell(beginRow, beginColumn).InsertTable(list.AsEnumerable());
// Removed range stuff I don't understand
wsTable.Cell(beginRow, beginColumn).SetValue("Nom du site");
wsTable.Cell(beginRow, beginColumn+1).SetValue("Adresse d'audit");
wsTable.Cell(beginRow, beginColumn+2).SetValue("Certifications demandées");
wsTable.Cell(beginRow, beginColumn+3).SetValue("Activités du site");
wsTable.Cell(beginRow, beginColumn+4).SetValue("Produits du site");
}
编辑:这里似乎有一个很好的表格介绍:https://github.com/ClosedXML/ClosedXML-wiki/blob/master/Inserting-Tables.md