org.docx4j.openpackaging.parts.relationships.RelationshipsPart Java Examples
The following examples show how to use
org.docx4j.openpackaging.parts.relationships.RelationshipsPart.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoordinatesWalker.java From docx-stamper with MIT License | 6 votes |
public void walk() { RelationshipsPart relationshipsPart = document.getMainDocumentPart().getRelationshipsPart(); // walk through elements in headers List<Relationship> headerRelationships = getRelationshipsOfType(document, Namespaces.HEADER); for (Relationship header : headerRelationships) { HeaderPart headerPart = (HeaderPart) relationshipsPart.getPart(header.getId()); walkContent(headerPart.getContent()); } // walk through elements in main document part walkContent(document.getMainDocumentPart().getContent()); // walk through elements in headers List<Relationship> footerRelationships = getRelationshipsOfType(document, Namespaces.FOOTER); for (Relationship footer : footerRelationships) { FooterPart footerPart = (FooterPart) relationshipsPart.getPart(footer.getId()); walkContent(footerPart.getContent()); } }
Example #2
Source File: Docx4j_替换模板.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * 替换图表数据 */ private void replacePieChartData(WordprocessingMLPackage wordMLPackage, String[] chartArr) throws Docx4JException { RelationshipsPart rp = wordMLPackage.getMainDocumentPart().getRelationshipsPart(); Relationship rel = rp.getRelationshipByType(Namespaces.SPREADSHEETML_CHART); Chart chart = (Chart) rp.getPart(rel); CTChartSpace chartSpace = chart.getContents(); List<Object> charObjList = chartSpace.getChart().getPlotArea().getAreaChartOrArea3DChartOrLineChart(); CTPieChart pieChart = (CTPieChart) charObjList.get(0); List<CTPieSer> serList = pieChart.getSer(); CTNumDataSource serVal = serList.get(0).getVal(); List<CTNumVal> ptList = serVal.getNumRef().getNumCache().getPt(); ptList.get(0).setV(chartArr[0]); ptList.get(1).setV(chartArr[1]); }
Example #3
Source File: Document.java From yarg with Apache License 2.0 | 5 votes |
public static Document create(SpreadsheetMLPackage thePackage) { Document document = new Document(); document.thePackage = thePackage; RelationshipsPart rp = thePackage.getRelationshipsPart(); document.traverse(null, rp); return document; }
Example #4
Source File: AbstractInliner.java From yarg with Apache License 2.0 | 5 votes |
private void putImage(WorksheetPart worksheetPart, SpreadsheetMLPackage pkg, BinaryPartAbstractImage imagePart, CTOneCellAnchor anchor) throws Docx4JException { PartName drawingPart = new PartName(StringUtils.replaceIgnoreCase(worksheetPart.getPartName().getName(), "worksheets/sheet", "drawings/drawing")); String imagePartName = imagePart.getPartName().getName(); Part part = pkg.getParts().get(drawingPart); if (part != null && !(part instanceof Drawing)) throw new ReportFormattingException("Wrong Class: not a Drawing"); Drawing drawing = (Drawing) part; int currentId = 0; if (drawing == null) { drawing = new Drawing(drawingPart); drawing.setContents(new org.docx4j.dml.spreadsheetdrawing.CTDrawing()); Relationship relationship = worksheetPart.addTargetPart(drawing); org.xlsx4j.sml.CTDrawing smlDrawing = new org.xlsx4j.sml.CTDrawing(); smlDrawing.setId(relationship.getId()); smlDrawing.setParent(worksheetPart.getContents()); worksheetPart.getContents().setDrawing(smlDrawing); } else { currentId = drawing.getContents().getEGAnchor().size(); } CTPicture picture = new CTPicture(); CTBlipFillProperties blipFillProperties = new CTBlipFillProperties(); blipFillProperties.setStretch(new CTStretchInfoProperties()); blipFillProperties.getStretch().setFillRect(new CTRelativeRect()); blipFillProperties.setBlip(new CTBlip()); blipFillProperties.getBlip().setEmbed("rId" + (currentId + 1)); blipFillProperties.getBlip().setCstate(STBlipCompression.PRINT); picture.setBlipFill(blipFillProperties); CTNonVisualDrawingProps nonVisualDrawingProps = new CTNonVisualDrawingProps(); nonVisualDrawingProps.setId(currentId + 2); nonVisualDrawingProps.setName(imagePartName.substring(imagePartName.lastIndexOf("/") + 1)); nonVisualDrawingProps.setDescr(nonVisualDrawingProps.getName()); CTNonVisualPictureProperties nonVisualPictureProperties = new CTNonVisualPictureProperties(); nonVisualPictureProperties.setPicLocks(new CTPictureLocking()); nonVisualPictureProperties.getPicLocks().setNoChangeAspect(true); CTPictureNonVisual nonVisualPicture = new CTPictureNonVisual(); nonVisualPicture.setCNvPr(nonVisualDrawingProps); nonVisualPicture.setCNvPicPr(nonVisualPictureProperties); picture.setNvPicPr(nonVisualPicture); CTShapeProperties shapeProperties = new CTShapeProperties(); CTTransform2D transform2D = new CTTransform2D(); transform2D.setOff(new CTPoint2D()); transform2D.setExt(new CTPositiveSize2D()); shapeProperties.setXfrm(transform2D); shapeProperties.setPrstGeom(new CTPresetGeometry2D()); shapeProperties.getPrstGeom().setPrst(STShapeType.RECT); shapeProperties.getPrstGeom().setAvLst(new CTGeomGuideList()); picture.setSpPr(shapeProperties); anchor.setPic(picture); anchor.setClientData(new CTAnchorClientData()); drawing.getContents().getEGAnchor().add(anchor); Relationship rel = new Relationship(); rel.setId("rId" + (currentId + 1)); rel.setType(Namespaces.IMAGE); rel.setTarget(imagePartName); drawing.getRelationshipsPart().addRelationship(rel); RelationshipsPart relPart = drawing.getRelationshipsPart(); pkg.getParts().remove(relPart.getPartName()); pkg.getParts().put(relPart); pkg.getParts().remove(drawing.getPartName()); pkg.getParts().put(drawing); }
Example #5
Source File: ExpressionReplacementInHeaderAndFooterTest.java From docx-stamper with MIT License | 4 votes |
private HeaderPart getHeaderPart(WordprocessingMLPackage document) { RelationshipsPart relPart = document.getMainDocumentPart().getRelationshipsPart(); Relationship rel = relPart.getRelationshipByType(Namespaces.HEADER); return (HeaderPart) relPart.getPart(rel); }
Example #6
Source File: ExpressionReplacementInHeaderAndFooterTest.java From docx-stamper with MIT License | 4 votes |
private FooterPart getFooterPart(WordprocessingMLPackage document) { RelationshipsPart relPart = document.getMainDocumentPart().getRelationshipsPart(); Relationship rel = relPart.getRelationshipByType(Namespaces.FOOTER); return (FooterPart) relPart.getPart(rel); }