将 Excel 转换为 JSON
Contents
[
Hide
]
Aspose.Cells for Python via Java 支持将 Workbook 转换为 Json(JavaScript Object Notation) 文件。
将 Excel 工作簿转换为 JSON
无需考虑如何将 Excel 工作簿转换为 JSON,因为 Aspose.Cells for Python via Java 库有最佳决策。 Aspose.Cells for Python via Java API 支持将电子表格转换为 JSON 格式。要将工作簿导出到 JSON,请通过保存格式.JSON作为第二个参数[工作簿.保存](https://reference.aspose.com/cells/python-java/asposecells.api/workbook#save(java.lang.String,%20int)) 方法。您也可以使用JsonSave选项类以指定将工作表导出到 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
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文件作为参考。
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
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() |