Skip to content

Commit 874bf5f

Browse files
990137-ExcelToHtmlUG
1 parent cd20e8e commit 874bf5f

File tree

4 files changed

+50
-142
lines changed

4 files changed

+50
-142
lines changed

Document-Processing/Excel/Conversions/Excel-to-JSON/NET/Excel-to-JSON-Conversion.md

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,17 @@ using (ExcelEngine excelEngine = new ExcelEngine())
2929
{
3030
IApplication application = excelEngine.Excel;
3131
application.DefaultVersion = ExcelVersion.Xlsx;
32-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
33-
IWorkbook workbook = application.Workbooks.Open(inputStream);
32+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
3433
IWorksheet worksheet = workbook.Worksheets[0];
3534

3635
#region save as JSON
37-
//Saves the workbook to a JSON filestream, as schema by default
38-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite);
39-
workbook.SaveAsJson(outputStream);
36+
//Saves the workbook to JSON, as schema by default
37+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema-default.json"));
4038

41-
//Saves the workbook to a JSON filestream as schema
42-
FileStream stream1 = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite);
43-
workbook.SaveAsJson(stream1, true);
39+
//Saves the workbook to JSON as schema
40+
workbook.SaveAsJson("Output/Excel-Workbook-To-JSON-as-schema.json", true);
4441
#endregion
4542

46-
//Dispose streams
47-
outputStream.Dispose();
48-
stream1.Dispose();
49-
inputStream.Dispose();
50-
5143
#region Open JSON
5244
//Open default JSON
5345

@@ -181,20 +173,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
181173
{
182174
IApplication application = excelEngine.Excel;
183175
application.DefaultVersion = ExcelVersion.Xlsx;
184-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
185-
IWorkbook workbook = application.Workbooks.Open(inputStream);
176+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
186177
IWorksheet worksheet = workbook.Worksheets[0];
187178

188179
#region save as JSON
189-
//Saves the workbook to a JSON file without schema
190-
FileStream outputStream = new FileStream("Output/Workbook-To-JSON-without-schema.json", FileMode.Create);
191-
workbook.SaveAsJson(outputStream,false);
180+
//Saves the workbook to JSON file without schema
181+
workbook.SaveAsJson(Path.GetFullPath(@"Output/Workbook-To-JSON-without-schema.json"),false);
192182
#endregion
193183

194-
//Dispose streams
195-
outputStream.Dispose();
196-
inputStream.Dispose();
197-
198184
#region Open JSON
199185
//Open default JSON
200186
#endregion
@@ -311,25 +297,17 @@ using (ExcelEngine excelEngine = new ExcelEngine())
311297
{
312298
IApplication application = excelEngine.Excel;
313299
application.DefaultVersion = ExcelVersion.Xlsx;
314-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
315-
IWorkbook workbook = application.Workbooks.Open(inputStream);
300+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
316301
IWorksheet worksheet = workbook.Worksheets[0];
317302

318303
#region save as JSON
319-
//Saves the workbook to a JSON filestream, as schema by default
320-
FileStream outputStream = new FileStream("Output/Excel-Worksheet-To-JSON-filestream-as-schema-default.json", FileMode.Create);
321-
workbook.SaveAsJson(outputStream, worksheet);
304+
//Saves the workbook to JSON, as schema by default
305+
workbook.SaveAsJson(Path.GetFullPath(@"Output/Excel-Worksheet-To-JSON-filestream-as-schema-default.json"), worksheet);
322306

323-
//Saves the workbook to a JSON filestream as schema
324-
FileStream stream1 = new FileStream("Output/Excel-Worksheet-To-JSON-filestream-as-schema.json", FileMode.Create, FileAccess.ReadWrite);
325-
workbook.SaveAsJson(stream1, worksheet, true);
307+
//Saves the workbook to JSON as schema
308+
workbook.SaveAsJson(Path.GetFullPath(@"Output/Excel-Worksheet-To-JSON-filestream-as-schema.json"), worksheet, true);
326309
#endregion
327310

328-
//Dispose streams
329-
outputStream.Dispose();
330-
stream1.Dispose();
331-
inputStream.Dispose();
332-
333311
#region Open JSON
334312
//Open default JSON
335313

@@ -466,20 +444,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
466444
{
467445
IApplication application = excelEngine.Excel;
468446
application.DefaultVersion = ExcelVersion.Xlsx;
469-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
470-
IWorkbook workbook = application.Workbooks.Open(inputStream);
447+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
471448
IWorksheet worksheet = workbook.Worksheets[0];
472449

473450
#region save as JSON
474-
//Saves the workbook to a JSON filestream, as schema by default
475-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Worksheet-To-JSON-filestream-without-schema.json"), FileMode.Create, FileAccess.ReadWrite);
476-
workbook.SaveAsJson(outputStream, worksheet,false);
451+
//Saves the workbook to JSON, as schema by default
452+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Worksheet-To-JSON-filestream-without-schema.json"), worksheet,false);
477453
#endregion
478454

479-
//Dispose streams
480-
outputStream.Dispose();
481-
inputStream.Dispose();
482-
483455
#region Open JSON
484456
//Open default JSON
485457
#endregion
@@ -602,28 +574,20 @@ using (ExcelEngine excelEngine = new ExcelEngine())
602574
{
603575
IApplication application = excelEngine.Excel;
604576
application.DefaultVersion = ExcelVersion.Xlsx;
605-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
606-
IWorkbook workbook = application.Workbooks.Open(inputStream);
577+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
607578
IWorksheet worksheet = workbook.Worksheets[0];
608579

609580
//Custom range
610581
IRange range = worksheet.Range["A1:F100"];
611582

612583
#region save as JSON
613-
//Saves the workbook to a JSON filestream, as schema by default
614-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite);
615-
workbook.SaveAsJson(outputStream, range);
584+
//Saves the workbook to JSON, as schema by default
585+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema-default.json"), range);
616586

617-
//Saves the workbook to a JSON filestream as schema
618-
FileStream stream1 = new FileStream("Output/Excel-Range-To-JSON-as-schema.json", FileMode.Create, FileAccess.ReadWrite);
619-
workbook.SaveAsJson(stream1, range, true);
587+
//Saves the workbook to JSON as schema
588+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema.json"), range, true);
620589
#endregion
621590

622-
//Dispose streams
623-
outputStream.Dispose();
624-
stream1.Dispose();
625-
inputStream.Dispose();
626-
627591
#region Open JSON
628592
//Open default JSON
629593

@@ -769,23 +733,17 @@ using (ExcelEngine excelEngine = new ExcelEngine())
769733
{
770734
IApplication application = excelEngine.Excel;
771735
application.DefaultVersion = ExcelVersion.Xlsx;
772-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
773-
IWorkbook workbook = application.Workbooks.Open(inputStream);
736+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
774737
IWorksheet worksheet = workbook.Worksheets[0];
775738

776739
//Custom range
777740
IRange range = worksheet.Range["A1:F100"];
778741

779742
#region save as JSON
780-
//Saves the workbook to a JSON filestream, as schema by default
781-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Range-To-JSON-filestream-without-schema.json"), FileMode.Create, FileAccess.ReadWrite);
782-
workbook.SaveAsJson(outputStream, range, false);
743+
//Saves the workbook to JSON, as schema by default
744+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-filestream-without-schema.json"), range, false);
783745
#endregion
784746

785-
//Dispose streams
786-
outputStream.Dispose();
787-
inputStream.Dispose();
788-
789747
#region Open JSON
790748
//Open default JSON
791749
#endregion

Document-Processing/Excel/Conversions/Excel-to-JSON/overview.md

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,17 @@ using (ExcelEngine excelEngine = new ExcelEngine())
2929
{
3030
IApplication application = excelEngine.Excel;
3131
application.DefaultVersion = ExcelVersion.Xlsx;
32-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
33-
IWorkbook workbook = application.Workbooks.Open(inputStream);
32+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
3433
IWorksheet worksheet = workbook.Worksheets[0];
3534

3635
#region save as JSON
37-
//Saves the workbook to a JSON filestream, as schema by default
38-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite);
39-
workbook.SaveAsJson(outputStream);
36+
//Saves the workbook to JSON, as schema by default
37+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema-default.json"));
4038

41-
//Saves the workbook to a JSON filestream as schema
42-
FileStream stream1 = new FileStream("Output/Excel-Workbook-To-JSON-as-schema.json", FileMode.Create, FileAccess.ReadWrite);
43-
workbook.SaveAsJson(stream1, true);
39+
//Saves the workbook to JSON as schema
40+
workbook.SaveAsJson("Output/Excel-Workbook-To-JSON-as-schema.json", true);
4441
#endregion
4542

46-
//Dispose streams
47-
outputStream.Dispose();
48-
stream1.Dispose();
49-
inputStream.Dispose();
50-
5143
#region Open JSON
5244
//Open default JSON
5345

@@ -181,20 +173,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
181173
{
182174
IApplication application = excelEngine.Excel;
183175
application.DefaultVersion = ExcelVersion.Xlsx;
184-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
185-
IWorkbook workbook = application.Workbooks.Open(inputStream);
176+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
186177
IWorksheet worksheet = workbook.Worksheets[0];
187178

188179
#region save as JSON
189-
//Saves the workbook to a JSON file without schema
190-
FileStream outputStream = new FileStream("Output/Workbook-To-JSON-without-schema.json", FileMode.Create);
191-
workbook.SaveAsJson(outputStream,false);
180+
//Saves the workbook to JSON file without schema
181+
workbook.SaveAsJson(Path.GetFullPath(@"Output/Workbook-To-JSON-without-schema.json"),false);
192182
#endregion
193183

194-
//Dispose streams
195-
outputStream.Dispose();
196-
inputStream.Dispose();
197-
198184
#region Open JSON
199185
//Open default JSON
200186
#endregion
@@ -311,25 +297,17 @@ using (ExcelEngine excelEngine = new ExcelEngine())
311297
{
312298
IApplication application = excelEngine.Excel;
313299
application.DefaultVersion = ExcelVersion.Xlsx;
314-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
315-
IWorkbook workbook = application.Workbooks.Open(inputStream);
300+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
316301
IWorksheet worksheet = workbook.Worksheets[0];
317302

318303
#region save as JSON
319-
//Saves the workbook to a JSON filestream, as schema by default
320-
FileStream outputStream = new FileStream("Output/Excel-Worksheet-To-JSON-filestream-as-schema-default.json", FileMode.Create);
321-
workbook.SaveAsJson(outputStream, worksheet);
304+
//Saves the workbook to JSON, as schema by default
305+
workbook.SaveAsJson(Path.GetFullPath(@"Output/Excel-Worksheet-To-JSON-filestream-as-schema-default.json"), worksheet);
322306

323-
//Saves the workbook to a JSON filestream as schema
324-
FileStream stream1 = new FileStream("Output/Excel-Worksheet-To-JSON-filestream-as-schema.json", FileMode.Create, FileAccess.ReadWrite);
325-
workbook.SaveAsJson(stream1, worksheet, true);
307+
//Saves the workbook to JSON as schema
308+
workbook.SaveAsJson(Path.GetFullPath(@"Output/Excel-Worksheet-To-JSON-filestream-as-schema.json"), worksheet, true);
326309
#endregion
327310

328-
//Dispose streams
329-
outputStream.Dispose();
330-
stream1.Dispose();
331-
inputStream.Dispose();
332-
333311
#region Open JSON
334312
//Open default JSON
335313

@@ -466,20 +444,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
466444
{
467445
IApplication application = excelEngine.Excel;
468446
application.DefaultVersion = ExcelVersion.Xlsx;
469-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
470-
IWorkbook workbook = application.Workbooks.Open(inputStream);
447+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
471448
IWorksheet worksheet = workbook.Worksheets[0];
472449

473450
#region save as JSON
474-
//Saves the workbook to a JSON filestream, as schema by default
475-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Worksheet-To-JSON-filestream-without-schema.json"), FileMode.Create, FileAccess.ReadWrite);
476-
workbook.SaveAsJson(outputStream, worksheet,false);
451+
//Saves the workbook to JSON, as schema by default
452+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Worksheet-To-JSON-filestream-without-schema.json"), worksheet,false);
477453
#endregion
478454

479-
//Dispose streams
480-
outputStream.Dispose();
481-
inputStream.Dispose();
482-
483455
#region Open JSON
484456
//Open default JSON
485457
#endregion
@@ -602,28 +574,20 @@ using (ExcelEngine excelEngine = new ExcelEngine())
602574
{
603575
IApplication application = excelEngine.Excel;
604576
application.DefaultVersion = ExcelVersion.Xlsx;
605-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
606-
IWorkbook workbook = application.Workbooks.Open(inputStream);
577+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
607578
IWorksheet worksheet = workbook.Worksheets[0];
608579

609580
//Custom range
610581
IRange range = worksheet.Range["A1:F100"];
611582

612583
#region save as JSON
613-
//Saves the workbook to a JSON filestream, as schema by default
614-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite);
615-
workbook.SaveAsJson(outputStream, range);
584+
//Saves the workbook to JSON, as schema by default
585+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema-default.json"), range);
616586

617-
//Saves the workbook to a JSON filestream as schema
618-
FileStream stream1 = new FileStream("Output/Excel-Range-To-JSON-as-schema.json", FileMode.Create, FileAccess.ReadWrite);
619-
workbook.SaveAsJson(stream1, range, true);
587+
//Saves the workbook to JSON as schema
588+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-as-schema.json"), range, true);
620589
#endregion
621590

622-
//Dispose streams
623-
outputStream.Dispose();
624-
stream1.Dispose();
625-
inputStream.Dispose();
626-
627591
#region Open JSON
628592
//Open default JSON
629593

@@ -769,23 +733,17 @@ using (ExcelEngine excelEngine = new ExcelEngine())
769733
{
770734
IApplication application = excelEngine.Excel;
771735
application.DefaultVersion = ExcelVersion.Xlsx;
772-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
773-
IWorkbook workbook = application.Workbooks.Open(inputStream);
736+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
774737
IWorksheet worksheet = workbook.Worksheets[0];
775738

776739
//Custom range
777740
IRange range = worksheet.Range["A1:F100"];
778741

779742
#region save as JSON
780-
//Saves the workbook to a JSON filestream, as schema by default
781-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Excel-Range-To-JSON-filestream-without-schema.json"), FileMode.Create, FileAccess.ReadWrite);
782-
workbook.SaveAsJson(outputStream, range, false);
743+
//Saves the workbook to JSON, as schema by default
744+
workbook.SaveAsJson(Path.GetFullPath("Output/Excel-Range-To-JSON-filestream-without-schema.json"), range, false);
783745
#endregion
784746

785-
//Dispose streams
786-
outputStream.Dispose();
787-
inputStream.Dispose();
788-
789747
#region Open JSON
790748
//Open default JSON
791749
#endregion

Document-Processing/Excel/Conversions/Excel-to-ODS/NET/Excel-to-ODS-Conversion.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
5959

6060
#region Save
6161
//Saving the workbook
62-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExcelToODS.ods"), FileMode.Create, FileAccess.Write);
63-
workbook.SaveAs(outputStream, ExcelSaveType.SaveAsODS);
62+
workbook.SaveAs("Output.ods");
6463
#endregion
65-
66-
//Dispose streams
67-
outputStream.Dispose();
6864
}
6965
{% endhighlight %}
7066

Document-Processing/Excel/Conversions/Excel-to-ODS/overview.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ using (ExcelEngine excelEngine = new ExcelEngine())
5959

6060
#region Save
6161
//Saving the workbook
62-
FileStream outputStream = new FileStream(Path.GetFullPath("Output/ExcelToODS.ods"), FileMode.Create, FileAccess.Write);
63-
workbook.SaveAs(outputStream, ExcelSaveType.SaveAsODS);
62+
workbook.SaveAs("Output.ods");
6463
#endregion
65-
66-
//Dispose streams
67-
outputStream.Dispose();
6864
}
6965
{% endhighlight %}
7066

0 commit comments

Comments
 (0)