Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohan2401 authored Dec 13, 2024
1 parent 8267b36 commit bae5235
Showing 1 changed file with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,20 @@ Step 5: Include the below code snippet in **Program.cs** to convert an Excel wor
```csharp
using (ExcelEngine excelEngine = new ExcelEngine())
{
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);
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-Workbook-To-JSON-as-schema-default.json"), FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAsJson(outputStream);

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

//Dispose streams
outputStream.Dispose();
stream1.Dispose();
inputStream.Dispose();

#region Open JSON
//Open default JSON
//Open JSON with Schema
#endregion
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);
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();
}
```

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.
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 comments on commit bae5235

Please sign in to comment.