WeihanLi/WeihanLi.Npoi

如何实现头部粗体或者不同的颜色的

Closed this issue · 4 comments

如何实现头部粗体或者不同的颜色的

暂时不支持样式配置

新发布了一个预览版 1.16.0-preview-20210306-055310,写了一个简单的示例,可以参考:

private static void FluentSettingsForExcel()

var setting = FluentSettings.For<TestEntity>();
// ExcelSetting
setting.HasAuthor("WeihanLi")
    .HasTitle("WeihanLi.Npoi test")
    .HasDescription("WeihanLi.Npoi test")
    .HasSubject("WeihanLi.Npoi test");

setting.HasSheetSetting(config =>
{
    config.StartRowIndex = 1;
    config.SheetName = "SystemSettingsList";
    config.AutoColumnWidthEnabled = true;

    config.RowAction = row =>
    {
        if (row.RowNum == 0)
        {
            var style = row.Sheet.Workbook.CreateCellStyle();
            style.Alignment = HorizontalAlignment.Center;
            var font = row.Sheet.Workbook.CreateFont();
            font.FontName = "JetBrains Mono";
            font.IsBold = true;
            font.FontHeight = 200;
            style.SetFont(font);
            row.Cells.ForEach(c => c.CellStyle = style);
        }
    };
});
//...

导出效果如下:
export result

fixed by #106 ,请使用 1.16.0 及以上版本,如果使用过程中有问题,欢迎重新提 issue