Click here to Skip to main content
16,016,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello dear,

I am exporting data from DataGrid as

Workbook workbook = new Workbook();
                        
                        // create a worksheet object
                        Worksheet worksheet = new Worksheet("Enterprise_Summary_Reports");
                      
                        // for header
                        foreach (DataGridColumn dgcol in datagrid1.Columns)
                        {
                            worksheet.Cells[0, ColumnCount] = new Cell(dgcol.Header.ToString());
                            
                            CellStyle css = new CellStyle();
                            css.BackColor = (Color)Colors.Red;
                            worksheet.Cells[0, ColumnCount].Style = css;
                            ColumnCount++;
}
// statements for adding rows                         
  workbook.Worksheets.Add(worksheet);
  // get the selected file's stream
  Stream sFile = sDialog.OpenFile();
  workbook.Save(sFile);


By this my file get saved properly but the formatting which i assigned to header row i.e BackColor is Red not displayed in excel sheet.

Please suggest me proper way for this.

Thanks in advance
Posted
Comments
Herman<T>.Instance 4-Aug-11 4:16am    
for what excel version?
is '(Color)Colors.Red;' your own defenition of Red?
Member 8100743 4-Aug-11 4:17am    
No its inbuild in silverlight 4
Herman<T>.Instance 4-Aug-11 4:46am    
and what excel version? For excel 2003 only 15 or 256 colors can be set. If your red is different than the red Excel wants/needs then it displays no red.
Member 8100743 4-Aug-11 5:06am    
For excel 2003

Hi
Use this

Microsoft.Office.Interop.Excel.Range rngTableHeading = excel.get_Range("A2", "IV2");
rngTableHeading.Font.Name = "Calibri";
rngTableHeading.Font.Size = "12";
rngTableHeading.Font.Bold = true;
rngTableHeading.Interior.ColorIndex = 36;
rngTableHeading.Rows.AutoFit();

By
Shan.R
 
Share this answer
 
why don't you try ExcelPackage.dll :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900