You can find all details at: Convert JSON to CSV or CSV to JSON Programmatically in C# VB.NET
Created
January 18, 2021 22:07
-
-
Save aspose-com-gists/8ee937b58ee2881ce8ec9dd1cb986d02 to your computer and use it in GitHub Desktop.
Convert JSON to CSV or CSV to JSON Programmatically in C# VB.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load CSV file | |
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.CSV); | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(dataDir + "Sample_out.csv", loadOptions); | |
Aspose.Cells.Cell lastCell = workbook.Worksheets[0].Cells.LastCell; | |
// Set ExportRangeToJsonOptions | |
Aspose.Cells.Utility.ExportRangeToJsonOptions options = new Aspose.Cells.Utility.ExportRangeToJsonOptions(); | |
Aspose.Cells.Range range = workbook.Worksheets[0].Cells.CreateRange(0, 0, lastCell.Row + 1, lastCell.Column + 1); | |
string data = Aspose.Cells.Utility.JsonUtility.ExportRangeToJson(range, options); | |
// Write from CSV to a JSON file | |
System.IO.File.WriteAllText(dataDir + "CSV_out.json", data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read JSON file | |
string str = File.ReadAllText(dataDir + "SampleJson.json"); | |
// Create empty workbook | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(); | |
// Get Cells | |
Aspose.Cells.Cells cells = workbook.Worksheets[0].Cells; | |
// Set JsonLayoutOptions | |
Aspose.Cells.Utility.JsonLayoutOptions importOptions = new Aspose.Cells.Utility.JsonLayoutOptions(); | |
importOptions.ConvertNumericOrDate = true; | |
importOptions.ArrayAsTable = true; | |
importOptions.IgnoreArrayTitle = true; | |
importOptions.IgnoreObjectTitle = true; | |
Aspose.Cells.Utility.JsonUtility.ImportData(str, cells, 0, 0, importOptions); | |
// Save Workbook | |
workbook.Save(dataDir + @"Sample_out.csv"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment