c# - 在 Excel 工作表顶部添加额外的标题行 [EPPlus]

标签 c# asp.net epplus

我正在使用网络应用程序。在那里,我应该将数据导出到 excel。为此,我使用了 EPPlus。

我搜索了很多但找不到在 Excel 工作表顶部添加额外行的方法。请查看下图以更好地理解这个想法。

enter image description here

我尝试合并标题,但我不会得到其他标题,所以我认为“在顶部添加额外的行”将是一个更好的短语。

我没有义务使用 EPPlus。如果有其他方法,我一定会去尝试。

谁能帮我解决这个问题?非常感谢您的回复。

最佳答案

您想要的是合并单元格。你可以这样做:

 ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
 ws.Cells["A1:G1"].Merge = true;

并继续使用 EPPlus。非常好

其他格式示例:

using (ExcelRange Title = Cells[1, 1, 1, dt.Columns.Count]) {
    Title.Merge = true;
    Title.Style.Font.Size = 18;
    Title.Style.Font.Bold = true;
    Title.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
    Title.Style.Fill.BackgroundColor.SetColor(systemColor);
    Title.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
    Title.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
    Title.Style.TextRotation = 90;
    Title.Value = "This is my title";
}

关于c# - 在 Excel 工作表顶部添加额外的标题行 [EPPlus],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18016340/

相关文章:

c# - 单元测试 MVC Controller 调用静态库调用外部 API

c# - 以用户身份运行时访问映射的驱动器

c# - Windows服务中Application.ExecutablePath的等价物是什么

c# - .NET : Output caching for WebMethod?

c# - 如何使用 EPPlus 将数据从 csv 导入 Excel?

alignment - EPPlus namedstyle horizo​​ntalAlignment

c# - Entity Framework 代码优先无法正常工作

c# - 拆分逗号以将多行插入数据库 (ASP.NET MVC)

.net - 对 ASP.NET 2.0 Web 服务进行版本控制的最佳方式是什么?

c# - 使用 EPPlus 将格式应用于 TotalsRow