Skip to content

Commit c6ce3d2

Browse files
999551-PreserveLeadingZerosSample
1 parent dde189a commit c6ce3d2

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-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="PreserveLeadingZeros/PreserveLeadingZeros.csproj" />
3+
</Solution>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"Employee ID","Last Name","Mixed_N_String"
2+
1,"Davolio","00123"
3+
2,"Fuller","00123"
4+
3,"Leverling","00123"
5+
4,"Peacock","00123"
6+
5,"Buchanan","abcde"
7+
6,"Suyama","abcde"

CSV to Excel/Preserve Leading Zeros/.NET/PreserveLeadingZeros/PreserveLeadingZeros/Output/.gitkeep

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
23+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Syncfusion.XlsIO;
2+
3+
namespace PreserveLeadingZeros
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
using (ExcelEngine excelEngine = new ExcelEngine())
10+
{
11+
IApplication application = excelEngine.Excel;
12+
application.DefaultVersion = ExcelVersion.Xlsx;
13+
application.PreserveCSVDataTypes = true;
14+
15+
//Enable KeepLeadingZeros property
16+
application.KeepLeadingZeros = true;
17+
18+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.csv"), ",");
19+
20+
//Save the workbook
21+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)