PNG Generated using Microsoft's Office JavaScript API prints incorrectly cells with wrapped text on 2 lines when only one is visible

Pavel Otta (CZ) 0 Reputation points
2026-09-15T13:56:56.2266667+00:00

PNG Generated using Microsoft's Office JavaScript API prints incorrectly cells with wrapped text on 2 lines when only one is visible in Excel online or Excel for Desktop as it prints both lines and broke the design.

Seems like rendering limitation in Microsoft's Office JavaScript API (Office.js), specifically Excel.Range.getImage(), which is implemented by Excel itself.

Our Linked object is correct. The Screenshot is the one that is wrong, because it is a bitmap produced by Excel and we receive it already corrupted.

What the data actually is

The third column header of the ingested range ('Key Deal KPIs'!B6:E14) is a single cell containing wrapped text that needs two lines:

  • line 1: LTM
  • line 2: Mar-19

The row it sits in is only one line tall (11.5pt). Excel's normal on-screen and print rendering clips the second line, so the user only ever sees LTM.

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments

1 answer

Sort by: Oldest
  1. Zahid Barrera Ramirez 275 Reputation points
    2026-09-15T19:01:29.56+00:00

    Hi @Pavel Otta (CZ)

    Based on your description, this looks much more like a rendering bug/limitation in Excel.Range.getImage() than an issue with your linked object.

    Range.getImage() does not simply capture the visible Excel viewport. It asks Excel to render the range into a Base64 PNG, and Microsoft already documents a known issue where wrapped text can be rendered differently from what is visibly shown in the worksheet.

    That matches your scenario very closely:

    • the cell contains two wrapped lines,

    the row height only exposes the first line in Excel,

    the worksheet view correctly clips the second line,

    but Range.getImage() renders both lines into the bitmap.

    So I would not try to “fix” the linked object or downstream image handling. The PNG is already incorrect when returned by Excel.

    As a workaround, the safest options would be:

    temporarily resize the row so the wrapped text is fully visible before calling getImage(), then restore the original height, or

    temporarily replace/normalize the wrapped text in the source range before generating the image, then restore the original value/formatting.

    Neither workaround is ideal if your requirement is to reproduce exactly what the user sees on screen.

    Since the worksheet renders correctly in both Excel for the web and desktop, but Range.getImage() does not, I would report this as an Office.js product bug and include a minimal reproduction showing:

    one cell with wrapped text containing two lines,

    row height set so only the first line is visible,

    Range.getImage() output showing both lines.

    There is historical precedent for Range.getImage() rendering inconsistently across Excel clients, and Microsoft has previously classified similar behavior as product bugs rather than application-code issues.

    If you can provide the Excel version/build and whether the same PNG is produced in both Desktop and Web, that would make the bug report even stronger.

    If this answer was helpful, please consider marking it as helpful or accepting it as the answer.Hi Pavel,

    Based on your description, this looks much more like a rendering bug/limitation in Excel.Range.getImage() than an issue with your linked object.

    Range.getImage() does not simply capture the visible Excel viewport. It asks Excel to render the range into a Base64 PNG, and Microsoft already documents a known issue where wrapped text can be rendered differently from what is visibly shown in the worksheet.

    That matches your scenario very closely:

    the cell contains two wrapped lines,

    the row height only exposes the first line in Excel,

    the worksheet view correctly clips the second line,

    but Range.getImage() renders both lines into the bitmap.

    So I would not try to “fix” the linked object or downstream image handling. The PNG is already incorrect when returned by Excel.

    As a workaround, the safest options would be:

    temporarily resize the row so the wrapped text is fully visible before calling getImage(), then restore the original height, or

    temporarily replace/normalize the wrapped text in the source range before generating the image, then restore the original value/formatting.

    Neither workaround is ideal if your requirement is to reproduce exactly what the user sees on screen.

    Since the worksheet renders correctly in both Excel for the web and desktop, but Range.getImage() does not, I would report this as an Office.js product bug and include a minimal reproduction showing:

    one cell with wrapped text containing two lines,

    row height set so only the first line is visible,

    Range.getImage() output showing both lines.

    There is historical precedent for Range.getImage() rendering inconsistently across Excel clients, and Microsoft has previously classified similar behavior as product bugs rather than application-code issues.

    If you can provide the Excel version/build and whether the same PNG is produced in both Desktop and Web, that would make the bug report even stronger.

    If this answer was helpful, please consider marking it as helpful or accepting it as the answer.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.