From 001e43364481438707406da26098498572755a39 Mon Sep 17 00:00:00 2001 From: KarthikaSF4773 Date: Thu, 6 Nov 2025 13:32:21 +0530 Subject: [PATCH] 990137-ExcelToHtmlSample --- .../Range to JSON with Schema/Program.cs | 18 +++++------------- .../Range to JSON without Schema/Program.cs | 12 +++--------- .../Workbook to JSON with Schema/Program.cs | 12 +++--------- .../Workbook to JSON without Schema/Program.cs | 12 +++--------- .../Worksheet to JSON with Schema/Program.cs | 18 +++++------------- .../Program.cs | 12 +++--------- .../Excel to HTML/Excel to HTML/Program.cs | 6 +----- .../.NET/Excel to ODS/Excel to ODS/Program.cs | 6 +----- 8 files changed, 24 insertions(+), 72 deletions(-) diff --git a/Convert Excel to JSON/Range to JSON with Schema/.NET/Range to JSON with Schema/Range to JSON with Schema/Program.cs b/Convert Excel to JSON/Range to JSON with Schema/.NET/Range to JSON with Schema/Range to JSON with Schema/Program.cs index e73cbbca..932a8e93 100644 --- a/Convert Excel to JSON/Range to JSON with Schema/.NET/Range to JSON with Schema/Range to JSON with Schema/Program.cs +++ b/Convert Excel to JSON/Range to JSON with Schema/.NET/Range to JSON with Schema/Range to JSON with Schema/Program.cs @@ -12,28 +12,20 @@ static void Main(string[] args) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Custom range IRange range = worksheet.Range["A1:F100"]; #region save as JSON - //Saves the workbook to a JSON filestream, as schema by default - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAsJson(outputStream, range); + //Saves the workbook to JSON, as schema by default + workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema-default.json"), range); - //Saves the workbook to a JSON filestream as schema - FileStream stream1 = new FileStream("Output/Excel-Range-To-JSON-as-schema.json", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAsJson(stream1, range, true); + //Saves the workbook to JSON as schema + workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema.json"), range, true); #endregion - //Dispose streams - outputStream.Dispose(); - stream1.Dispose(); - inputStream.Dispose(); - #region Open JSON //Open default JSON diff --git a/Convert Excel to JSON/Range to JSON without Schema/.NET/Range to JSON without Schema/Range to JSON without Schema/Program.cs b/Convert Excel to JSON/Range to JSON without Schema/.NET/Range to JSON without Schema/Range to JSON without Schema/Program.cs index 484e3c04..beea187a 100644 --- a/Convert Excel to JSON/Range to JSON without Schema/.NET/Range to JSON without Schema/Range to JSON without Schema/Program.cs +++ b/Convert Excel to JSON/Range to JSON without Schema/.NET/Range to JSON without Schema/Range to JSON without Schema/Program.cs @@ -12,23 +12,17 @@ static void Main(string[] args) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; //Custom range IRange range = worksheet.Range["A1:F100"]; #region save as JSON - //Saves the workbook to a JSON filestream, as schema by default - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Range-To-JSON-filestream-without-schema.json"), FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAsJson(outputStream, range, false); + //Saves the workbook to JSON, as schema by default + workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-filestream-without-schema.json"), range, false); #endregion - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); - #region Open JSON //Open default JSON #endregion diff --git a/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/Workbook to JSON with Schema/Program.cs b/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/Workbook to JSON with Schema/Program.cs index 745ce599..3acdacf2 100644 --- a/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/Workbook to JSON with Schema/Program.cs +++ b/Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/Workbook to JSON with Schema/Program.cs @@ -12,17 +12,11 @@ static void Main(string[] args) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; - //Saves the workbook to a JSON filestream as schema - FileStream jsonWithSchema = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAsJson(jsonWithSchema, true); - - //Dispose streams - jsonWithSchema.Dispose(); - inputStream.Dispose(); + //Saves the workbook to JSON as schema + workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), true); } } } diff --git a/Convert Excel to JSON/Workbook to JSON without Schema/.NET/Workbook to JSON without Schema/Workbook to JSON without Schema/Program.cs b/Convert Excel to JSON/Workbook to JSON without Schema/.NET/Workbook to JSON without Schema/Workbook to JSON without Schema/Program.cs index 3d6417b1..ca29fe63 100644 --- a/Convert Excel to JSON/Workbook to JSON without Schema/.NET/Workbook to JSON without Schema/Workbook to JSON without Schema/Program.cs +++ b/Convert Excel to JSON/Workbook to JSON without Schema/.NET/Workbook to JSON without Schema/Workbook to JSON without Schema/Program.cs @@ -12,20 +12,14 @@ static void Main(string[] args) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region save as JSON - //Saves the workbook to a JSON file without schema - FileStream outputStream = new FileStream("Output/Workbook-To-JSON-without-schema.json", FileMode.Create); - workbook.SaveAsJson(outputStream,false); + //Saves the workbook to JSON file without schema + workbook.SaveAsJson(Path.GetFullPath(@"Output/Workbook-To-JSON-without-schema.json"),false); #endregion - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); - #region Open JSON //Open default JSON #endregion diff --git a/Convert Excel to JSON/Worksheet to JSON with Schema/.NET/Worksheet to JSON with Schema/Worksheet to JSON with Schema/Program.cs b/Convert Excel to JSON/Worksheet to JSON with Schema/.NET/Worksheet to JSON with Schema/Worksheet to JSON with Schema/Program.cs index 318ef158..3912fac2 100644 --- a/Convert Excel to JSON/Worksheet to JSON with Schema/.NET/Worksheet to JSON with Schema/Worksheet to JSON with Schema/Program.cs +++ b/Convert Excel to JSON/Worksheet to JSON with Schema/.NET/Worksheet to JSON with Schema/Worksheet to JSON with Schema/Program.cs @@ -12,25 +12,17 @@ static void Main(string[] args) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region save as JSON - //Saves the workbook to a JSON filestream, as schema by default - FileStream outputStream = new FileStream("Output/Excel-Worksheet-To-JSON-filestream-as-schema-default.json", FileMode.Create); - workbook.SaveAsJson(outputStream, worksheet); + //Saves the workbook to JSON, as schema by default + workbook.SaveAsJson(Path.GetFullPath(@"Output/Excel-Worksheet-To-JSON-filestream-as-schema-default.json"), worksheet); - //Saves the workbook to a JSON filestream as schema - FileStream stream1 = new FileStream("Output/Excel-Worksheet-To-JSON-filestream-as-schema.json", FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAsJson(stream1, worksheet, true); + //Saves the workbook to JSON as schema + workbook.SaveAsJson(Path.GetFullPath(@"Output/Excel-Worksheet-To-JSON-filestream-as-schema.json"), worksheet, true); #endregion - //Dispose streams - outputStream.Dispose(); - stream1.Dispose(); - inputStream.Dispose(); - #region Open JSON //Open default JSON diff --git a/Convert Excel to JSON/Worksheet to JSON without Schema/.NET/Worksheet to JSON without Schema/Worksheet to JSON without Schema/Program.cs b/Convert Excel to JSON/Worksheet to JSON without Schema/.NET/Worksheet to JSON without Schema/Worksheet to JSON without Schema/Program.cs index 4a031edc..0dc8b0ab 100644 --- a/Convert Excel to JSON/Worksheet to JSON without Schema/.NET/Worksheet to JSON without Schema/Worksheet to JSON without Schema/Program.cs +++ b/Convert Excel to JSON/Worksheet to JSON without Schema/.NET/Worksheet to JSON without Schema/Worksheet to JSON without Schema/Program.cs @@ -12,20 +12,14 @@ static void Main(string[] args) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; - FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); - IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; #region save as JSON - //Saves the workbook to a JSON filestream, as schema by default - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Worksheet-To-JSON-filestream-without-schema.json"), FileMode.Create, FileAccess.ReadWrite); - workbook.SaveAsJson(outputStream, worksheet,false); + //Saves the workbook to JSON, as schema by default + workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Worksheet-To-JSON-filestream-without-schema.json"), worksheet,false); #endregion - //Dispose streams - outputStream.Dispose(); - inputStream.Dispose(); - #region Open JSON //Open default JSON #endregion diff --git a/Excel to HTML/Excel to HTML/.NET/Excel to HTML/Excel to HTML/Program.cs b/Excel to HTML/Excel to HTML/.NET/Excel to HTML/Excel to HTML/Program.cs index f22064ed..2106887b 100644 --- a/Excel to HTML/Excel to HTML/.NET/Excel to HTML/Excel to HTML/Program.cs +++ b/Excel to HTML/Excel to HTML/.NET/Excel to HTML/Excel to HTML/Program.cs @@ -24,12 +24,8 @@ static void Main(string[] args) #region Save as HTML //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.html"), FileMode.Create, FileAccess.Write); - workbook.SaveAsHtml(outputStream, saveOptions); + workbook.SaveAsHtml(Path.GetFullPath("Output/Output.html"), saveOptions); #endregion - - //Dispose streams - outputStream.Dispose(); } } } diff --git a/Excel to ODS/Excel to ODS/.NET/Excel to ODS/Excel to ODS/Program.cs b/Excel to ODS/Excel to ODS/.NET/Excel to ODS/Excel to ODS/Program.cs index 819cab7e..b2210674 100644 --- a/Excel to ODS/Excel to ODS/.NET/Excel to ODS/Excel to ODS/Program.cs +++ b/Excel to ODS/Excel to ODS/.NET/Excel to ODS/Excel to ODS/Program.cs @@ -50,12 +50,8 @@ static void Main(string[] args) #region Save //Saving the workbook - FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExcelToODS.ods"), FileMode.Create, FileAccess.Write); - workbook.SaveAs(outputStream, ExcelSaveType.SaveAsODS); + workbook.SaveAs("Output.ods"); #endregion - - //Dispose streams - outputStream.Dispose(); } } }