diff --git a/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand.sln b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand.sln new file mode 100644 index 00000000..df29a3bf --- /dev/null +++ b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand.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}") = "Parse Worksheets On Demand", "Parse Worksheets On Demand\Parse Worksheets On Demand.csproj", "{A53113E8-EBC9-4BAD-B29D-59FDA607B4C7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A53113E8-EBC9-4BAD-B29D-59FDA607B4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A53113E8-EBC9-4BAD-B29D-59FDA607B4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A53113E8-EBC9-4BAD-B29D-59FDA607B4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A53113E8-EBC9-4BAD-B29D-59FDA607B4C7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Data/Input.xlsx b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Data/Input.xlsx new file mode 100644 index 00000000..4b567ea3 Binary files /dev/null and b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Data/Input.xlsx differ diff --git a/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Output/.gitkeep b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Parse Worksheets On Demand.csproj b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Parse Worksheets On Demand.csproj new file mode 100644 index 00000000..263c7b5b --- /dev/null +++ b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Parse Worksheets On Demand.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Parse_Worksheets_On_Demand + enable + enable + + + + + + + + + Always + + + + diff --git a/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Program.cs b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Program.cs new file mode 100644 index 00000000..2d276d03 --- /dev/null +++ b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/Parse Worksheets On Demand/Program.cs @@ -0,0 +1,36 @@ +using System; +using System.IO; +using Syncfusion.XlsIO; + + + +namespace Parse_Worksheets_On_Demand +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic, ExcelParseOptions.ParseWorksheetsOnDemand); + + // Access the first worksheet (triggers parsing) + IWorksheet worksheet = workbook.Worksheets[0]; + + // Process your data + string value = worksheet.Range["A1"].Text; + + // Save to file system + FileStream stream = new FileStream("Output/Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.SaveAs(stream); + workbook.Close(); + excelEngine.Dispose(); + } + + } + + } +} \ No newline at end of file diff --git a/FAQ/Worksheet/.NET/Parse Worksheets On Demand/README.md b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/README.md new file mode 100644 index 00000000..dcde9901 --- /dev/null +++ b/FAQ/Worksheet/.NET/Parse Worksheets On Demand/README.md @@ -0,0 +1,35 @@ +# How to avoid processing unnecessary worksheets when opening an Excel document using C#? + +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 avoid processing unnecessary worksheets when opening an Excel document using C#? +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream("Input.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream,ExcelOpenType.Automatic, ExcelParseOptions.ParseWorksheetsOnDemand); + // Access the first worksheet (triggers parsing) + IWorksheet worksheet = workbook.Worksheets[0]; + // Process your data + string value = worksheet.Range["A1"].Text; + // Save to file system + FileStream stream = new FileStream("Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.SaveAs(stream); + workbook.Close(); + excelEngine.Dispose(); +} +``` +