• 技术文章 >Python技术 >Python基础教程

    Python如何读取excel中的图片

    2021-04-07 17:18:09原创4565
    学会用Python提取word图片的小伙伴,今天又来学提取excel图片的方法啦。本期文章将通过python的包来提取,对比以往的代码更加简洁方便。

    一、环境准备:

    pip install pillow
    pip install pypiwin32

    二、操作代码

    from PIL import ImageGrab
    import win32com.client as win32
    
    excel = win32.gencache.EnsureDispatch('Excel.Application')
    workbook = excel.Workbooks.Open(r'C:\Users\file.xlsx')
    
    for sheet in workbook.Worksheets:
        for i, shape in enumerate(sheet.Shapes):
            if shape.Name.startswith('Picture'):
                shape.Copy()
                image = ImageGrab.grabclipboard()
                image.save('{}.jpg'.format(i+1), 'jpeg')
    excel.Quit()

    三、注意事项

    今天读取excel图片的方法比较简单,下期还有读取pdf图片的方法,大家不要错过哦~更多Python学习推荐:PyThon学习网教学中心

    (推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)

    专题推荐:python读取excel图片
    品易云
    上一篇:Python入门:HTTPS请求与响应服务器 下一篇:Python如何读取pdf中的图片

    相关文章推荐

    • Python如何处理Excel中的数据• 如何把python中的数据导入excel• python怎么把数据保存为excel• Python如何读取pdf中的图片

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网