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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations