Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liuwangchao opened this issue Sep 29, 2024 · 1 comment
Open

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

liuwangchao opened this issue Sep 29, 2024 · 1 comment

Comments

@liuwangchao
Copy link
Contributor

liuwangchao commented Sep 29, 2024

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.):

@CR903
Copy link

CR903 commented Dec 3, 2024

the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants