SlideShare a Scribd company logo
1 of 4
C# Excel Number Style

In Excel, right-click a cell or group of cells and choosing Format Cell, a window with number
formatting options will pop up for you to choose. Number formatting is the ability to control how
a number is displayed by taking advantage of the culture-specific thousand and decimal
separators, the amount of decimals as well as a currency symbol. Number format can also be used
to format dates, percentages, and even custom formats. Through C#, programmers also can set
number styles in Excel, and even without Microsoft Excel installed on system.

How to Use C# Set Excel Number Style

Spire.XLS for .NET is .NET Excel component which enables your .NET applications fast
generate, read, write and modify Excel document without Microsoft Office Excel Automation.
With Spire.XLS, programmers can use C# set Excel number style easily.

Download Spire.XLS for .NET (or Spire.Office) with .NET Framework 2.0 (or above) together
and use the code below to set Excel number Style:

C# Excel Number Style:

01   private void ExcelDocViewer( string fileName )
02   {
03      try
04      {
05         System.Diagnostics.Process.Start(fileName);
06      }
07      catch{}
08   }
09
10   private void btnRun_Click(object sender, System.EventArgs e)
11   {
12      Workbook workbook = new Workbook();
13      Worksheet sheet = workbook.Worksheets[0];
14
15     sheet.Range["B1"].Text = "NUMBER FORMATTING";
16     sheet.Range["B1"].Style.Font.IsBold = true;
17
18     sheet.Range["B3"].Text = "0";
19     sheet.Range["C3"].NumberValue = 1234.5678;
20     sheet.Range["C3"].NumberFormat = "0";
21
22     sheet.Range["B4"].Text = "0.00";
23     sheet.Range["C4"].NumberValue = 1234.5678;
24     sheet.Range["C4"].NumberFormat = "0.00";
25
26     sheet.Range["B5"].Text = "#,##0.00";
27     sheet.Range["C5"].NumberValue = 1234.5678;
28     sheet.Range["C5"].NumberFormat = "#,##0.00";
29
30     sheet.Range["B6"].Text = "$#,##0.00";
31     sheet.Range["C6"].NumberValue = 1234.5678;
32     sheet.Range["C6"].NumberFormat = "$#,##0.00";
33
34     sheet.Range["B7"].Text = "0;[Red]-0";
35     sheet.Range["C7"].NumberValue = -1234.5678;
36     sheet.Range["C7"].NumberFormat = "0;[Red]-0";
37
38     sheet.Range["B8"].Text = "0.00;[Red]-0.00";
39     sheet.Range["C8"].NumberValue = -1234.5678;
40     sheet.Range["C8"].NumberFormat = "0.00;[Red]-0.00";
41
42     sheet.Range["B9"].Text = "#,##0;[Red]-#,##0";
43     sheet.Range["C9"].NumberValue = -1234.5678;
44     sheet.Range["C9"].NumberFormat = "#,##0;[Red]-#,##0";
45
46     sheet.Range["B10"].Text = "#,##0.00;[Red]-#,##0.000";
47     sheet.Range["C10"].NumberValue = -1234.5678;
48     sheet.Range["C10"].NumberFormat = "#,##0.00;[Red]-#,##0.00";
49
50     sheet.Range["B11"].Text = "0.00E+00";
51     sheet.Range["C11"].NumberValue = 1234.5678;
52     sheet.Range["C11"].NumberFormat = "0.00E+00";
53
54     sheet.Range["B12"].Text = "0.00%";
55     sheet.Range["C12"].NumberValue = 1234.5678;
56     sheet.Range["C12"].NumberFormat = "0.00%";
57
58     sheet.Range["B3:B12"].Style.KnownColor = ExcelColors.Gray25Percent;
59
60
61     sheet.AutoFitColumn(2);
62     sheet.AutoFitColumn(3);
63
64
65     workbook.SaveToFile("Sample.xls");
66     ExcelDocViewer(workbook.FileName);
67 }
After running the code above in your application, you will get different number style as the image
below:




More about Spire.XSL
Download Spire.XSL
Purchase Spire.XLS

A short listing of the great formatting capabilities is provided below, but let's not regard it as a
replacement for the online reference Excel help on that matter.

    To escape text, enclose it in quotes, like in $0.00" Surplus";$-0.00" Shortage"
    To add a space character, include an _ (underscore).
    Use # for insignificant digits. Using ####.#, 1234.59 displays as 1234.6
    Use 0 for significant digits (or for padding). Using #.0#, 12 displays as 12.0
    Use ? for alignment
    Use , as thousand separator
    Use . as decimal separator
    Use ; to separate the formatting when the number is positive, and the formatting when the
     number is not
    Use [Red] to add color to a cell, as in [Red]###,###.00. Among known colors are [Red],
     [Black], [Cyan], [Green], [Magenta], [Blue], [White] and [Yellow], as well as colors from the
     56 predefined palette of the form [Color___] where ___ is a number between 1 and 56.
    Use closed brackets to enclose conditions, or use the conditional formatting object. Example
     using closed brackets : [Red][<=100];[Blue][>100]
    Use % to display a number as a percentage. Please note that Excel will automatically perform
     a 100 time multiplication.
   Use the typical date symbols to format dates. Symbols can be combined as below :

More Related Content

What's hot

Keyboard shortcuts in ms excel 3
Keyboard shortcuts in ms excel 3Keyboard shortcuts in ms excel 3
Keyboard shortcuts in ms excel 3thespotlesslives
 
Designing the application
Designing the applicationDesigning the application
Designing the applicationMilind Mishra
 
Keyboard shortcuts in ms excel 5
Keyboard shortcuts in ms excel 5Keyboard shortcuts in ms excel 5
Keyboard shortcuts in ms excel 5thespotlesslives
 
PlacecardTemplateInstructions
PlacecardTemplateInstructionsPlacecardTemplateInstructions
PlacecardTemplateInstructionsKim Howard
 
Autocad keyboard-shortcuts
Autocad keyboard-shortcutsAutocad keyboard-shortcuts
Autocad keyboard-shortcutscaq1n
 

What's hot (9)

Keyboard shortcuts in ms excel 3
Keyboard shortcuts in ms excel 3Keyboard shortcuts in ms excel 3
Keyboard shortcuts in ms excel 3
 
Designing the application
Designing the applicationDesigning the application
Designing the application
 
To excel or not?
To excel or not?To excel or not?
To excel or not?
 
Keyboard shortcuts in ms excel 5
Keyboard shortcuts in ms excel 5Keyboard shortcuts in ms excel 5
Keyboard shortcuts in ms excel 5
 
Cad
CadCad
Cad
 
Spl book salution
Spl book salutionSpl book salution
Spl book salution
 
How to delect data with the help of
How to delect data with the help ofHow to delect data with the help of
How to delect data with the help of
 
PlacecardTemplateInstructions
PlacecardTemplateInstructionsPlacecardTemplateInstructions
PlacecardTemplateInstructions
 
Autocad keyboard-shortcuts
Autocad keyboard-shortcutsAutocad keyboard-shortcuts
Autocad keyboard-shortcuts
 

Similar to C# excel set excel number style

C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chartChen Stephen
 
WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightMICTT Palma
 
Build .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and DashboardBuild .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and DashboardIron Speed
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
 
Cucci_-Excel_for_beginners_.pptx
Cucci_-Excel_for_beginners_.pptxCucci_-Excel_for_beginners_.pptx
Cucci_-Excel_for_beginners_.pptxHamid458506
 
Cucci_-Excel_for_beginners_ (1).pptx
Cucci_-Excel_for_beginners_ (1).pptxCucci_-Excel_for_beginners_ (1).pptx
Cucci_-Excel_for_beginners_ (1).pptxkokila60
 
Excel Training.pptx
Excel Training.pptxExcel Training.pptx
Excel Training.pptxssuser5cc925
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence PortfolioChris Seebacher
 
on SQL Managment studio(For the following exercise, use the Week 5.pdf
on SQL Managment studio(For the following exercise, use the Week 5.pdfon SQL Managment studio(For the following exercise, use the Week 5.pdf
on SQL Managment studio(For the following exercise, use the Week 5.pdfformaxekochi
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...AntareepMajumder
 
Angular 12 CRUD Example with Web API
Angular 12 CRUD Example with Web APIAngular 12 CRUD Example with Web API
Angular 12 CRUD Example with Web APICodingvila
 
Libre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsLibre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsSmart Chicago Collaborative
 
Excel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docxExcel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docxelbanglis
 
MS Excel new version 2013
MS Excel new version 2013MS Excel new version 2013
MS Excel new version 2013AmirAshfaq
 
I.Multiple Choice 20 Questions worth 1 point each..docx
I.Multiple Choice 20 Questions worth 1 point each..docxI.Multiple Choice 20 Questions worth 1 point each..docx
I.Multiple Choice 20 Questions worth 1 point each..docxjewisonantone
 

Similar to C# excel set excel number style (20)

C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chart
 
WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con Silverlight
 
Html css
Html cssHtml css
Html css
 
Build .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and DashboardBuild .NET Applications with Reporting and Dashboard
Build .NET Applications with Reporting and Dashboard
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in C
 
Cucci_-Excel_for_beginners_.pptx
Cucci_-Excel_for_beginners_.pptxCucci_-Excel_for_beginners_.pptx
Cucci_-Excel_for_beginners_.pptx
 
Cucci_-Excel_for_beginners_ (1).pptx
Cucci_-Excel_for_beginners_ (1).pptxCucci_-Excel_for_beginners_ (1).pptx
Cucci_-Excel_for_beginners_ (1).pptx
 
Excel Training.pptx
Excel Training.pptxExcel Training.pptx
Excel Training.pptx
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
on SQL Managment studio(For the following exercise, use the Week 5.pdf
on SQL Managment studio(For the following exercise, use the Week 5.pdfon SQL Managment studio(For the following exercise, use the Week 5.pdf
on SQL Managment studio(For the following exercise, use the Week 5.pdf
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
Angular 12 CRUD Example with Web API
Angular 12 CRUD Example with Web APIAngular 12 CRUD Example with Web API
Angular 12 CRUD Example with Web API
 
Libre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsLibre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding Functions
 
New features in C# 6
New features in C# 6New features in C# 6
New features in C# 6
 
Excel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docxExcel Project 2 – MS Excel Summer 2018 Use the project.docx
Excel Project 2 – MS Excel Summer 2018 Use the project.docx
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
MS Excel new version 2013
MS Excel new version 2013MS Excel new version 2013
MS Excel new version 2013
 
I.Multiple Choice 20 Questions worth 1 point each..docx
I.Multiple Choice 20 Questions worth 1 point each..docxI.Multiple Choice 20 Questions worth 1 point each..docx
I.Multiple Choice 20 Questions worth 1 point each..docx
 

More from Chen Stephen

Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersUpcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersChen Stephen
 
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenTop 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenChen Stephen
 
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenTop 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenChen Stephen
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2Chen Stephen
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2Chen Stephen
 
How to prevent code rot
How to prevent code rotHow to prevent code rot
How to prevent code rotChen Stephen
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web appsChen Stephen
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8Chen Stephen
 
C# insert comments in word
C# insert comments in wordC# insert comments in word
C# insert comments in wordChen Stephen
 

More from Chen Stephen (10)

Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersUpcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
 
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenTop 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
 
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenTop 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2
 
How to prevent code rot
How to prevent code rotHow to prevent code rot
How to prevent code rot
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web apps
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8
 
C# insert comments in word
C# insert comments in wordC# insert comments in word
C# insert comments in word
 
Listview to dif
Listview to difListview to dif
Listview to dif
 

Recently uploaded

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Recently uploaded (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

C# excel set excel number style

  • 1. C# Excel Number Style In Excel, right-click a cell or group of cells and choosing Format Cell, a window with number formatting options will pop up for you to choose. Number formatting is the ability to control how a number is displayed by taking advantage of the culture-specific thousand and decimal separators, the amount of decimals as well as a currency symbol. Number format can also be used to format dates, percentages, and even custom formats. Through C#, programmers also can set number styles in Excel, and even without Microsoft Excel installed on system. How to Use C# Set Excel Number Style Spire.XLS for .NET is .NET Excel component which enables your .NET applications fast generate, read, write and modify Excel document without Microsoft Office Excel Automation. With Spire.XLS, programmers can use C# set Excel number style easily. Download Spire.XLS for .NET (or Spire.Office) with .NET Framework 2.0 (or above) together and use the code below to set Excel number Style: C# Excel Number Style: 01 private void ExcelDocViewer( string fileName ) 02 { 03 try 04 { 05 System.Diagnostics.Process.Start(fileName); 06 } 07 catch{} 08 } 09 10 private void btnRun_Click(object sender, System.EventArgs e) 11 { 12 Workbook workbook = new Workbook(); 13 Worksheet sheet = workbook.Worksheets[0]; 14 15 sheet.Range["B1"].Text = "NUMBER FORMATTING"; 16 sheet.Range["B1"].Style.Font.IsBold = true; 17 18 sheet.Range["B3"].Text = "0"; 19 sheet.Range["C3"].NumberValue = 1234.5678; 20 sheet.Range["C3"].NumberFormat = "0"; 21 22 sheet.Range["B4"].Text = "0.00"; 23 sheet.Range["C4"].NumberValue = 1234.5678; 24 sheet.Range["C4"].NumberFormat = "0.00";
  • 2. 25 26 sheet.Range["B5"].Text = "#,##0.00"; 27 sheet.Range["C5"].NumberValue = 1234.5678; 28 sheet.Range["C5"].NumberFormat = "#,##0.00"; 29 30 sheet.Range["B6"].Text = "$#,##0.00"; 31 sheet.Range["C6"].NumberValue = 1234.5678; 32 sheet.Range["C6"].NumberFormat = "$#,##0.00"; 33 34 sheet.Range["B7"].Text = "0;[Red]-0"; 35 sheet.Range["C7"].NumberValue = -1234.5678; 36 sheet.Range["C7"].NumberFormat = "0;[Red]-0"; 37 38 sheet.Range["B8"].Text = "0.00;[Red]-0.00"; 39 sheet.Range["C8"].NumberValue = -1234.5678; 40 sheet.Range["C8"].NumberFormat = "0.00;[Red]-0.00"; 41 42 sheet.Range["B9"].Text = "#,##0;[Red]-#,##0"; 43 sheet.Range["C9"].NumberValue = -1234.5678; 44 sheet.Range["C9"].NumberFormat = "#,##0;[Red]-#,##0"; 45 46 sheet.Range["B10"].Text = "#,##0.00;[Red]-#,##0.000"; 47 sheet.Range["C10"].NumberValue = -1234.5678; 48 sheet.Range["C10"].NumberFormat = "#,##0.00;[Red]-#,##0.00"; 49 50 sheet.Range["B11"].Text = "0.00E+00"; 51 sheet.Range["C11"].NumberValue = 1234.5678; 52 sheet.Range["C11"].NumberFormat = "0.00E+00"; 53 54 sheet.Range["B12"].Text = "0.00%"; 55 sheet.Range["C12"].NumberValue = 1234.5678; 56 sheet.Range["C12"].NumberFormat = "0.00%"; 57 58 sheet.Range["B3:B12"].Style.KnownColor = ExcelColors.Gray25Percent; 59 60 61 sheet.AutoFitColumn(2); 62 sheet.AutoFitColumn(3); 63 64 65 workbook.SaveToFile("Sample.xls"); 66 ExcelDocViewer(workbook.FileName); 67 }
  • 3. After running the code above in your application, you will get different number style as the image below: More about Spire.XSL Download Spire.XSL Purchase Spire.XLS A short listing of the great formatting capabilities is provided below, but let's not regard it as a replacement for the online reference Excel help on that matter.  To escape text, enclose it in quotes, like in $0.00" Surplus";$-0.00" Shortage"  To add a space character, include an _ (underscore).  Use # for insignificant digits. Using ####.#, 1234.59 displays as 1234.6  Use 0 for significant digits (or for padding). Using #.0#, 12 displays as 12.0  Use ? for alignment  Use , as thousand separator  Use . as decimal separator  Use ; to separate the formatting when the number is positive, and the formatting when the number is not  Use [Red] to add color to a cell, as in [Red]###,###.00. Among known colors are [Red], [Black], [Cyan], [Green], [Magenta], [Blue], [White] and [Yellow], as well as colors from the 56 predefined palette of the form [Color___] where ___ is a number between 1 and 56.  Use closed brackets to enclose conditions, or use the conditional formatting object. Example using closed brackets : [Red][<=100];[Blue][>100]  Use % to display a number as a percentage. Please note that Excel will automatically perform a 100 time multiplication.
  • 4. Use the typical date symbols to format dates. Symbols can be combined as below :