# ReportSheet IO

## Content

You can export and import ReportSheets in various formats, such as JSON, SJS, and Excel.

> **Note**: To use the ReportSheet IO features, specific script files based on the IO operations are necessary for reference. For example,
>
> * \<script src="scripts/gc.spread.sheets.print.x.x.x.min.js">\</script>
> * \<script src="scripts/gc.spread.sheets.io.x.x.x.min.js">\</script>

## Export JSON

For ReportSheet JSON serialization, use the `toJSON` method of the [GC.Spread.Sheets.Workbook](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook) class.
The code below depicts how to export JSON files from the Spread control.

```javascript
// Export the JSON file.
let json = spread.toJSON();
let content = JSON.stringify(json);
let blob = new Blob([content], { type: "application/json;charset=utf-8" });
let fileNameNode = document.getElementById('json-name');
saveAs(blob, (fileNameNode.value || 'report') + ".json");
```

## Export SJS

Use the `save` method of the [GC.Spread.Sheets.Workbook](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook) class to export ReportSheet data to SJS.
The code below depicts how to export SJS files from the Spread control.

```javascript
// Export the .sjs file.
let fileNameNode = document.getElementById('sjs-name');
spread.save(function (blob) {
    saveAs(blob, (fileNameNode.value || 'report') + ".sjs");
}, function (e) {
    console.log(e);
}, {});
```

## Export Excel

Use the `export` method of the [GC.Spread.Sheets.Workbook](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook) class to export ReportSheet data to Excel.
The code below depicts how to export Excel files from the Spread control.

```javascript
// Export the Excel file.
let fileNameNode = document.getElementById('excel-name');
spread.export(
       (blob) => {
              saveAs(blob, (fileNameNode.value || 'report') + ".xlsx");
        },
        null,
        {
              fileType: GC.Spread.Sheets.FileType.excel,
        }
 );
```

## Import JSON

For ReportSheet JSON deserialization, you need to use the `fromJSON` method of the [GC.Spread.Sheets.Workbook](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook) class.
The code below depicts how to import JSON files from the Spread component.

```javascript
// Import the JSON file.
const file = ei.target.files[0];
if (file) {
      if (!file.type || file.type === 'application/json') {
            const reader = new FileReader();
            reader.readAsText(file, "UTF-8");
            reader.onload = function (evt) {
                   const fileString = evt.target.result;
                   const jsonObj = JSON.parse(fileString);
                   spread.fromJSON(jsonObj);
            };
       }
}
```

## Import SJS

Use the `open` method of the [GC.Spread.Sheets.Workbook](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook) class to open an SJS format report.
The code below depicts how a user can select an SJS type of file and open it into the Spread component.

```javascript
// Import the SJS file.
const file = ei.target.files[0];
if (file) {
      spread.open(file, function () { }, function () { }, {});
}
```

## Import Excel

Use the `import` method of the [GC.Spread.Sheets.Workbook](/spreadjs/api/v17/classes/GC.Spread.Sheets.Workbook) class to import an Excel format report.
The code below depicts how you can select an Excel type of file and import it into the Spread component.

```javascript
// Import the Excel file.
const file = ei.target.files[0];
if (file) {
         spread.import(file, function () {
         }, function () { }, {
               fileType: GC.Spread.Sheets.FileType.excel
         })
}
```