use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFSheet method commit.
protected final void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
String docName = getRootElementName();
if (docName != null) {
xmlOptions.setSaveSyntheticDocumentElement(new QName("http://schemas.openxmlformats.org/presentationml/2006/main", docName));
}
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
getXmlObject().save(out, xmlOptions);
out.close();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFSheet method importBlip.
/**
* Import a picture data from another document.
*
* @param blipId ID of the package relationship to retrieve.
* @param packagePart package part containing the data to import
* @return ID of the created relationship
*/
String importBlip(String blipId, PackagePart packagePart) {
PackageRelationship blipRel = packagePart.getRelationship(blipId);
PackagePart blipPart;
try {
blipPart = packagePart.getRelatedPart(blipRel);
} catch (InvalidFormatException e) {
throw new POIXMLException(e);
}
XSLFPictureData data = new XSLFPictureData(blipPart);
XMLSlideShow ppt = getSlideShow();
XSLFPictureData pictureData = ppt.addPicture(data.getData(), data.getType());
PackagePart pic = pictureData.getPackagePart();
RelationPart rp = addRelation(blipId, XSLFRelation.IMAGES, new XSLFPictureData(pic));
return rp.getRelationship().getId();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFPictureShape method getPictureData.
/**
* Return the data on the (internal) picture.
* For an external linked picture, will return null
*/
public XSLFPictureData getPictureData() {
if (_data == null) {
String blipId = getBlipId();
if (blipId == null)
return null;
PackagePart p = getSheet().getPackagePart();
PackageRelationship rel = p.getRelationship(blipId);
if (rel != null) {
try {
PackagePart imgPart = p.getRelatedPart(rel);
_data = new XSLFPictureData(imgPart);
} catch (Exception e) {
throw new POIXMLException(e);
}
}
}
return _data;
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFGraphicFrame method copyDiagram.
// TODO should be moved to a sub-class
private void copyDiagram(CTGraphicalObjectData objData, XSLFGraphicFrame srcShape) {
String xpath = "declare namespace dgm='http://schemas.openxmlformats.org/drawingml/2006/diagram' $this//dgm:relIds";
XmlObject[] obj = objData.selectPath(xpath);
if (obj != null && obj.length == 1) {
XmlCursor c = obj[0].newCursor();
XSLFSheet sheet = srcShape.getSheet();
try {
String dm = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "dm"));
PackageRelationship dmRel = sheet.getPackagePart().getRelationship(dm);
PackagePart dmPart = sheet.getPackagePart().getRelatedPart(dmRel);
getSheet().importPart(dmRel, dmPart);
String lo = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "lo"));
PackageRelationship loRel = sheet.getPackagePart().getRelationship(lo);
PackagePart loPart = sheet.getPackagePart().getRelatedPart(loRel);
getSheet().importPart(loRel, loPart);
String qs = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "qs"));
PackageRelationship qsRel = sheet.getPackagePart().getRelationship(qs);
PackagePart qsPart = sheet.getPackagePart().getRelatedPart(qsRel);
getSheet().importPart(qsRel, qsPart);
String cs = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "cs"));
PackageRelationship csRel = sheet.getPackagePart().getRelationship(cs);
PackagePart csPart = sheet.getPackagePart().getRelatedPart(csRel);
getSheet().importPart(csRel, csPart);
} catch (InvalidFormatException e) {
throw new POIXMLException(e);
}
c.dispose();
}
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFHyperlink method linkToExternal.
private void linkToExternal(String url) {
PackagePart thisPP = _sheet.getPackagePart();
if (_link.isSetId() && !_link.getId().isEmpty()) {
thisPP.removeRelationship(_link.getId());
}
PackageRelationship rel = thisPP.addExternalRelationship(url, XSLFRelation.HYPERLINK.getRelation());
_link.setId(rel.getId());
if (_link.isSetAction()) {
_link.unsetAction();
}
}
Aggregations