SlideShare a Scribd company logo
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 3
thespotlesslives
 
Designing the application
Designing the applicationDesigning the application
Designing the applicationMilind Mishra
 
To excel or not?
To excel or not?To excel or not?
To excel or not?
Filippo Selden
 
Keyboard shortcuts in ms excel 5
Keyboard shortcuts in ms excel 5Keyboard shortcuts in ms excel 5
Keyboard shortcuts in ms excel 5
thespotlesslives
 
Spl book salution
Spl book salutionSpl book salution
Spl book salution
ahonaislamonti
 
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
Talesun Solar USA Ltd.
 
PlacecardTemplateInstructions
PlacecardTemplateInstructionsPlacecardTemplateInstructions
PlacecardTemplateInstructionsKim Howard
 
Autocad keyboard-shortcuts
Autocad keyboard-shortcutsAutocad keyboard-shortcuts
Autocad keyboard-shortcuts
caq1n
 

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 Silverlight
MICTT Palma
 
Html css
Html cssHtml css
Html css
John Felix
 
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
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
Sankhya_Analytics
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
Hemantha Kulathilake
 
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
BUBT
 
Cucci_-Excel_for_beginners_.pptx
Cucci_-Excel_for_beginners_.pptxCucci_-Excel_for_beginners_.pptx
Cucci_-Excel_for_beginners_.pptx
Hamid458506
 
Cucci_-Excel_for_beginners_ (1).pptx
Cucci_-Excel_for_beginners_ (1).pptxCucci_-Excel_for_beginners_ (1).pptx
Cucci_-Excel_for_beginners_ (1).pptx
kokila60
 
Excel Training.pptx
Excel Training.pptxExcel Training.pptx
Excel Training.pptx
ssuser5cc925
 
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.pdf
formaxekochi
 
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 API
Codingvila
 
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
Smart Chicago Collaborative
 
New features in C# 6
New features in C# 6New features in C# 6
New features in C# 6
Software Associates
 
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
elbanglis
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
Munazza-Mah-Jabeen
 
MS Excel new version 2013
MS Excel new version 2013MS Excel new version 2013
MS Excel new version 2013
AmirAshfaq
 
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
jewisonantone
 

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 rot
Chen Stephen
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web apps
Chen 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 8
Chen 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

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 

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 :