赞
踩
在各种情况下,需要将 Excel 电子表格嵌入到 Web 或桌面应用程序中。在这种情况下的解决方案之一是将 Excel 工作表转换为图像格式。在本文中,将学习如何在 Python中将Excel XLSX 或 XLS 转换为 PNG、JPEG、SVG 或其他图像。
为了将 Excel 的 XLSX 或 XLS 文件转换为图像格式,我们将使用Aspose.Cells for Python via Java它是一个电子表格操作 API,可让您创建、修改或转换 Excel 文件。你可以下载Aspose.Cells for Python
Aspose.Cells for Python via Java 支持将 Excel 文件转换为以下图像格式:
在 Python 中将 Excel 转换为图像
以下是将 Excel 文件转换为图像格式,即 PNG、JPEG 等的步骤。
以下代码示例展示了如何在 Python 中将 Excel 工作表转换为 PNG 图像。
# load the Excel workbook workbook = Workbook("Book1.xlsx") # create image options imgOptions = ImageOrPrintOptions() imgOptions.setSaveFormat(SaveFormat.SVG) # load the worksheet to be rendered sheet = workbook.getWorksheets().get(0) # create sheet render object sr = SheetRender(sheet, imgOptions) # convert sheet to PNG image for j in range(0, sr.getPageCount()): sr.toImage(j, "WorksheetToImage-out%s" %(j) + ".png")
在 Python 中将 Excel 转换为 SVG
以下是在 Python 中将 Excel 文件转换为 SVG 的步骤。
以下代码示例展示了如何在 Python 中将 Excel 转换为 SVG。
# load the Excel workbook workbook = Workbook("Book1.xlsx") # create image options imgOptions = ImageOrPrintOptions() imgOptions.setSaveFormat(SaveFormat.SVG) # get sheet count sheetCount = workbook.getWorksheets().getCount() # loop through the sheets for i in range(0, sheetCount): sheet = workbook.getWorksheets().get(i) # convert each sheet to SVG sr = SheetRender(sheet, imgOptions) for j in range(0, sr.getPageCount()): sr.toImage(j, sheet.getName() + "%s" % j + "_out.svg")
如果您有任何疑问或需求,请随时加入Aspose技术交流群(761297826),很高兴为您提供查询和咨询。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。