xlsxwriter 单元格中的 valign 图像

valign images in xlsxwriter cell

单元格中的图像是否有任何破解方法

Is there a way of getting the row_height after sheet.write and text_wrap format is applied?

可能无法访问用于计算字符串边界框的 Windows API。

您或许可以根据字符串的长度做出一些可行的估计。文本换行中的每个新行等于 15 个字符单位或 20 个像素。

Since once of the columns is a text-wrap and the height of those rows are dynamic, I have no way of knowing the row height to calculate the y_offset for those images

这是主要问题。为了准确指定图像位置,您需要指定明确的行高,以便 XlsxWriter 可以根据单元格的大小计算图像的位置。换句话说,您必须避免 Excel 在换行文本时为您提供的自动行高。

固定行高后,您可以使用 'x_offset' 和 'y_offset' 选项将图像准确放置在您想要的位置。

请注意,您还可以使用条件格式根据单元格值创建红绿灯。请参阅此 code from the XlsxWriter docs 的 Sheet9/Example 9 和下图。即使使用文本换行,这些也可以自动居中。