|
|
|
|
|
|
|
|
import org.apache.poi.ooxml.POIXMLDocumentPart; |
|
|
import org.apache.poi.ooxml.POIXMLDocumentPart; |
|
|
import org.apache.poi.ooxml.POIXMLException; |
|
|
import org.apache.poi.ooxml.POIXMLException; |
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
|
|
|
|
|
import org.apache.poi.openxml4j.opc.OPCPackage; |
|
|
import org.apache.poi.openxml4j.opc.PackagePart; |
|
|
import org.apache.poi.openxml4j.opc.PackagePart; |
|
|
import org.apache.poi.openxml4j.opc.PackagePartName; |
|
|
import org.apache.poi.openxml4j.opc.PackagePartName; |
|
|
import org.apache.poi.openxml4j.opc.PackageRelationship; |
|
|
import org.apache.poi.openxml4j.opc.PackageRelationship; |
|
|
|
|
|
|
|
|
protected RelationPart createChartRelationPart() { |
|
|
protected RelationPart createChartRelationPart() { |
|
|
XSSFWorkbook wb = getSheet().getWorkbook(); |
|
|
XSSFWorkbook wb = getSheet().getWorkbook(); |
|
|
XSSFFactory factory = wb == null ? XSSFFactory.getInstance() : wb.getXssfFactory(); |
|
|
XSSFFactory factory = wb == null ? XSSFFactory.getInstance() : wb.getXssfFactory(); |
|
|
int chartNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.CHART.getContentType()) |
|
|
|
|
|
|
|
|
OPCPackage pkg = getPackagePart().getPackage(); |
|
|
|
|
|
int chartNumber = pkg.getPartsByContentType(XSSFRelation.CHART.getContentType()) |
|
|
.size() + 1; |
|
|
.size() + 1; |
|
|
|
|
|
|
|
|
|
|
|
// some broken files have incorrectly named package parts, |
|
|
|
|
|
// so we need to avoid duplicates here by checking and increasing |
|
|
|
|
|
// the part-number |
|
|
|
|
|
try { |
|
|
|
|
|
while (pkg.getPart(PackagingURIHelper.createPartName(XSSFRelation.CHART.getFileName(chartNumber))) != null) { |
|
|
|
|
|
chartNumber++; |
|
|
|
|
|
} |
|
|
|
|
|
} catch (InvalidFormatException e) { |
|
|
|
|
|
throw new IllegalStateException("Failed for " + chartNumber, e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return createRelationship(XSSFRelation.CHART, factory, chartNumber, false); |
|
|
return createRelationship(XSSFRelation.CHART, factory, chartNumber, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|