diff --git a/FAQ/Excel size/.NET/Excel size/Excel size.sln b/FAQ/Excel size/.NET/Excel size/Excel size.sln new file mode 100644 index 00000000..c2b7fea1 --- /dev/null +++ b/FAQ/Excel size/.NET/Excel size/Excel size.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35506.116 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excel size", "Excel size\Excel size.csproj", "{2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FAQ/Excel size/.NET/Excel size/Excel size/Excel size.csproj b/FAQ/Excel size/.NET/Excel size/Excel size/Excel size.csproj new file mode 100644 index 00000000..098c5c21 --- /dev/null +++ b/FAQ/Excel size/.NET/Excel size/Excel size/Excel size.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Excel_size + enable + enable + + + + + + + diff --git a/FAQ/Excel size/.NET/Excel size/Excel size/Program.cs b/FAQ/Excel size/.NET/Excel size/Excel size/Program.cs new file mode 100644 index 00000000..fdc77a94 --- /dev/null +++ b/FAQ/Excel size/.NET/Excel size/Excel size/Program.cs @@ -0,0 +1,37 @@ +using System; +using System.IO; +using Syncfusion.XlsIO; + +namespace ExcelSize +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + worksheet.Range["A1"].Text = "Sample Data"; + + //Save to memory stream + using (MemoryStream stream = new MemoryStream()) + { + workbook.SaveAs(stream); + + //Compute file size in bytes + long sizeInBytes = stream.Length; + Console.WriteLine($"File size: {sizeInBytes} bytes"); + + //Convert to KB + double sizeInKB = sizeInBytes / 1024.0; + Console.WriteLine($"File size: {sizeInKB:F2} KB"); + } + } + } + + } +} \ No newline at end of file diff --git a/FAQ/Excel size/.NET/Excel size/README.md b/FAQ/Excel size/.NET/Excel size/README.md new file mode 100644 index 00000000..825ed9fd --- /dev/null +++ b/FAQ/Excel size/.NET/Excel size/README.md @@ -0,0 +1,43 @@ +# How to compute the size of the Excel file? + +Step 1: Create a New C# Console Application Project. + +Step 2: Name the Project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. + +```csharp +using System; +using System.IO; +using Syncfusion.XlsIO; +``` + +Step 5: Include the below code snippet in **Program.cs** to compute the size of the Excel file. + +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + worksheet.Range["A1"].Text = "Sample Data"; + + //Save to memory stream + using (MemoryStream stream = new MemoryStream()) + { + workbook.SaveAs(stream); + + //Compute file size in bytes + long sizeInBytes = stream.Length; + Console.WriteLine($"File size: {sizeInBytes} bytes"); + + //Convert to KB + double sizeInKB = sizeInBytes / 1024.0; + Console.WriteLine($"File size: {sizeInKB:F2} KB"); + } +} +``` \ No newline at end of file