Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created November 29, 2022 11:45

Revisions

  1. conholdate-gists renamed this gist Nov 29, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. conholdate-gists created this gist Nov 29, 2022.
    17 changes: 17 additions & 0 deletions CSV-to-JSON-in-Nodejs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    var fs = require('fs');
    var aspose = aspose || {};
    aspose.cells = require("aspose.cells");
    // Instantiate an instance of the LoadOptions class and set the format to CSV.
    var loadOptions = new aspose.cells.LoadOptions(aspose.cells.LoadFormat.CSV);
    // Load CSV file by initializing the constructor by Workbook class.
    var workbook = new aspose.cells.Workbook( "sample.csv", loadOptions);
    // Invoke the getLastCell method to get the last cell in this worksheet. Returns null if there is no data in the worksheet.
    var lastCell = workbook.getWorksheets().get(0).getCells().getLastCell();
    // Set exporting range to json by calling the ExportRangeToJsonOptions method.
    var options = new aspose.cells.ExportRangeToJsonOptions();
    // Call the createRange method to create a Range object from a range of cells.
    var range = workbook.getWorksheets().get(0).getCells().createRange(0, 0, lastCell.getRow() + 1, lastCell.getColumn() + 1);
    // Export the range to json file by calling the exportRangeToJson method.
    var data = aspose.cells.JsonUtility.exportRangeToJson(range, options);
    // Display JSON
    console.log(data);