【问题标题】:How to set color for header or first row in excel [duplicate]如何在excel中设置标题或第一行的颜色[重复]
【发布时间】:2013-07-15 19:25:44
【问题描述】:

我正在阅读 excel 表以及导出读取的 excel。我想将填充(背景颜色)颜色设置为导出的 excel 表的标题行。我正在使用 C# +asp.net。

【问题讨论】:

  • 你用什么导出到Excel?
  • 取决于您用于导出的代码,所以如果您显示您的代码会更好
  • if (dt.Rows.Count > 0) { 字符串文件名 = ExcelName; System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);数据网格 dgGrid = new DataGrid(); dgGrid.DataSource = dt; dgGrid.DataBind();
  • dgGrid.RenderControl(hw); Response.ContentType = "应用程序/vnd.ms-excel"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + ""); this.EnableViewState = false; Response.Write(tw.ToString()); Response.End();

标签: c#


【解决方案1】:

这样的事情可能会有所帮助。更改其他参数以获得所需的结果。

Microsoft.Office.Tools.Excel.Worksheet.Range["A1","B1"].Interior.Color = Excel.XlRgbColor.rgbDarkBlue;

“A”和“B”代表你的范围。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2010-11-06
    • 1970-01-01
    • 2016-09-30
    • 2010-10-10
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 2019-02-09
    相关资源
    最近更新 更多