Skip to content

Commit d4d03cc

Browse files
authored
Merge pull request #282 from SyncfusionExamples/990897-NumberFormatColumnSample
990897-How to apply number formatting to an entire column using XlsIO
2 parents 251a803 + abcc65c commit d4d03cc

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="ColumnNumberFormat/ColumnNumberFormat.csproj" />
3+
</Solution>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Output\*">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Data\*">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
</Project>
Binary file not shown.

FAQ/Column Number Format/.NET/ColumnNumberFormat/ColumnNumberFormat/Output/.gitkeep

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Syncfusion.XlsIO;
2+
3+
namespace ColumnNumberFormat
4+
{
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
using (ExcelEngine excelEngine = new ExcelEngine())
10+
{
11+
IApplication application = excelEngine.Excel;
12+
application.DefaultVersion = ExcelVersion.Xlsx;
13+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
14+
IWorksheet sheet = workbook.Worksheets[0];
15+
16+
//Case 1: Apply direct number format (zero-based index)
17+
sheet.Columns[0].NumberFormat = "yyyy-mm-dd"; //Column A
18+
sheet.Columns[3].NumberFormat = "$#,##0.00"; //Column D
19+
sheet.Columns[4].NumberFormat = "0.00%"; //Column E
20+
21+
//Case 2: Apply style-based format (one-based index)
22+
IStyle style = workbook.Styles.Add("DecimalStyle");
23+
style.NumberFormat = "0.00";
24+
sheet.SetDefaultColumnStyle(3, style); //Column C
25+
26+
//Saving the workbook
27+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)