import java.util.Locale;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
*/
@Beta
public abstract class XDDFChartData {
+ private static final Logger LOGGER = LogManager.getLogger(XDDFChartData.class);
+
protected XDDFChart parent;
protected List<Series> series;
private XDDFCategoryAxis categoryAxis;
if (categoryData != null && values != null) {
int numOfPoints = category.getPointCount();
if (numOfPoints != values.getPointCount()) {
- throw new IllegalStateException("Category and values must have the same point count, but had " +
+ LOGGER.warn("Category and values must have the same point count, but had " +
numOfPoints + " categories and " + values.getPointCount() + " values.");
}
}
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLException;
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.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
protected RelationPart createChartRelationPart() {
XSSFWorkbook wb = getSheet().getWorkbook();
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;
+ // 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);
}