转换Excel为JSON

将Excel工作簿转换为JSON

不必再想着如何将Excel工作簿转换为JSON,因为Aspose.Cells for Python via Java库已有最佳解决方案。Aspose.Cells for Python via Java API支持将电子表格转换为JSON格式。要将工作簿导出为JSON,请将SaveFormat.JSON作为Workbook.save方法的第二个参数传递。您还可以使用JsonSaveOptions类指定导出工作表到JSON的附加设置。

以下代码示例演示了将Excel工作簿导出为Json。请查看代码将源文件转换为代码生成的Json文件以供参考。

import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook, SaveFormat
# Load Source Excel file
workbook = Workbook("sample.xlsx")
# Save the workbook in JSON format
workbook.save("sample_out.json", SaveFormat.JSON)
jpype.shutdownJVM()

以下代码示例示范了使用JsonSaveOptions类指定附加设置,从而导出Excel工作簿为Json。请参阅转换源文件到代码生成的Json文件的代码以供参考。

import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook, SaveFormat, JsonSaveOptions, CellArea
# Create an options of saving the file.
options = JsonSaveOptions()
# Set the exporting range.
options.setExportArea(CellArea.createCellArea("B1", "C4"))
# Load Source Excel file
workbook = Workbook("sample.xlsx")
# Save the workbook in JSON format
workbook.save("sample_out.json", options)
jpype.shutdownJVM()