Skip to content

Excelize floating images support editAs="oneCell" attribute #2002

Closed
@liuwangchao

Description

@liuwangchao

Description

I found the following three problems when using excelize's floating picture function, hoped to add the attribute editAs="oneCell"

Probrem 1:

Use the floating image in the table exported by Excelize, due to the twoCell format,

	      +------------+------------+
	      |     A      |      B     |
	+-----+------------+------------+
	|     |(x1,y1)     |            |
	|  1  |(A1)._______|______      |
	|     |    |              |     |
	|     |    |              |     |
	+-----+----|    OBJECT    |-----+
	|     |    |              |     |
	|  2  |    |______________.     |
	|     |            |        (B2)|
	|     |            |     (x2,y2)|
	+-----+------------+------------+

the size of the image will change as the coordinates of the lower right corner point change.

When adjusting the row height and column width, the image will also adjust the height and width accordingly, and the ratio of the image will be affected

For example, the original image was in this scale:

IMG_20240930_091921

After adjusting the row height of row 7 and the column width of column C, the proportions of the image are affected.

IMG_20240930_092251

However, this phenomenon does not occur when using floating pictures inserted by Excel.

IMG_20240930_092407

It looks like it's because the floating picture inserted by Excel has the attribute editAs="oneCell", adjusting the row width and column height will not affect the original width and height of the picture.

mmexport1727661154061

Probrem 2:

When I put a floating image on top of a collapsed row or column,

IMG_20240930_095325

Floating images in files exported by Excelize will have the wrong display ratio:

IMG_20240930_101747

It looks like it's because in the method of func (f *File) positionObjectPixels(sheet string, col, row, x1, y1, width, height int) (int, int, int, int, int, int) {}, when calculating colEnd, rowEnd, width, height, the folded rows and columns will also be calculated.

// Subtract the underlying cell widths to find end cell of the object.
for width >= f.getColWidth(sheet, colEnd+1) {
	colEnd++
	width -= f.getColWidth(sheet, colEnd)
}

// Subtract the underlying cell heights to find end cell of the object.
aaa := f.getRowHeight(sheet, rowEnd+1)
for height >= aaa {
    rowEnd++
    bbb := f.getRowHeight(sheet, rowEnd)
    height -= bbb
    aaa = f.getRowHeight(sheet, rowEnd+1)
}

As a result, when the file is actually opened, if rowEnd is in the folded row, the above image proportion problem will occur.

After unfolding, the display returns to normal. After resuming folding, the display will appear abnormal again.

IMG_20240930_101856

Probrem 3:

Pictures exported using Excelize have problems with proportions even on rows and columns that are not folded. The original image is a square with the same width and height, but the proportion of the exported image has changed. The screenshots are compared as follows:

IMG_20240930_102011

This problem may be that the width and height of each cell are inconsistent in files of different standards, which leads to problems in determining the size of the image based on the point in the lower right corner of the image.

IMG_20240930_102350

Describe the results you received:

support editAs="oneCell" attribute

Output of go version:

1.22.6

Excelize version or commit ID:

v2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions