fix image
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import copy
|
||||
import datetime
|
||||
import io
|
||||
from pathlib import Path
|
||||
|
||||
from openpyxl import load_workbook
|
||||
from openpyxl.drawing.image import Image as XlImage
|
||||
@@ -225,12 +226,26 @@ def _embed_image(ws, png_bytes: bytes, anchor_row: int, pre_rows: int) -> int:
|
||||
# В отличие от TwoCellAnchor, LibreOffice не пересчитывает позицию
|
||||
# через сумму высот строк → картинка не уплывает вверх при склейке форм.
|
||||
img = XlImage(io.BytesIO(png_bytes))
|
||||
cell_anchor = OneCellAnchor()
|
||||
cell_anchor._from = AnchorMarker(col=0, colOff=0, row=anchor_row - 1, rowOff=0)
|
||||
cell_anchor.ext.cx = int(pt_w * 12700) # pt → EMU
|
||||
cell_anchor.ext.cy = int(pt_h * 12700)
|
||||
img.anchor = cell_anchor
|
||||
ws.add_image(img)
|
||||
# Установим размер картинки в пикселях с учётом масштабирования
|
||||
scale = 1.0
|
||||
if pt_w > MAX_PT_W:
|
||||
scale = MAX_PT_W / pt_w
|
||||
img.width = int(px_w * scale)
|
||||
img.height = int(px_h * scale)
|
||||
|
||||
# Добавляем изображение привязкой к ячейке A{anchor_row}
|
||||
try:
|
||||
ws.add_image(img, f"A{anchor_row}")
|
||||
except Exception:
|
||||
try:
|
||||
cell_anchor = OneCellAnchor()
|
||||
cell_anchor._from = AnchorMarker(col=0, colOff=0, row=anchor_row - 1, rowOff=0)
|
||||
cell_anchor.ext.cx = int(pt_w * 12700) # pt → EMU
|
||||
cell_anchor.ext.cy = int(pt_h * 12700)
|
||||
img.anchor = cell_anchor
|
||||
ws.add_image(img)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return -rows_to_delete # отрицательное смещение: строки были удалены
|
||||
|
||||
|
||||
Reference in New Issue
Block a user