美文网首页
pandas 把image写入xls

pandas 把image写入xls

作者: 不知道是哪个号 | 来源:发表于2019-02-27 10:15 被阅读0次
import base64
import pandas as pd
import re
from io import BytesIO

def get_excel(self, img_data=None):
    """img_data: 图片base64字符串数据"""
    output = BytesIO()
    excel_writer = pd.ExcelWriter(output, engine='xlsxwriter')
    base64_data = re.sub('^data:image/.+;base64,', '', img_data)
    byte_data = base64.b64decode(base64_data)
    image_data = BytesIO(byte_data)
    excel_writer.book.add_worksheet('Sheet2').insert_image(0, 0, 'image', {'image_data': image_data})
    excel_writer.save()
    output.seek(0)
    return output

相关文章

网友评论

      本文标题:pandas 把image写入xls

      本文链接:https://www.haomeiwen.com/subject/vgsfyqtx.html