Search in sources :

Example 11 with Relationship

use of org.docx4j.relationships.Relationship in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jAddComments method addContent.

private static void addContent(WorksheetPart sheet) throws JAXBException, Docx4JException {
    // Minimal content already present
    SheetData sheetData = sheet.getContents().getSheetData();
    // Now add
    Row row = Context.getsmlObjectFactory().createRow();
    Cell cell = Context.getsmlObjectFactory().createCell();
    cell.setV("1234");
    row.getC().add(cell);
    row.getC().add(createCell("hello world!"));
    sheetData.getRow().add(row);
    // ADD A COMMENT TO CELL A1
    CommentsPart cp = new CommentsPart();
    cp.setContents(createComment("A1"));
    sheet.addTargetPart(cp);
    // Add <legacyDrawing r:id="rId1"/>
    VMLPart vmlPart = new VMLPart();
    // corresponds to A1
    vmlPart.setContents(getVml(0, 0));
    // you'll need extra VML for each comment
    Relationship rel = sheet.addTargetPart(vmlPart);
    CTLegacyDrawing legacyDrawing = Context.getsmlObjectFactory().createCTLegacyDrawing();
    legacyDrawing.setId(rel.getId());
    sheet.getContents().setLegacyDrawing(legacyDrawing);
}
Also used : SheetData(org.xlsx4j.sml.SheetData) CommentsPart(org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart) Relationship(org.docx4j.relationships.Relationship) VMLPart(org.docx4j.openpackaging.parts.VMLPart) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell) CTLegacyDrawing(org.xlsx4j.sml.CTLegacyDrawing)

Example 12 with Relationship

use of org.docx4j.relationships.Relationship in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jAddImage method main.

public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(Xlsx4jAddImage.class);
    String outputfilepath = dataDir + "AddImage-Xlsx4j.xlsx";
    String imagefilePath = dataDir + "greentick.png";
    SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
    WorksheetPart worksheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
    // Create Drawing part and add to sheet
    Drawing drawingPart = new Drawing();
    Relationship drawingRel = worksheet.addTargetPart(drawingPart);
    // Add anchor XML to worksheet
    org.xlsx4j.sml.CTDrawing drawing = org.xlsx4j.jaxb.Context.getsmlObjectFactory().createCTDrawing();
    worksheet.getJaxbElement().setDrawing(drawing);
    drawing.setId(drawingRel.getId());
    // Create image part and add to Drawing part
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(pkg, drawingPart, FileUtils.readFileToByteArray(new File(imagefilePath)));
    String imageRelID = imagePart.getSourceRelationship().getId();
    // Create and set drawing part content
    // Take your pick ..
    // .. build it using code
    // drawingPart.setJaxbElement(
    // buildDrawingPartContentUsingCode(imageRelID));
    // .. or build it from an XML string
    drawingPart.setJaxbElement(buildDrawingPartContentFromXmlString(imageRelID));
    // Save the xlsx
    SaveToZipFile saver = new SaveToZipFile(pkg);
    saver.save(outputfilepath);
    System.out.println("\n\n done .. " + outputfilepath);
}
Also used : CTDrawing(org.docx4j.dml.spreadsheetdrawing.CTDrawing) Drawing(org.docx4j.openpackaging.parts.DrawingML.Drawing) SpreadsheetMLPackage(org.docx4j.openpackaging.packages.SpreadsheetMLPackage) PartName(org.docx4j.openpackaging.parts.PartName) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) Relationship(org.docx4j.relationships.Relationship) SaveToZipFile(org.docx4j.openpackaging.io.SaveToZipFile) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage) SaveToZipFile(org.docx4j.openpackaging.io.SaveToZipFile) File(java.io.File)

Example 13 with Relationship

use of org.docx4j.relationships.Relationship in project flexmark-java by vsch.

the class DocxContextImpl method getHyperlinkRelationship.

@Override
public Relationship getHyperlinkRelationship(String url) {
    Relationship rel = myHyperlinks.get(url);
    if (rel != null)
        return rel;
    // We need to add a relationship to word/_rels/document.xml.rels
    // but since its external, we don't use the
    // usual wordMLPackage.getMainDocumentPart().addTargetPart
    // mechanism
    org.docx4j.relationships.ObjectFactory factory = new org.docx4j.relationships.ObjectFactory();
    rel = factory.createRelationship();
    rel.setType(Namespaces.HYPERLINK);
    rel.setTarget(url);
    rel.setTargetMode("External");
    myContentContainer.getRelationshipsPart().addRelationship(rel);
    myHyperlinks.put(url, rel);
    return rel;
}
Also used : Relationship(org.docx4j.relationships.Relationship)

Example 14 with Relationship

use of org.docx4j.relationships.Relationship in project Java-Tutorial by gpcodervn.

the class HyperlinkTest method testLink.

private void testLink(String relId, String href) {
    Relationship r = wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByID(relId);
    assertEquals(r.getTarget(), href);
}
Also used : Relationship(org.docx4j.relationships.Relationship)

Example 15 with Relationship

use of org.docx4j.relationships.Relationship in project docx4j-template by vindell.

the class Docx4J_例子2 method createTextFooterPart.

// 文字页脚
public Relationship createTextFooterPart(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception {
    FooterPart footerPart = new FooterPart();
    Relationship rel = t.addTargetPart(footerPart);
    footerPart.setJaxbElement(getTextFtr(wordprocessingMLPackage, factory, footerPart, content, isUnderLine, underLineSz, jcEnumeration));
    return rel;
}
Also used : FooterPart(org.docx4j.openpackaging.parts.WordprocessingML.FooterPart) Relationship(org.docx4j.relationships.Relationship)

Aggregations

Relationship (org.docx4j.relationships.Relationship)27 FooterPart (org.docx4j.openpackaging.parts.WordprocessingML.FooterPart)7 HeaderPart (org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart)7 File (java.io.File)6 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)4 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)3 PartName (org.docx4j.openpackaging.parts.PartName)3 ObjectFactory (org.docx4j.wml.ObjectFactory)3 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 ContentType (org.docx4j.openpackaging.contenttype.ContentType)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)2 AlternativeFormatInputPart (org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart)2 CTAltChunk (org.docx4j.wml.CTAltChunk)2 Text (com.vladsch.flexmark.ast.Text)1 AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)1 EnumeratedReferenceText (com.vladsch.flexmark.ext.enumerated.reference.EnumeratedReferenceText)1 FileNotFoundException (java.io.FileNotFoundException)1 JAXBException (javax.xml.bind.JAXBException)1 CTChartSpace (org.docx4j.dml.chart.CTChartSpace)1