Skip to content

Commit 01637b6

Browse files
authored
Merge pull request #170 from SyncfusionExamples/941162-ExcelSize
941162-FAQ for How to compute the size of the Excel file
2 parents a386662 + d6d09fa commit 01637b6

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excel size", "Excel size\Excel size.csproj", "{2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}"
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+
{2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2C781C8A-0C25-4840-A9B8-B0E97CDC83F7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Excel_size</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+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
5+
namespace ExcelSize
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.Create(1);
16+
IWorksheet worksheet = workbook.Worksheets[0];
17+
18+
worksheet.Range["A1"].Text = "Sample Data";
19+
20+
//Save to memory stream
21+
using (MemoryStream stream = new MemoryStream())
22+
{
23+
workbook.SaveAs(stream);
24+
25+
//Compute file size in bytes
26+
long sizeInBytes = stream.Length;
27+
Console.WriteLine($"File size: {sizeInBytes} bytes");
28+
29+
//Convert to KB
30+
double sizeInKB = sizeInBytes / 1024.0;
31+
Console.WriteLine($"File size: {sizeInKB:F2} KB");
32+
}
33+
}
34+
}
35+
36+
}
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# How to compute the size of the Excel file?
2+
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
6+
7+
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).
8+
9+
Step 4: Include the following namespaces in the **Program.cs** file.
10+
11+
```csharp
12+
using System;
13+
using System.IO;
14+
using Syncfusion.XlsIO;
15+
```
16+
17+
Step 5: Include the below code snippet in **Program.cs** to compute the size of the Excel file.
18+
19+
```csharp
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
IApplication application = excelEngine.Excel;
23+
application.DefaultVersion = ExcelVersion.Xlsx;
24+
IWorkbook workbook = application.Workbooks.Create(1);
25+
IWorksheet worksheet = workbook.Worksheets[0];
26+
27+
worksheet.Range["A1"].Text = "Sample Data";
28+
29+
//Save to memory stream
30+
using (MemoryStream stream = new MemoryStream())
31+
{
32+
workbook.SaveAs(stream);
33+
34+
//Compute file size in bytes
35+
long sizeInBytes = stream.Length;
36+
Console.WriteLine($"File size: {sizeInBytes} bytes");
37+
38+
//Convert to KB
39+
double sizeInKB = sizeInBytes / 1024.0;
40+
Console.WriteLine($"File size: {sizeInKB:F2} KB");
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)