diff --git a/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount.sln b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount.sln new file mode 100644 index 00000000..1b3e2ea3 --- /dev/null +++ b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34310.174 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DecimalPlacesCount", "DecimalPlacesCount\DecimalPlacesCount.csproj", "{6A87150C-3AB9-4F73-943D-880A5091DBCD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6A87150C-3AB9-4F73-943D-880A5091DBCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A87150C-3AB9-4F73-943D-880A5091DBCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A87150C-3AB9-4F73-943D-880A5091DBCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A87150C-3AB9-4F73-943D-880A5091DBCD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5438F081-8D9A-4D05-8234-C220E1FE4339} + EndGlobalSection +EndGlobal diff --git a/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Data/InputTemplate.xlsx b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Data/InputTemplate.xlsx new file mode 100644 index 00000000..d810aa7e Binary files /dev/null and b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Data/InputTemplate.xlsx differ diff --git a/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/DecimalPlacesCount.csproj b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/DecimalPlacesCount.csproj new file mode 100644 index 00000000..410dc961 --- /dev/null +++ b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/DecimalPlacesCount.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + Edit_Pivot_Table + enable + enable + + + + + + + + + Always + + + Always + + + + + + + diff --git a/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Output/.gitkeep b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Program.cs b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Program.cs new file mode 100644 index 00000000..1f7441f8 --- /dev/null +++ b/FAQ/Decimal Places Count/.NET/DecimalPlacesCount/DecimalPlacesCount/Program.cs @@ -0,0 +1,39 @@ +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.XlsIO.Implementation.PivotTables; + +namespace DecimalPlacesCount +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); + IWorksheet worksheet = workbook.Worksheets[0]; + + // Get the cell text safely + string cellText = worksheet.Range["G2"].Value?.ToString() ?? string.Empty; + + // Count decimal places: if there's a decimal point, count chars after it; otherwise 0 + int countDecimalPlaces = 0; + int dotIndex = cellText.IndexOf('.'); + if (dotIndex >= 0) + { + countDecimalPlaces = cellText.Length - dotIndex - 1; + } + + // Display result in console + Console.WriteLine(countDecimalPlaces); + + #region Save + //Saving the workbook + workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx")); + #endregion + } + } + } +} \ No newline at end of file