ExcelTechnology

Control Excel Font or Color of One Row by Using C#

Developers often use C# to operate Excel for realizing Excel automation. Generally speaking, there are several parts included in Excel automation, for example, Excel creation, data import and export and so on. In order to generate a complete Excel file, developers often have Excel formatted.
The frequently used formatting in Excel is font styles, which is one part of cell formatting. There are lots of font styles for Excel. When we open an Excel, we can find the Format in menu. After selecting Cell, kinds of formatting tools are displayed. Click the Font tab and we can select the wanted styles for the cells which are needed to be formatted.
Sometimes, we may make specified cells be obvious by using different color and size from other cells. The special cell may be the column title or the most important information. For example, if the data in one cell is the total quantity of one column, the data may be set as red or other bright colors. Although it is easy to set font style, according to users’ requirements, we may come across some difficult questions.
Recently, I found a problem about that how to control one row font or color when exporting Excel by using C#. After trying several methods, the following code may be helpful to solve this problem.
Firstly, we need to set the column format to complete to set Excel Font by using C#.
Excel.Range my range = mysheet.get_Range(mysheet.Cells[1,1], mysheet.Cells[5,1]);
Myrange.NumberFormatLocal = “@”;
The last line code means that the cell format type is text formatting.

Then, set the color of the tenth row as red.
mysheet.get_Range((Excel.Range)mysheet.Cells[10,1],(Excel.Range)mysheet.Cells[10,200]).Select();
mysheet.get_Range((Excel.Range)mysheet.Cells[10,1],(Excel.Range)mysheet.Cells[10,200]).Interior.ColorIndex=3;
mysheet.get_Range((Excel.Range)mysheet.Cells[10,1],(Excel.Range)mysheet.Cells[10,200]).Font.ColorIndex=3;
After running the code, we can find that all the characters in cells of the tenth row become red.

04.01.2011. u 09:00 | 0 Komentara | Print | # | ^

<< Arhiva >>

Creative Commons License
Ovaj blog je ustupljen pod Creative Commons licencom Imenovanje-Dijeli pod istim uvjetima.

< siječanj, 2011 >
P U S Č P S N
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Kolovoz 2011 (2)
Srpanj 2011 (2)
Lipanj 2011 (2)
Svibanj 2011 (2)
Travanj 2011 (3)
Ožujak 2011 (2)
Veljača 2011 (2)
Siječanj 2011 (5)
Prosinac 2010 (5)

Dnevnik.hr
Gol.hr
Zadovoljna.hr
Novaplus.hr
NovaTV.hr
DomaTV.hr
Mojamini.tv

Opis bloga

something about Excel Technology in VB.Net and C#

Linkovi

Dnevnik.hr
Video news portal Nove TV

Blog.hr
Blog servis

Igre.hr
Najbolje igre i igrice

Forum.hr
Monitor.hr