【发布时间】:2016-10-12 13:21:35
【问题描述】:
我在 Excel 中有一张名为 Export 的表格,我希望它的标题为灰色。 代码如下:
protected void btnExcel_OnClick(object sender, EventArgs e)
{
var ex = new Aspose.Cells.Workbook();
ex.Worksheets.Clear();
Aspose.Cells.Worksheet ws = ex.Worksheets.Add("Export");
ws.Cells.ImportTable(Export.GetExportList(GetWhereClause(), ConfigurationManager.AppSettings();
ws.Cells[0, 0].PutValue("A");
ws.Cells[0, 1].PutValue("B");
ws.Cells[0, 2].PutValue("C");
ws.Cells[0, 3].PutValue("D");
ws.Cells[0, 4].PutValue("E");
var style = ws.Cells.Rows[0].Style;
style.Font.IsBold = true;
ws.Cells.Rows[0].ApplyStyle(style, new StyleFlag { FontBold = true });
ex.Save(string.Format("Export_{0}.xlsx", DateTime.Now.ToString("yyyyMMdd_HHmmss")), FileFormatType.Excel2007Xlsx, SaveType.OpenInExcel, Response);
}
我也包含了按钮代码。 我尝试过这样的事情:
style.BackgroundColor = Color.DarkGrey;
或
ws.Cells[0, 0].Style.BackgroundColor = Color.DarkGrey;
而且我没有.Interior 方法。没有任何效果。我能做什么?
【问题讨论】:
-
“没有任何效果”是什么意思?究竟是什么不起作用?
-
您是否尝试过为单元格单独设置样式?像这样 ws.Cells[0,0].SetStyle(style);
-
@haindl 我在上面尝试的代码行。颜色根本没有出现。
-
你试过stackoverflow.com/questions/17696458/…这里的方法了吗?
-
@Jacobr365,是的。没用。
标签: c# excel aspose aspose-cells