SlideShare ist ein Scribd-Unternehmen logo
1 von 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 :

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Kürzlich hochgeladen (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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 :