Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static int getMaxImageSize() {
*/
protected static final POIXMLRelation[] RELATIONS;
static {
RELATIONS = new POIXMLRelation[13];
RELATIONS = new POIXMLRelation[15];
RELATIONS[Workbook.PICTURE_TYPE_EMF] = XSSFRelation.IMAGE_EMF;
RELATIONS[Workbook.PICTURE_TYPE_WMF] = XSSFRelation.IMAGE_WMF;
RELATIONS[Workbook.PICTURE_TYPE_PICT] = XSSFRelation.IMAGE_PICT;
Expand All @@ -69,6 +69,7 @@ public static int getMaxImageSize() {
RELATIONS[XSSFWorkbook.PICTURE_TYPE_EPS] = XSSFRelation.IMAGE_EPS;
RELATIONS[XSSFWorkbook.PICTURE_TYPE_BMP] = XSSFRelation.IMAGE_BMP;
RELATIONS[XSSFWorkbook.PICTURE_TYPE_WPG] = XSSFRelation.IMAGE_WPG;
RELATIONS[XSSFWorkbook.PICTURE_TYPE_SVG] = XSSFRelation.IMAGE_SVG;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ public final class XSSFRelation extends POIXMLRelation {
XSSFPictureData::new, XSSFPictureData::new
);

public static final XSSFRelation IMAGE_SVG = new XSSFRelation(
PictureData.PictureType.SVG.contentType,
PackageRelationshipTypes.IMAGE_PART,
"/xl/media/image#.svg",
XSSFPictureData::new, XSSFPictureData::new
);

public static final XSSFRelation HDPHOTO_WDP = new XSSFRelation(
PictureData.PictureType.WDP.contentType,
PackageRelationshipTypes.HDPHOTO_PART,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ private static POIXMLRelation mapType(PictureType type) throws InvalidFormatExce
return XSSFRelation.IMAGE_WMF;
case WPG:
return XSSFRelation.IMAGE_WPG;
case SVG:
return XSSFRelation.IMAGE_SVG;
default:
throw new InvalidFormatException("Unsupported picture format "+type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
public static final int PICTURE_TYPE_EPS = 10;
public static final int PICTURE_TYPE_BMP = 11;
public static final int PICTURE_TYPE_WPG = 12;
// Picture Type WDP has ooxmlId 13 but is currently not implemented
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 :)


/**
* The underlying XML bean
Expand Down Expand Up @@ -592,6 +594,12 @@ public CTWorkbook getCTWorkbook() {
* @see Workbook#PICTURE_TYPE_JPEG
* @see Workbook#PICTURE_TYPE_PNG
* @see Workbook#PICTURE_TYPE_DIB
* @see #PICTURE_TYPE_GIF
* @see #PICTURE_TYPE_TIFF
* @see #PICTURE_TYPE_EPS
* @see #PICTURE_TYPE_BMP
* @see #PICTURE_TYPE_WPG
* @see #PICTURE_TYPE_SVG
* @see #getAllPictures()
*/
@Override
Expand Down Expand Up @@ -620,6 +628,12 @@ public int addPicture(byte[] pictureData, int format) {
* @see Workbook#PICTURE_TYPE_JPEG
* @see Workbook#PICTURE_TYPE_PNG
* @see Workbook#PICTURE_TYPE_DIB
* @see #PICTURE_TYPE_GIF
* @see #PICTURE_TYPE_TIFF
* @see #PICTURE_TYPE_EPS
* @see #PICTURE_TYPE_BMP
* @see #PICTURE_TYPE_WPG
* @see #PICTURE_TYPE_SVG
* @see #getAllPictures()
*/
public int addPicture(InputStream is, int format) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,39 @@ void testNewPictFormat() throws IOException {
}
}

@Test
void testNewSvgFormat() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
String svg = "<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>";
byte[] data = svg.getBytes(LocaleUtil.CHARSET_1252);

List<XSSFPictureData> pictures = wb.getAllPictures();
assertEquals(0, pictures.size());

int idx = wb.addPicture(data, XSSFWorkbook.PICTURE_TYPE_SVG);
assertEquals(1, pictures.size());
assertEquals("svg", pictures.get(idx).suggestFileExtension());
assertArrayEquals(data, pictures.get(idx).getData());

//TODO finish usermodel API for XSSFPicture
XSSFPicture p1 = drawing.createPicture(new XSSFClientAnchor(), idx);
assertNotNull(p1);

//check that the added pictures are accessible after write
try (XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
List<XSSFPictureData> pictures2 = wbBack.getAllPictures();
assertEquals(1, pictures2.size());

assertEquals("svg", pictures2.get(idx).suggestFileExtension());
assertArrayEquals(data, pictures2.get(idx).getData());
}
}
}

/**
* Bug 53568: XSSFPicture.getPictureData() can return null.
*/
Expand Down