def test():
book_name_xls = '/Users/admin/jiangzhang/ws/tools/test/身份证识别接口统计表耳环.xls'
url = 'https://img.alicdn.com/imgextra/i2/2201498506788/O1CN01EYM8bZ200xAfddsV1_!!0-item_pic.jpg_430x430q90.jpg'
img_dir = '/Users/admin/jiangzhang/ws/detection/data/使用txt匹配的/batch_20210810/ori/服装/674640_1072056.jpg'
sheet_name_xls = 'a,b'
value_title = [["url", "data", "图片", "机器识别结果", "阈值"], ]
workbook = xlsxwriter.Workbook(book_name_xls) # 新建一个工作簿
sheet = workbook.add_worksheet(sheet_name_xls) # 在工作簿中新建一个表格
col = 2
row = 3
image_width = 750.0
image_height = 480.0
cell_width = 64.0
cell_height = 40.0
sheet.set_default_row(cell_height)
write_image_to_cell(sheet, cell_width, cell_height, col, row, img_dir, image_width, image_height)
workbook.close()
def write_image_to_cell(sheet, cell_width, cell_height, col, row, img_dir, image_width, image_height):
x_scale = (cell_width-5) * 1.0 / image_width
y_scale = (cell_height + 10) * 1.0 / image_height
sheet.insert_image(row, col, img_dir, {'x_offset': 2, 'y_offset': 2, 'x_scale': x_scale, 'y_scale': y_scale, 'positioning': 1})
if __name__ == '__main__':
test()