Skip to content

Conversation

@focJSi
Copy link

@focJSi focJSi commented Nov 26, 2025

Currently, adding SVGs to a XSSF Workbook is not supported.

I added this feature similarly to #607 (Support SVGs in XWPF) with a basic test.
Do you have any tipps / suggestions to write a better test for this feature?

I have locally tried it out, generating svg_sample.xlsx.

I have read here that for full backwards compatibility, one would have to convert the SVG to a PNG, as Excel does it.
From my undestanding, the same should apply to the added feature in #607, so I decided to give it a try and open the PR similarly. Any thoughts on this?

public static final int PICTURE_TYPE_EPS = 10;
public static final int PICTURE_TYPE_BMP = 11;
public static final int PICTURE_TYPE_WPG = 12;
public static final int PICTURE_TYPE_SVG = 14;
Copy link
Author

@focJSi focJSi Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org.apache.poi.common.usermodel.PictureType.WDP has ooxmlId 13, which is missing here.
Should these constants be refactored to use org.apache.poi.common.usermodel.PictureType#ooxmlId in a seperate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the WDP one here as a placeholder for a later refactor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I added a comment as a placeholder. Hope that was what you were looking for :)

XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();

byte[] data = "test svg data".getBytes(LocaleUtil.CHARSET_1252);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid svg image data (which should not be relevant for this test).
But maybe you can use a valid svg string, so it will not break if someone adds a SVG->PNG converter for backward compatibility

https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/decimal.svg, for example:

<svg viewBox='0 0 125 80' xmlns='http://www.w3.org/2000/svg'>
  <text y="75" font-size="100" font-family="serif"><![CDATA[10]]></text>
</svg>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, adjusted the data

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.

3 participants