簡體   English   中英

如何使用 xlsxwriter 將圖像插入到 excel 文件中?

[英]How to insert an image to an excel file with xlsxwriter?

我必須將帶有一些其他數據的圖像寫入我的 Django 項目中的 excel 文件,並且我嘗試了下面的代碼。

for counter_i, cost in enumerate(costs):
        counter_i += 1
        for counter_j, feature in enumerate(features):
            value = getattr(cost, feature)
            if feature == 'image':
                image = str(value)
                worksheet.insert_image(counter_i, counter_j, image, {'x_offset': 15, 'y_offset': 10})
            else:
                worksheet.write(counter_i, counter_j, value)

在此代碼中,“值”包含圖像的路徑。 但是我遇到了錯誤,例如

warn("Image file '%s' not found." % force_unicode(filename))

此外,我嘗試提供整個路徑,例如C:/Users/username/..但這一次,我收到了Permission Denied錯誤。

我怎樣才能解決這個問題?

我一直在使用 xlsxwriter 添加圖像。 但是發現很少有有用的鏈接有類似的問題和一些與此相關的信息。

this_link_if_you_are_using_URL

Image_with_path

類似問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM