转换Excel为JSON
Contents
[
Hide
]
Aspose.Cells支持将工作簿转换为Json(JavaScript对象表示)文件。
如何将Excel工作簿转换为JSON
不需要纠结如何将Excel工作簿转换为JSON,因为Aspose.Cells Java库有最佳解决方案。Aspose.Cells Java API支持将电子表格转换为JSON格式。要将工作簿导出为JSON,请将SaveFormat.JSON作为Workbook.save方法的第二个参数传递。您也可以使用JsonSaveOptions类来指定导出工作表为JSON的附加设置。
以下代码示例演示了将Excel工作簿导出为Json。请查看代码将源文件转换为代码生成的Json文件以供参考。
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 Source Excel file | |
Workbook workbook = new Workbook("sample.xlsx"); | |
//Save the workbook in JSON format | |
workbook.save("sample_out.json", SaveFormat.JSON); |
以下代码示例示范了使用JsonSaveOptions类指定附加设置,从而导出Excel工作簿为Json。请参阅转换源文件到代码生成的Json文件的代码以供参考。
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
//Create an options of saving the file. | |
JsonSaveOptions options = new JsonSaveOptions(); | |
//Set the exporting range. | |
options.setExportArea(CellArea.createCellArea("B1", "C4")); | |
//Load Source Excel file | |
Workbook workbook = new Workbook("sample.xlsx"); | |
//Save the workbook in JSON format | |
workbook.save("sample_out.json", options); |