Skip to content

Commit bae5235

Browse files
authored
Update README.md
1 parent 8267b36 commit bae5235

File tree

1 file changed

+14
-27
lines changed
  • Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/Workbook to JSON with Schema

1 file changed

+14
-27
lines changed

Convert Excel to JSON/Workbook to JSON with Schema/.NET/Workbook to JSON with Schema/Workbook to JSON with Schema/README.md

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,20 @@ Step 5: Include the below code snippet in **Program.cs** to convert an Excel wor
2121
```csharp
2222
using (ExcelEngine excelEngine = new ExcelEngine())
2323
{
24-
IApplication application = excelEngine.Excel;
25-
application.DefaultVersion = ExcelVersion.Xlsx;
26-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
27-
IWorkbook workbook = application.Workbooks.Open(inputStream);
28-
IWorksheet worksheet = workbook.Worksheets[0];
29-
30-
#region save as JSON
31-
//Saves the workbook to a JSON filestream, as schema by default
32-
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Excel-Workbook-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite);
33-
workbook.SaveAsJson(outputStream);
34-
35-
//Saves the workbook to a JSON filestream as schema
36-
FileStream stream1 = new FileStream(Path.GetFullPath(@"Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite);
37-
workbook.SaveAsJson(stream1, true);
38-
#endregion
39-
40-
//Dispose streams
41-
outputStream.Dispose();
42-
stream1.Dispose();
43-
inputStream.Dispose();
44-
45-
#region Open JSON
46-
//Open default JSON
47-
48-
//Open JSON with Schema
49-
#endregion
24+
IApplication application = excelEngine.Excel;
25+
application.DefaultVersion = ExcelVersion.Xlsx;
26+
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
27+
IWorkbook workbook = application.Workbooks.Open(inputStream);
28+
IWorksheet worksheet = workbook.Worksheets[0];
29+
30+
//Saves the workbook to a JSON filestream as schema
31+
FileStream jsonWithSchema = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite);
32+
workbook.SaveAsJson(jsonWithSchema, true);
33+
34+
//Dispose streams
35+
jsonWithSchema.Dispose();
36+
inputStream.Dispose();
5037
}
5138
```
5239

53-
More information about converting an Excel workbook to a JSON file with schema can be found in this [documentation](https://help.syncfusion.com/document-processing/excel/conversions/excel-to-json/overview#workbook-to-json-as-schema) section.
40+
More information about converting an Excel workbook to a JSON file with schema can be found in this [documentation](https://help.syncfusion.com/document-processing/excel/conversions/excel-to-json/overview#workbook-to-json-as-schema) section.

0 commit comments

Comments
 (0)