Discussion:
Not able to add images to an existing XLSX file
epags
2018-04-06 10:12:00 UTC
Permalink
Hi,I already read a lot of posts, but I didn't find any solution.I'm using
the latest version (3.1.7) and I'm trying to add a JPEG image to every sheet
of one of my XLSX files; every sheet has already another JPEG image, I need
to add a logo.This is my code:
... FileInputStream input = new FileInputStream("file.xlsx"); Workbook
wb = WorkbookFactory.create(input); InputStream is = new
FileInputStream("logo.jpg"); byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close(); CreationHelper helper = wb.getCreationHelper(); Drawing<?>
drawing; for (Sheet sheet : wb) { drawing =
sheet.createDrawingPatriarch(); ClientAnchor anchor =
helper.createClientAnchor(); anchor.setCol1(1);
anchor.setRow1(1); Picture pict = drawing.createPicture(anchor,
pictureIdx); pict.resize(); } FileOutputStream output = new
FileOutputStream("file_with_logo.xlsx"); wb.write(output);
wb.close();...
and this is the error message:
org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with
the name '/xl/media/image86.jpeg' already exists : Packages shall not
contain equivalent part names and package implementers shall neither create
nor recognize packages with equivalent part names. [M1.12] at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:869) at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:833) at
org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:513)
at
org.apache.poi.xssf.usermodel.XSSFWorkbook.addPicture(XSSFWorkbook.java:524)
at
com.savecg.tigreplus.validation.test.TestAddLogo.main(TestAddLogo.java:49)
The incriminated line is *int pictureIdx = wb.addPicture(bytes,
Workbook.PICTURE_TYPE_JPEG);*I checked the list of pictures into the file
(by using the getAllPictures() method), and this is the list:
Name: /xl/media/image86.jpeg - Content Type: image/jpegName:
/xl/media/image87.jpeg - Content Type: image/jpegName:
/xl/media/image88.jpeg - Content Type: image/jpegName:
/xl/media/image89.jpeg - Content Type: image/jpegName:
/xl/media/image90.jpeg - Content Type: image/jpegName:
/xl/media/image91.jpeg - Content Type: image/jpegName:
/xl/media/image92.jpeg - Content Type: image/jpegName:
/xl/media/image93.jpeg - Content Type: image/jpegName:
/xl/media/image94.jpeg - Content Type: image/jpegName:
/xl/media/image95.jpeg - Content Type: image/jpegName:
/xl/media/image96.jpeg - Content Type: image/jpegName:
/xl/media/image97.jpeg - Content Type: image/jpegName:
/xl/media/image98.jpeg - Content Type: image/jpegName:
/xl/media/image99.jpeg - Content Type: image/jpegName:
/xl/media/image100.jpeg - Content Type: image/jpegName:
/xl/media/image101.jpeg - Content Type: image/jpegName:
/xl/media/image102.jpeg - Content Type: image/jpegName:
/xl/media/image103.jpeg - Content Type: image/jpegName:
/xl/media/image104.jpeg - Content Type: image/jpegName:
/xl/media/image105.jpeg - Content Type: image/jpegName:
/xl/media/image106.jpeg - Content Type: image/jpegName:
/xl/media/image107.jpeg - Content Type: image/jpegName:
/xl/media/image108.jpeg - Content Type: image/jpegName:
/xl/media/image109.jpeg - Content Type: image/jpegName:
/xl/media/image110.jpeg - Content Type: image/jpegName:
/xl/media/image111.jpeg - Content Type: image/jpegName:
/xl/media/image112.jpeg - Content Type: image/jpegName:
/xl/media/image113.jpeg - Content Type: image/jpegName:
/xl/media/image114.jpeg - Content Type: image/jpegName:
/xl/media/image115.jpeg - Content Type: image/jpegName:
/xl/media/image116.jpeg - Content Type: image/jpegName:
/xl/media/image117.jpeg - Content Type: image/jpegName:
/xl/media/image118.jpeg - Content Type: image/jpegName:
/xl/media/image119.jpeg - Content Type: image/jpegName:
/xl/media/image120.jpeg - Content Type: image/jpegName:
/xl/media/image121.jpeg - Content Type: image/jpegName:
/xl/media/image122.jpeg - Content Type: image/jpegName:
/xl/media/image123.jpeg - Content Type: image/jpegName:
/xl/media/image124.jpeg - Content Type: image/jpegName:
/xl/media/image125.jpeg - Content Type: image/jpegName:
/xl/media/image126.jpeg - Content Type: image/jpegName:
/xl/media/image127.jpeg - Content Type: image/jpegName:
/xl/media/image128.jpeg - Content Type: image/jpegName:
/xl/media/image129.jpeg - Content Type: image/jpegName:
/xl/media/image130.jpeg - Content Type: image/jpegName:
/xl/media/image131.jpeg - Content Type: image/jpegName:
/xl/media/image132.jpeg - Content Type: image/jpegName:
/xl/media/image133.jpeg - Content Type: image/jpegName:
/xl/media/image134.jpeg - Content Type: image/jpegName:
/xl/media/image135.jpeg - Content Type: image/jpegName:
/xl/media/image136.jpeg - Content Type: image/jpegName:
/xl/media/image137.jpeg - Content Type: image/jpegName:
/xl/media/image138.jpeg - Content Type: image/jpegName:
/xl/media/image139.jpeg - Content Type: image/jpegName:
/xl/media/image140.jpeg - Content Type: image/jpegName:
/xl/media/image141.jpeg - Content Type: image/jpegName:
/xl/media/image142.jpeg - Content Type: image/jpegName:
/xl/media/image143.jpeg - Content Type: image/jpegName:
/xl/media/image144.jpeg - Content Type: image/jpegName:
/xl/media/image145.jpeg - Content Type: image/jpegName:
/xl/media/image146.jpeg - Content Type: image/jpegName:
/xl/media/image147.jpeg - Content Type: image/jpegName:
/xl/media/image148.jpeg - Content Type: image/jpegName:
/xl/media/image149.jpeg - Content Type: image/jpegName:
/xl/media/image150.jpeg - Content Type: image/jpegName:
/xl/media/image151.jpeg - Content Type: image/jpegName:
/xl/media/image152.jpeg - Content Type: image/jpegName:
/xl/media/image153.jpeg - Content Type: image/jpegName:
/xl/media/image154.jpeg - Content Type: image/jpegName:
/xl/media/image155.jpeg - Content Type: image/jpegName:
/xl/media/image156.jpeg - Content Type: image/jpegName:
/xl/media/image157.jpeg - Content Type: image/jpegName:
/xl/media/image158.jpeg - Content Type: image/jpegName:
/xl/media/image159.jpeg - Content Type: image/jpegName:
/xl/media/image160.jpeg - Content Type: image/jpegName:
/xl/media/image161.jpeg - Content Type: image/jpegName:
/xl/media/image162.jpeg - Content Type: image/jpegName:
/xl/media/image163.jpeg - Content Type: image/jpegName:
/xl/media/image164.jpeg - Content Type: image/jpegName:
/xl/media/image165.jpeg - Content Type: image/jpegName:
/xl/media/image166.jpeg - Content Type: image/jpegName:
/xl/media/image167.jpeg - Content Type: image/jpegName:
/xl/media/image168.jpeg - Content Type: image/jpegName:
/xl/media/image169.jpeg - Content Type: image/jpegName:
/xl/media/image170.jpeg - Content Type: image/jpeg
Is there a way to solve the problem?Thanks in advance for any
help.Regards,Eddy



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
epags
2018-04-06 12:36:11 UTC
Permalink
Hi,I already read a lot of posts, but I didn't find any solution.I'm using
the latest version (3.1.7) and I'm trying to add a JPEG image to every sheet
of one of my XLSX files; every sheet has already another JPEG image, I need
to add a logo.This is my code:
... FileInputStream input = new FileInputStream("file.xlsx"); Workbook
wb = WorkbookFactory.create(input); InputStream is = new
FileInputStream("logo.jpg"); byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close(); CreationHelper helper = wb.getCreationHelper(); Drawing<?>
drawing; for (Sheet sheet : wb) { drawing =
sheet.createDrawingPatriarch(); ClientAnchor anchor =
helper.createClientAnchor(); anchor.setCol1(1);
anchor.setRow1(1); Picture pict = drawing.createPicture(anchor,
pictureIdx); pict.resize(); } FileOutputStream output = new
FileOutputStream("file_with_logo.xlsx"); wb.write(output);
wb.close();...
and this is the error message:
org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with
the name '/xl/media/image86.jpeg' already exists : Packages shall not
contain equivalent part names and package implementers shall neither create
nor recognize packages with equivalent part names. [M1.12] at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:869) at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:833) at
org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:513)
at
org.apache.poi.xssf.usermodel.XSSFWorkbook.addPicture(XSSFWorkbook.java:524)
at
com.savecg.tigreplus.validation.test.TestAddLogo.main(TestAddLogo.java:49)
The incriminated line is *int pictureIdx = wb.addPicture(bytes,
Workbook.PICTURE_TYPE_JPEG);*I checked the list of pictures into the file
(by using the getAllPictures() method), and this is the list:
Name: /xl/media/image86.jpeg - Content Type: image/jpegName:
/xl/media/image87.jpeg - Content Type: image/jpegName:
/xl/media/image88.jpeg - Content Type: image/jpegName:
/xl/media/image89.jpeg - Content Type: image/jpegName:
/xl/media/image90.jpeg - Content Type: image/jpegName:
/xl/media/image91.jpeg - Content Type: image/jpegName:
/xl/media/image92.jpeg - Content Type: image/jpegName:
/xl/media/image93.jpeg - Content Type: image/jpegName:
/xl/media/image94.jpeg - Content Type: image/jpegName:
/xl/media/image95.jpeg - Content Type: image/jpegName:
/xl/media/image96.jpeg - Content Type: image/jpegName:
/xl/media/image97.jpeg - Content Type: image/jpegName:
/xl/media/image98.jpeg - Content Type: image/jpegName:
/xl/media/image99.jpeg - Content Type: image/jpegName:
/xl/media/image100.jpeg - Content Type: image/jpegName:
/xl/media/image101.jpeg - Content Type: image/jpegName:
/xl/media/image102.jpeg - Content Type: image/jpegName:
/xl/media/image103.jpeg - Content Type: image/jpegName:
/xl/media/image104.jpeg - Content Type: image/jpegName:
/xl/media/image105.jpeg - Content Type: image/jpegName:
/xl/media/image106.jpeg - Content Type: image/jpegName:
/xl/media/image107.jpeg - Content Type: image/jpegName:
/xl/media/image108.jpeg - Content Type: image/jpegName:
/xl/media/image109.jpeg - Content Type: image/jpegName:
/xl/media/image110.jpeg - Content Type: image/jpegName:
/xl/media/image111.jpeg - Content Type: image/jpegName:
/xl/media/image112.jpeg - Content Type: image/jpegName:
/xl/media/image113.jpeg - Content Type: image/jpegName:
/xl/media/image114.jpeg - Content Type: image/jpegName:
/xl/media/image115.jpeg - Content Type: image/jpegName:
/xl/media/image116.jpeg - Content Type: image/jpegName:
/xl/media/image117.jpeg - Content Type: image/jpegName:
/xl/media/image118.jpeg - Content Type: image/jpegName:
/xl/media/image119.jpeg - Content Type: image/jpegName:
/xl/media/image120.jpeg - Content Type: image/jpegName:
/xl/media/image121.jpeg - Content Type: image/jpegName:
/xl/media/image122.jpeg - Content Type: image/jpegName:
/xl/media/image123.jpeg - Content Type: image/jpegName:
/xl/media/image124.jpeg - Content Type: image/jpegName:
/xl/media/image125.jpeg - Content Type: image/jpegName:
/xl/media/image126.jpeg - Content Type: image/jpegName:
/xl/media/image127.jpeg - Content Type: image/jpegName:
/xl/media/image128.jpeg - Content Type: image/jpegName:
/xl/media/image129.jpeg - Content Type: image/jpegName:
/xl/media/image130.jpeg - Content Type: image/jpegName:
/xl/media/image131.jpeg - Content Type: image/jpegName:
/xl/media/image132.jpeg - Content Type: image/jpegName:
/xl/media/image133.jpeg - Content Type: image/jpegName:
/xl/media/image134.jpeg - Content Type: image/jpegName:
/xl/media/image135.jpeg - Content Type: image/jpegName:
/xl/media/image136.jpeg - Content Type: image/jpegName:
/xl/media/image137.jpeg - Content Type: image/jpegName:
/xl/media/image138.jpeg - Content Type: image/jpegName:
/xl/media/image139.jpeg - Content Type: image/jpegName:
/xl/media/image140.jpeg - Content Type: image/jpegName:
/xl/media/image141.jpeg - Content Type: image/jpegName:
/xl/media/image142.jpeg - Content Type: image/jpegName:
/xl/media/image143.jpeg - Content Type: image/jpegName:
/xl/media/image144.jpeg - Content Type: image/jpegName:
/xl/media/image145.jpeg - Content Type: image/jpegName:
/xl/media/image146.jpeg - Content Type: image/jpegName:
/xl/media/image147.jpeg - Content Type: image/jpegName:
/xl/media/image148.jpeg - Content Type: image/jpegName:
/xl/media/image149.jpeg - Content Type: image/jpegName:
/xl/media/image150.jpeg - Content Type: image/jpegName:
/xl/media/image151.jpeg - Content Type: image/jpegName:
/xl/media/image152.jpeg - Content Type: image/jpegName:
/xl/media/image153.jpeg - Content Type: image/jpegName:
/xl/media/image154.jpeg - Content Type: image/jpegName:
/xl/media/image155.jpeg - Content Type: image/jpegName:
/xl/media/image156.jpeg - Content Type: image/jpegName:
/xl/media/image157.jpeg - Content Type: image/jpegName:
/xl/media/image158.jpeg - Content Type: image/jpegName:
/xl/media/image159.jpeg - Content Type: image/jpegName:
/xl/media/image160.jpeg - Content Type: image/jpegName:
/xl/media/image161.jpeg - Content Type: image/jpegName:
/xl/media/image162.jpeg - Content Type: image/jpegName:
/xl/media/image163.jpeg - Content Type: image/jpegName:
/xl/media/image164.jpeg - Content Type: image/jpegName:
/xl/media/image165.jpeg - Content Type: image/jpegName:
/xl/media/image166.jpeg - Content Type: image/jpegName:
/xl/media/image167.jpeg - Content Type: image/jpegName:
/xl/media/image168.jpeg - Content Type: image/jpegName:
/xl/media/image169.jpeg - Content Type: image/jpegName:
/xl/media/image170.jpeg - Content Type: image/jpeg
Is there a way to solve the problem?Thanks in advance for any
help.Regards,Eddy



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
Dominik Stadler
2018-04-06 13:04:30 UTC
Permalink
Sounds like a bug, can you provide a sample xlsx and jpeg file which
reproduces the problem?

Dominik
Post by epags
Hi,I already read a lot of posts, but I didn't find any solution.I'm using
the latest version (3.1.7) and I'm trying to add a JPEG image to every sheet
of one of my XLSX files; every sheet has already another JPEG image, I need
... FileInputStream input = new FileInputStream("file.xlsx");
Workbook
wb = WorkbookFactory.create(input); InputStream is = new
FileInputStream("logo.jpg"); byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close(); CreationHelper helper = wb.getCreationHelper();
Drawing<?>
drawing; for (Sheet sheet : wb) { drawing =
sheet.createDrawingPatriarch(); ClientAnchor anchor =
helper.createClientAnchor(); anchor.setCol1(1);
anchor.setRow1(1); Picture pict = drawing.createPicture(anchor,
pictureIdx); pict.resize(); } FileOutputStream output = new
FileOutputStream("file_with_logo.xlsx"); wb.write(output);
wb.close();...
org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with
the name '/xl/media/image86.jpeg' already exists : Packages shall not
contain equivalent part names and package implementers shall neither create
nor recognize packages with equivalent part names. [M1.12] at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:869) at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:833) at
org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:513)
at
org.apache.poi.xssf.usermodel.XSSFWorkbook.addPicture(XSSFWorkbook.java:524)
at
com.savecg.tigreplus.validation.test.TestAddLogo.main(TestAddLogo.java:49)
The incriminated line is *int pictureIdx = wb.addPicture(bytes,
Workbook.PICTURE_TYPE_JPEG);*I checked the list of pictures into the file
/xl/media/image170.jpeg - Content Type: image/jpeg
Is there a way to solve the problem?Thanks in advance for any
help.Regards,Eddy
--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
Greg Woolsey
2018-04-06 15:12:36 UTC
Permalink
I can't find it in the archives, but I'm sure there was another issue
recently where adding a new part (not an image, but the mechanism was
similar - maybe tables?) caused an error like this because the algorithm
for picking the number to assign the package part file didn't properly
notice non-contiguous existing values somehow. Perhaps this is similar. I
think that one assumed they started with 1, and just did count+1 to get the
next free one, rather than notice the file had existing values that were
higher than that due to edit cycles that created and removed things
previously.
Post by Dominik Stadler
Sounds like a bug, can you provide a sample xlsx and jpeg file which
reproduces the problem?
Dominik
Post by epags
Hi,I already read a lot of posts, but I didn't find any solution.I'm
using
Post by epags
the latest version (3.1.7) and I'm trying to add a JPEG image to every sheet
of one of my XLSX files; every sheet has already another JPEG image, I
need
Post by epags
... FileInputStream input = new FileInputStream("file.xlsx");
Workbook
wb = WorkbookFactory.create(input); InputStream is = new
FileInputStream("logo.jpg"); byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close(); CreationHelper helper = wb.getCreationHelper();
Drawing<?>
drawing; for (Sheet sheet : wb) { drawing =
sheet.createDrawingPatriarch(); ClientAnchor anchor =
helper.createClientAnchor(); anchor.setCol1(1);
anchor.setRow1(1); Picture pict = drawing.createPicture(anchor,
pictureIdx); pict.resize(); } FileOutputStream output = new
FileOutputStream("file_with_logo.xlsx"); wb.write(output);
wb.close();...
org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part
with
Post by epags
the name '/xl/media/image86.jpeg' already exists : Packages shall not
contain equivalent part names and package implementers shall neither
create
Post by epags
nor recognize packages with equivalent part names. [M1.12] at
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:869)
at
Post by epags
org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:833)
at
org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:513)
Post by epags
at
org.apache.poi.xssf.usermodel.XSSFWorkbook.addPicture(XSSFWorkbook.java:524)
Post by epags
at
com.savecg.tigreplus.validation.test.TestAddLogo.main(TestAddLogo.java:49)
Post by epags
The incriminated line is *int pictureIdx = wb.addPicture(bytes,
Workbook.PICTURE_TYPE_JPEG);*I checked the list of pictures into the file
/xl/media/image170.jpeg - Content Type: image/jpeg
Is there a way to solve the problem?Thanks in advance for any
help.Regards,Eddy
--
http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
Loading...