将图像添加到 XSSFWorkbook
后,我尝试更改插入图像的扩展名。但是,PackagePartName 不允许在设置后更改扩展名。
// Getting the workbook
FileInputStream in = new FileInputStream("testWorkbook.xlsx");
XSSFWorkbook wb = (XSSFWorkbook)WorkbookFactory.create(in);
InputStream inputStream = new FileInputStream("/home/test/test1.png");
// Get the contents of an InputStream as a byte array
byte[] imageData = IOUtils.toByteArray(inputStream);
// Inserting the image
int pictureIndex = workbook.addPicture(imageData, XSSFWorkbook.PICTURE_TYPE_PNG);
XSSFPictureData xssfPictureData = workbook.getAllPictures().get(pictureIndex);
System.out.println(xssfPictureData.getPackagePart().getPartName().getName()); // /xl/media/image1.png
System.out.println(xssfPictureData.getPackagePart().getPartName().getExtension()); // png
// Looking for something similar to this.
xssfPictureData.getPackagePart().getPartName().setExtension("svg"); // Not supported
有没有办法改变图片的扩展名?