2016-10-12 14 views
0

私はこのシートをと呼んでおり、そのヘッダーを灰色にします。Excel細胞の着色

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 method.Nothingの作品を持っていません。私に何ができる?ドキュメントから

+0

「何もしない」とはどういう意味ですか?何がうまくいかない? – haindl

+0

スタイルをセルに個別に設定しようとしましたか?このようにws.Cells [0,0] .SetStyle(style); –

+0

@haindl私が上で試したコード行。色はまったく表示されません。 –

答えて

0

@Jess WSS、

スプレッドシートの1行目のセルシェーディングを適用するために次のコードを確認してください。あなたのコードには2つの問題があることに注意してください。

  1. セルシェーディングを適用する場合は、Style.Patternプロパティも設定する必要があります。
  2. また、関連するStyleFlagプロパティをオンにする必要があります。この場合、スタイルを適用する前に、StyleFlag.CellShadingをtrueにする必要があります。

    var style = ws.Cells.Rows[0].Style; 
    style.Font.IsBold = true; 
    style.ForegroundColor = System.Drawing.Color.LightGray; 
    style.Pattern = BackgroundType.Solid; 
    ws.Cells.Rows[0].ApplyStyle(style, new StyleFlag { FontBold = true, CellShading = true }); 
    

enter image description here

注:私は開発者エバンジェリストとしてのAsposeで動作します。