【问题标题】:XLSXWRITER insert_image not working with BytesIOXLSXWRITER insert_image 不适用于 BytesIO
【发布时间】:2020-05-20 22:52:41
【问题描述】:

当直接写入 xlsx 文件时,insert_image 会按预期工作。但是写入 BytesIO 对象时它不起作用,图像根本不会出现。

【问题讨论】:

  • 您将需要添加一个显示它不起作用的示例。这是来自 XlsxWriter 文档的 example,它显示 insert_image() 正在使用 BytesIO。

标签: xlsxwriter insert-image


【解决方案1】:

好的,我必须实际指定 image_data 参数才能使用字节流。

img = 'img.png'
image_file = open(img, 'rb')
image_data = io.BytesIO(image_file.read())
image_file.close()

ws_dashboard.insert_image('A1',img, {'image_data': image_data, 'x_scale': 0.5, 'y_scale': 0.5})

【讨论】:

    猜你喜欢
    • 2014-06-28
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2019-01-09
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    相关资源
    最近更新 更多