Skip to content

Fix Anchor Column and Row Positioning by Adjusting Scaling for Excel Defaults#2924

Open
stany-bns wants to merge 1 commit intoexceljs:masterfrom
stany-bns:fix/image-anchor-precision
Open

Fix Anchor Column and Row Positioning by Adjusting Scaling for Excel Defaults#2924
stany-bns wants to merge 1 commit intoexceljs:masterfrom
stany-bns:fix/image-anchor-precision

Conversation

@stany-bns
Copy link
Copy Markdown

…faults

Previously colWidth and rowHeight assumed a simplistic scaling factor, causing incorrect image and object positioning when custom widths/heights were set.

This update uses accurate scaling:

  • 8.43 width = 640000 EMUs
  • 15 height = 180000 EMUs
    This pull request includes several changes aimed at improving code readability and accuracy in calculations, as well as adding a new test for image positioning with custom column widths. The most important changes include refactoring calculation logic in the Anchor class, simplifying test assertions, and introducing a new integration test for image positioning.

Codebase Improvements

  • Refactored calculation logic in Anchor class: Updated column width and row height calculations to use more precise scaling factors for better accuracy. (lib/doc/anchor.js: [1] [2] [3]

  • Simplified test assertions: Replaced multiline assertions with single-line equivalents for better readability in the test suite. (spec/integration/workbook-xlsx-reader.spec.js: [1] [2] [3]

Testing Enhancements

  • New integration test for image positioning: Added a test to verify that images are positioned correctly when custom column widths are set. (spec/integration/workbook/images.spec.js: spec/integration/workbook/images.spec.jsR292-R338)

  • Updated unit tests for Anchor class: Adjusted tests to reflect the new scaling factors in column width and row height calculations. (spec/unit/doc/anchor.spec.js: [1] [2] [3]

These changes collectively improve the maintainability and accuracy of the codebase while enhancing test coverage.

Improves placement precision for images and anchored objects.

Summary

Test plan

Related to source code (for typings update)

…faults

Previously colWidth and rowHeight assumed a simplistic scaling factor,
causing incorrect image and object positioning when custom widths/heights were set.

This update uses accurate scaling:
- 8.43 width = 640000 EMUs
- 15 height = 180000 EMUs

Improves placement precision for images and anchored objects.
privatecoder added a commit to privatecoder/exceljs that referenced this pull request Sep 24, 2025
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.

1 participant