Skip to content

Add ImageEditAs type and update addImage method to support 'twoCell' option#2983

Open
hshoja wants to merge 1 commit intoexceljs:masterfrom
hshoja:master
Open

Add ImageEditAs type and update addImage method to support 'twoCell' option#2983
hshoja wants to merge 1 commit intoexceljs:masterfrom
hshoja:master

Conversation

@hshoja
Copy link
Copy Markdown

@hshoja hshoja commented Oct 8, 2025

Summary

This PR adds support for the twoCell editAs option when adding images to Excel worksheets. This feature allows images to be moved and sized with cells, providing better integration with Excel's filtering and row manipulation features.

This addresses the issue discussed in GitHub Discussion #2648 where the images remain visible when rows containing them are filtered or removed. The current library only supports oneCell (default) and absolute positioning, but Excel's native twoCell option provides the expected behavior for images that should move and resize with their containing cells.

  • All existing tests pass
  • Added new integration test for twoCell functionality
  • Manual testing completed with example code

Test plan

See working example demonstrating the twoCell functionality: ExcelJS twoCell Example

worksheet.addImage(imageId, {
  tl: { col: 1, row: 1 },
  br: { col: 2, row: 2 },
  editAs: "twoCell",
});

@IamMille
Copy link
Copy Markdown

IamMille commented Dec 3, 2025

@hshoja is this suppose to keep the aspect ratio also?

@hshoja
Copy link
Copy Markdown
Author

hshoja commented Dec 3, 2025

@hshoja is this suppose to keep the aspect ratio also?

By default, the "lock aspect ratio" settings are applied in all cases within Excel.

Screenshot 2025-12-03 at 10 52 46

I introduced twoCells to support the first option, which is "move and resize with cells." Since, I found that the "undefined" value isn't functioning properly in the current implementation.

The editAs property in the library is defined as follows:

undefined: Image will be moved and sized with cells
oneCell: Image will be moved with cells but not sized (default)
absolute: Image will not be moved or sized with cells

You might want to try using oneCell, but I'm not entirely sure if it will work as expected.

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

Successfully merging this pull request may close these issues.

2 participants