2016-10-12 7 views
0

나는 엑셀에 이라는이 시트를 가지고 있으며 그 머리글이 회색이되고 싶습니다.엑셀 세포 색칠

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 행에 셀 음영을 적용하기 위해 다음 코드 조각을 확인하시기 바랍니다. 참고로 코드에는 두 가지 문제가 있습니다.

  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와 함께 작동합니다.