git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1910949 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_4
throw new IllegalArgumentException("part"); | throw new IllegalArgumentException("part"); | ||||
} | } | ||||
if (partList.containsKey(part._partName)) { | |||||
if (hasPackagePart(part)) { | |||||
if (!partList.get(part._partName).isDeleted()) { | if (!partList.get(part._partName).isDeleted()) { | ||||
throw new InvalidOperationException( | throw new InvalidOperationException( | ||||
"A part with the name '" | "A part with the name '" | ||||
return part; | return part; | ||||
} | } | ||||
protected boolean hasPackagePart(PackagePart part) { | |||||
return partList.containsKey(part._partName); | |||||
} | |||||
/** | /** | ||||
* Remove the specified part in this package. If this part is relationship | * Remove the specified part in this package. If this part is relationship | ||||
* part, then delete all relationships in the source part. | * part, then delete all relationships in the source part. |
// Ensure that core properties are added if missing | // Ensure that core properties are added if missing | ||||
getPackageProperties(); | getPackageProperties(); | ||||
// Add core properties to part list ... | // Add core properties to part list ... | ||||
addPackagePart(this.packageProperties); | |||||
if (!hasPackagePart(this.packageProperties)) { | |||||
addPackagePart(this.packageProperties); | |||||
} | |||||
// ... and to add its relationship ... | // ... and to add its relationship ... | ||||
this.relationships.addRelationship(this.packageProperties | this.relationships.addRelationship(this.packageProperties | ||||
.getPartName().getURI(), TargetMode.INTERNAL, | .getPartName().getURI(), TargetMode.INTERNAL, |
} | } | ||||
} | } | ||||
@Test | |||||
void testBug66675() throws Exception { | |||||
try (XSSFWorkbook wb = openSampleWorkbook("bug66675.xlsx")) { | |||||
POIXMLProperties.CoreProperties coreProperties = wb.getProperties().getCoreProperties(); | |||||
assertNotNull(coreProperties); | |||||
wb.removeSheetAt(0); | |||||
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) { | |||||
wb.write(bos); | |||||
try (XSSFWorkbook wb2 = new XSSFWorkbook(bos.toInputStream())) { | |||||
XSSFSheet sheet = wb2.getSheetAt(0); | |||||
assertNotNull(sheet); | |||||
assertNotNull(wb2.getProperties().getCoreProperties()); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
private static void readByCommonsCompress(File temp_excel_poi) throws IOException { | private static void readByCommonsCompress(File temp_excel_poi) throws IOException { | ||||
/* read by commons-compress*/ | /* read by commons-compress*/ | ||||
try (ZipFile zipFile = new ZipFile(temp_excel_poi)) { | try (ZipFile zipFile = new ZipFile(temp_excel_poi)) { |