use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFSheet method importPart.
/**
* Import a package part into this sheet.
*/
PackagePart importPart(PackageRelationship srcRel, PackagePart srcPafrt) {
PackagePart destPP = getPackagePart();
PackagePartName srcPPName = srcPafrt.getPartName();
OPCPackage pkg = destPP.getPackage();
if (pkg.containPart(srcPPName)) {
// already exists
return pkg.getPart(srcPPName);
}
destPP.addRelationship(srcPPName, TargetMode.INTERNAL, srcRel.getRelationshipType());
PackagePart part = pkg.createPart(srcPPName, srcPafrt.getContentType());
try {
OutputStream out = part.getOutputStream();
InputStream is = srcPafrt.getInputStream();
IOUtils.copy(is, out);
is.close();
out.close();
} catch (IOException e) {
throw new POIXMLException(e);
}
return part;
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFPictureShape method getPictureLink.
/**
* For an external linked picture, return the last-seen
* path to the picture.
* For an internal picture, returns null.
*/
public URI getPictureLink() {
if (getBlipId() != null) {
// Internal picture, nothing to return
return null;
}
String rId = getBlipLink();
if (rId == null) {
// No link recorded, nothing we can do
return null;
}
PackagePart p = getSheet().getPackagePart();
PackageRelationship rel = p.getRelationship(rId);
if (rel != null) {
return rel.getTargetURI();
}
return null;
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSSFReader method getStylesTable.
/**
* Opens up the Styles Table, parses it, and
* returns a handy object for working with cell styles
*/
public StylesTable getStylesTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.STYLES.getContentType());
if (parts.size() == 0)
return null;
// Create the Styles Table, and associate the Themes if present
StylesTable styles = new StylesTable(parts.get(0));
parts = pkg.getPartsByContentType(XSSFRelation.THEME.getContentType());
if (parts.size() != 0) {
styles.setTheme(new ThemesTable(parts.get(0)));
}
return styles;
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSSFReader method getSheet.
/**
* Returns an InputStream to read the contents of the
* specified Sheet.
* @param relId The relationId of the sheet, from a r:id on the workbook
*/
public InputStream getSheet(String relId) throws IOException, InvalidFormatException {
PackageRelationship rel = workbookPart.getRelationship(relId);
if (rel == null) {
throw new IllegalArgumentException("No Sheet found with r:id " + relId);
}
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
PackagePart sheet = pkg.getPart(relName);
if (sheet == null) {
throw new IllegalArgumentException("No data found for Sheet with r:id " + relId);
}
return sheet.getInputStream();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class StylesTable method commit.
@Override
protected void commit() throws IOException {
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
writeTo(out);
out.close();
}
Aggregations