Skip to content

Commit 532ade5

Browse files
authored
Merge pull request #303 from SyncfusionExamples/994854-DecimalPlaceCount
documentation (994854): FAQ for How to count the number of decimal places in a numeric cell value in Excel?
2 parents ddb3f2e + 99cc2e6 commit 532ade5

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34310.174
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DecimalPlacesCount", "DecimalPlacesCount\DecimalPlacesCount.csproj", "{6A87150C-3AB9-4F73-943D-880A5091DBCD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6A87150C-3AB9-4F73-943D-880A5091DBCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6A87150C-3AB9-4F73-943D-880A5091DBCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6A87150C-3AB9-4F73-943D-880A5091DBCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6A87150C-3AB9-4F73-943D-880A5091DBCD}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5438F081-8D9A-4D05-8234-C220E1FE4339}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Edit_Pivot_Table</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\*">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
25+
26+
27+

FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Output/.gitkeep

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.IO;
2+
using Syncfusion.XlsIO;
3+
using Syncfusion.XlsIO.Implementation.PivotTables;
4+
5+
namespace DecimalPlacesCount
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
using (ExcelEngine excelEngine = new ExcelEngine())
12+
{
13+
IApplication application = excelEngine.Excel;
14+
application.DefaultVersion = ExcelVersion.Xlsx;
15+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
16+
IWorksheet worksheet = workbook.Worksheets[0];
17+
18+
// Get the cell text safely
19+
string cellText = worksheet.Range["G2"].Value?.ToString() ?? string.Empty;
20+
21+
// Count decimal places: if there's a decimal point, count chars after it; otherwise 0
22+
int countDecimalPlaces = 0;
23+
int dotIndex = cellText.IndexOf('.');
24+
if (dotIndex >= 0)
25+
{
26+
countDecimalPlaces = cellText.Length - dotIndex - 1;
27+
}
28+
29+
// Display result in console
30+
Console.WriteLine(countDecimalPlaces);
31+
32+
#region Save
33+
//Saving the workbook
34+
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
35+
#endregion
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)