转换Excel为JSON

将Excel工作簿转换为JSON

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

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Load your source workbook
workbook = Workbook("sample.xlsx")
# Convert the workbook to json file.
workbook.save("sample_out.json")

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

from aspose.cells import CellArea, JsonSaveOptions, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Create an options of saving the file.
options = JsonSaveOptions()
# Set the exporting range.
options.export_area = CellArea.create_cell_area("B1", "C4")
# Load your source workbook
workbook = Workbook("sample.xlsx")
# Convert the workbook to json file.
workbook.save("sample_out.json", options)