Click here to Skip to main content
15,921,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I have added data to Excel Worksheet using worksheet.Cells[Row, Col] = Data;

worksheet is defined accordingly.
Now i need to give a specific format to this cell with Row number "Row" and column number "Col" . i tried using the get_range method and setting the color or font size, but its not working. is there any way i can do this.
Posted

Create a named range:

Microsoft.Office.Tools.Excel.NamedRange Range1 = this.Controls.AddNamedRange(this.Range["A1:B20"] "NamedRange1");


Set Font Color

range1.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);


Hope that helps
 
Share this answer
 
v2
Cell Font Color


C#
Excel.Range formatRange;
formatRange = xlWorkSheet.get_Range("b1", "b1");
formatRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);


Cell Background color

C#
Excel.Range formatRange;
formatRange = xlWorkSheet.get_Range("b1", "b1");
formatRange.Interior.Color = System.Drawing.
ColorTranslator.ToOle(System.Drawing.Color.Red);


More info...Excel Cell Formatting

Niva
 
Share this answer
 
There is a sample project on MSDN that presents how to set font style in Excel in C#. Hope this an option for you.

https://code.msdn.microsoft.com/Set-Excel-Font-Style-in-C-8b1e3d11[^]
 
Share this answer
 
v2

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