mirror of https://github.com/apache/poi.git
use workbook's xssf factory
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
db71e2328a
commit
88ebe095dc
|
@ -175,7 +175,8 @@ public class StylesTable extends POIXMLDocumentPart implements Styles {
|
|||
public void ensureThemesTable() {
|
||||
if (theme != null) return;
|
||||
|
||||
setTheme((ThemesTable)workbook.createRelationship(XSSFRelation.THEME, XSSFFactory.getInstance()));
|
||||
XSSFFactory factory = workbook == null ? XSSFFactory.getInstance() : workbook.getXssfFactory();
|
||||
setTheme((ThemesTable)workbook.createRelationship(XSSFRelation.THEME, factory));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -241,10 +241,12 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
|
|||
}
|
||||
|
||||
protected RelationPart createChartRelationPart() {
|
||||
XSSFWorkbook wb = getSheet().getWorkbook();
|
||||
XSSFFactory factory = wb == null ? XSSFFactory.getInstance() : wb.getXssfFactory();
|
||||
int chartNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.CHART.getContentType())
|
||||
.size() + 1;
|
||||
|
||||
return createRelationship(XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber, false);
|
||||
return createRelationship(XSSFRelation.CHART, factory, chartNumber, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,8 +288,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
|
|||
* {@link XSSFWorkbook#getAllPictures()} .
|
||||
*/
|
||||
protected PackageRelationship addPictureReference(int pictureIndex) {
|
||||
XSSFWorkbook wb = (XSSFWorkbook) getParent().getParent();
|
||||
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
|
||||
XSSFPictureData data = getSheet().getWorkbook().getAllPictures().get(pictureIndex);
|
||||
XSSFPictureData pic = new XSSFPictureData(data.getPackagePart());
|
||||
RelationPart rp = addRelation(null, XSSFRelation.IMAGES, pic);
|
||||
return rp.getRelationship();
|
||||
|
|
|
@ -563,7 +563,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
// Default drawingNumber = #drawings.size() + 1
|
||||
int drawingNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size() + 1;
|
||||
drawingNumber = getNextPartNumber(XSSFRelation.DRAWINGS, drawingNumber);
|
||||
RelationPart rp = createRelationship(XSSFRelation.DRAWINGS, XSSFFactory.getInstance(), drawingNumber, false);
|
||||
RelationPart rp = createRelationship(XSSFRelation.DRAWINGS, getWorkbook().getXssfFactory(), drawingNumber, false);
|
||||
XSSFDrawing drawing = rp.getDocumentPart();
|
||||
String relId = rp.getRelationship().getId();
|
||||
|
||||
|
@ -590,7 +590,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
if(autoCreate) {
|
||||
int drawingNumber = getNextPartNumber(XSSFRelation.VML_DRAWINGS,
|
||||
getPackagePart().getPackage().getPartsByContentType(XSSFRelation.VML_DRAWINGS.getContentType()).size());
|
||||
RelationPart rp = createRelationship(XSSFRelation.VML_DRAWINGS, XSSFFactory.getInstance(), drawingNumber, false);
|
||||
RelationPart rp = createRelationship(XSSFRelation.VML_DRAWINGS, getWorkbook().getXssfFactory(), drawingNumber, false);
|
||||
drawing = rp.getDocumentPart();
|
||||
String relId = rp.getRelationship().getId();
|
||||
|
||||
|
@ -3531,13 +3531,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
// the sheet has (i.e. sheet 1 -> comments 1)
|
||||
try {
|
||||
sheetComments = (CommentsTable)createRelationship(
|
||||
XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), Math.toIntExact(sheet.getSheetId()));
|
||||
XSSFRelation.SHEET_COMMENTS, getWorkbook().getXssfFactory(), Math.toIntExact(sheet.getSheetId()));
|
||||
} catch(PartAlreadyExistsException e) {
|
||||
// Technically a sheet doesn't need the same number as
|
||||
// it's comments, and clearly someone has already pinched
|
||||
// our number! Go for the next available one instead
|
||||
sheetComments = (CommentsTable)createRelationship(
|
||||
XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), -1);
|
||||
XSSFRelation.SHEET_COMMENTS, getWorkbook().getXssfFactory(), -1);
|
||||
}
|
||||
}
|
||||
return sheetComments;
|
||||
|
@ -4161,7 +4161,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
}
|
||||
}
|
||||
|
||||
RelationPart rp = createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tableNumber, false);
|
||||
RelationPart rp = createRelationship(XSSFRelation.TABLE, getWorkbook().getXssfFactory(), tableNumber, false);
|
||||
XSSFTable table = rp.getDocumentPart();
|
||||
tbl.setId(rp.getRelationship().getId());
|
||||
table.getCTTable().setId(tableNumber);
|
||||
|
@ -4419,14 +4419,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
int tableId = getWorkbook().getPivotTables().size()+1;
|
||||
//Create relationship between pivotTable and the worksheet
|
||||
XSSFPivotTable pivotTable = (XSSFPivotTable) createRelationship(XSSFRelation.PIVOT_TABLE,
|
||||
XSSFFactory.getInstance(), tableId);
|
||||
getWorkbook().getXssfFactory(), tableId);
|
||||
pivotTable.setParentSheet(this);
|
||||
pivotTables.add(pivotTable);
|
||||
XSSFWorkbook workbook = getWorkbook();
|
||||
|
||||
//Create relationship between the pivot cache defintion and the workbook
|
||||
XSSFPivotCacheDefinition pivotCacheDefinition = (XSSFPivotCacheDefinition) workbook.
|
||||
createRelationship(XSSFRelation.PIVOT_CACHE_DEFINITION, XSSFFactory.getInstance(), tableId);
|
||||
createRelationship(XSSFRelation.PIVOT_CACHE_DEFINITION, getWorkbook().getXssfFactory(), tableId);
|
||||
String rId = workbook.getRelationId(pivotCacheDefinition);
|
||||
//Create relationship between pivotTable and pivotCacheDefinition without creating a new instance
|
||||
PackagePart pivotPackagePart = pivotTable.getPackagePart();
|
||||
|
@ -4440,7 +4440,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
|
||||
//Create relationship between pivotcacherecord and pivotcachedefinition
|
||||
XSSFPivotCacheRecords pivotCacheRecords = (XSSFPivotCacheRecords) pivotCacheDefinition.
|
||||
createRelationship(XSSFRelation.PIVOT_CACHE_RECORDS, XSSFFactory.getInstance(), tableId);
|
||||
createRelationship(XSSFRelation.PIVOT_CACHE_RECORDS, getWorkbook().getXssfFactory(), tableId);
|
||||
|
||||
//Set relationships id for pivotCacheDefinition to pivotCacheRecords
|
||||
pivotTable.getPivotCacheDefinition().getCTPivotCacheDefinition().setId(pivotCacheDefinition.getRelationId(pivotCacheRecords));
|
||||
|
|
|
@ -91,7 +91,7 @@ public class XSSFSignatureLine extends SignatureLine {
|
|||
XSSFVMLDrawing vml = sheet.getVMLDrawing(false);
|
||||
POIXMLRelation xtype = mapType(type);
|
||||
int idx = wb.getNextPartNumber(xtype, -1);
|
||||
POIXMLDocumentPart.RelationPart rp = vml.createRelationship(xtype, XSSFFactory.getInstance(), idx, false);
|
||||
POIXMLDocumentPart.RelationPart rp = vml.createRelationship(xtype, wb.getXssfFactory(), idx, false);
|
||||
POIXMLDocumentPart dp = rp.getDocumentPart();
|
||||
try (OutputStream out = dp.getPackagePart().getOutputStream()) {
|
||||
out.write(image);
|
||||
|
|
|
@ -338,6 +338,14 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
|||
this(part.getInputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the XSSFFactory
|
||||
* @since POI 5.1.0
|
||||
*/
|
||||
public XSSFFactory getXssfFactory() {
|
||||
return xssfFactory;
|
||||
}
|
||||
|
||||
protected void beforeDocumentRead() {
|
||||
// Ensure it isn't a XLSB file, which we don't support
|
||||
if (getCorePart().getContentType().equals(XSSFRelation.XLSB_BINARY_WORKBOOK.getContentType())) {
|
||||
|
@ -1987,7 +1995,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
|
|||
if (!getCreationHelper().getReferencedWorkbooks().containsKey(name)){
|
||||
externalLinkIdx = this.getNextPartNumber(XSSFRelation.EXTERNAL_LINKS,
|
||||
this.getPackagePart().getPackage().getPartsByContentType(XSSFRelation.EXTERNAL_LINKS.getContentType()).size());
|
||||
POIXMLDocumentPart.RelationPart rp = this.createRelationship(XSSFRelation.EXTERNAL_LINKS, XSSFFactory.getInstance(), externalLinkIdx, false);
|
||||
POIXMLDocumentPart.RelationPart rp = this.createRelationship(XSSFRelation.EXTERNAL_LINKS, xssfFactory, externalLinkIdx, false);
|
||||
ExternalLinksTable linksTable = rp.getDocumentPart();
|
||||
linksTable.setLinkedFileName(name);
|
||||
this.getExternalLinksTable().add(linksTable);
|
||||
|
|
|
@ -3618,9 +3618,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||
b1 = sheet.getRow(0).getCell(1);
|
||||
assertEquals(2.0, a1.getNumericCellValue());
|
||||
assertEquals("#REF!+3*$A$1", b1.getCellFormula());
|
||||
try (FileOutputStream fos = new FileOutputStream("abc.xlsx")) {
|
||||
wb1.write(fos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue