使用Python实现Excel表格转图片

  from spire.xls import *

  from spire.common import *

  # 创建Workbook对象

  workbook = Workbook()

  # 载入Excel文件

  workbook.LoadFromFile("示例.xlsx")

  # 获取工作表

  sheet = workbook.Worksheets.get_Item(0)

  # 移除页边距

  pageSetup = sheet.PageSetup

  pageSetup.TopMargin = 0

  pageSetup.BottomMargin = 0

  pageSetup.LeftMargin = 0

  pageSetup.RightMargin = 0

  # 将工作表转换为图片

  image = sheet.ToImage(sheet.FirstRow, sheet.FirstColumn, sheet.LastRow, sheet.LastColumn)

  # 保存图片

  image.Save("output/工作表转图片.png", ImageFormat.get_Png())

  workbook.Dispose()