В начале я вставил фотографию с помощью xlsxwriter в код ниже
Код: Выделить всё
def format_sheet_for_mapping_user_sector_location(
writer: pd.ExcelWriter,
sheet_params: dict,
df: pd.DataFrame,
column_headers: OrderedDict[str, MappingColumnHeader],
) -> Worksheet:
image_path = sheet_params.get('image_path')
if image_path:
print(os.path.abspath(image_path))
result = worksheet.insert_image('A1', os.path.abspath(image_path))
print(result)
return worksheet
Код: Выделить всё
def copy_excel_images(source_sheet: Worksheet, target_sheet: Worksheet) -> None:
"""
Copy all images from the source sheet to the target sheet.
"""
for image in source_sheet._images: # Access private `_images` attribute for all images
new_image = Image(image.ref) # Reuse the reference to the image
new_image.anchor = image.anchor # Maintain the same anchor position
target_sheet.add_image(new_image)
Подробнее здесь: https://stackoverflow.com/questions/792 ... xlsxwriter