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
网友评论