import xlsxwriter,xlrd import glob #打开excel文件 data=xlrd.open_workbook('优秀创意库-20180725.xlsx') #获取第一张工作表(通过索引的方式) table=data.sheets()[0] def new_xlsx(): book = xlsxwriter.Workbook('pict1.xlsx') worksheet = book.add_worksheet('demo') nrows = table.nrows # 表头 rows = table.row_values(0) for i, v in enumerate(rows): if v != '': worksheet.write(0, i, v) #表体 for k in range(1,nrows-1): rows = table.row_values(k) for i, v in enumerate(rows): if v != '': worksheet.set_column('H:H',width=60) worksheet.set_row(k,height=265) if i == 7: worksheet.insert_image('H'+str(k+1), '../screenshot_fina/'+str(int(rows[6]))+'.png', {'x_offset': 6, 'y_offset': 3}) else: worksheet.write(k,i,v) book.close() new_xlsx()