使用xlsx writer将图像插入excel-同一图像重复

时间:2019-03-08 23:00:33

标签: python excel xlsxwriter

我是python 3.6的初学者

我试图让Python从电子表格中读取文件名列表(Output.xlsx,行“ File_Name”),然后打开相应的图像并插入新的电子表格(“ images.xlsx”)中。 / p>

我遇到的问题是它多次在自身顶部插入同一张图片

任何建议将不胜感激:)

import pandas as pd
import xlsxwriter

# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()

#resize rows
worksheet.set_column('A:A', 30)
worksheet.set_default_row(100)

#tells is where to look for the output file names
TF_Output= "Output.xlsx"
xl = pd.ExcelFile(TF_Output)
df = xl.parse('Output')

image_row = 0
image_col = 1

#inserts images into the new excel file
for index, row in df.iterrows():
    variable1 = row['File_Name']
    file = str(variable1)

    for image in file:
        worksheet.insert_image(image_row,
                               image_col,
                               file,
                               {'x_scale': 0.1, 'y_scale': 0.1,
                                'x_offset': 5, 'y_offset': 5,
                                'positioning': 1})
    image_row += 1

workbook.close() 

0 个答案:

没有答案