本文整理汇总了Java中org.docx4j.relationships.Relationship类的典型用法代码示例。如果您正苦于以下问题:Java Relationship类的具体用法?Java Relationship怎么用?Java Relationship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Relationship类属于org.docx4j.relationships包,在下文中一共展示了Relationship类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Docx4J_简单例子 t = new Docx4J_简单例子();
WordprocessingMLPackage wordMLPackage = t
.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
//页眉
Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);
t.createHeaderReference(wordMLPackage, mp, factory, relationship);
t.addParagraphTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory);
//页脚
t.createNormalTableTest(wordMLPackage, mp, factory);
relationship =t.createFooterPageNumPart(wordMLPackage, mp, factory);
t.createFooterReference(wordMLPackage, mp, factory, relationship);
t.saveWordPackage(wordMLPackage, new File(
"f:/saveFile/temp/s_simple.docx"));
}
示例2: insertDocx
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
private void insertDocx(MainDocumentPart main, byte[] bytes, int chunkId) {
try {
AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/part" + chunkId + ".docx"));
// afiPart.setContentType(new ContentType(CONTENT_TYPE));
afiPart.setContentType(new ContentType(ContentTypes.APPLICATION_XML));
afiPart.setBinaryData(bytes);
Relationship altChunkRel = main.addTargetPart(afiPart);
CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk();
chunk.setId(altChunkRel.getId());
main.addObject(chunk);
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: createHeaderReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public void createHeaderReference(
WordprocessingMLPackage wordprocessingMLPackage,
MainDocumentPart t, ObjectFactory factory, Relationship relationship)
throws InvalidFormatException {
List<SectionWrapper> sections = wordprocessingMLPackage
.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = factory.createSectPr();
t.addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
HeaderReference headerReference = factory.createHeaderReference();
headerReference.setId(relationship.getId());
headerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(headerReference);
}
示例4: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public void createFooterReference(
WordprocessingMLPackage wordprocessingMLPackage,
MainDocumentPart t, ObjectFactory factory, Relationship relationship)
throws InvalidFormatException {
List<SectionWrapper> sections = wordprocessingMLPackage
.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = factory.createSectPr();
t.addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
示例5: createHeaderReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
/**
* 创建页眉引用关系
*
* @param word
* @param relationship
* @throws InvalidFormatException
*/
public static void createHeaderReference(
WordprocessingMLPackage word,
Relationship relationship )
throws InvalidFormatException {
List<SectionWrapper> sections = word.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr==null ) {
sectPr = factory.createSectPr();
word.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
HeaderReference headerReference = factory.createHeaderReference();
headerReference.setId(relationship.getId());
headerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(headerReference);
}
示例6: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
/**
* 创建页脚引用关系
*
* @param word
* @param relationship
* @throws InvalidFormatException
*/
public static void createFooterReference(
WordprocessingMLPackage word,
Relationship relationship )
throws InvalidFormatException {
List<SectionWrapper> sections = word.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr==null ) {
sectPr = factory.createSectPr();
word.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
示例7: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
/**
* First we retrieve the document sections from the package. As we want to add
* a footer, we get the last section and take the section properties from it.
* The section is always present, but it might not have properties, so we check
* if they exist to see if we should create them. If they need to be created,
* we do and add them to the main document part and the section.
* Then we create a reference to the footer, give it the id of the relationship,
* set the type to header/footer reference and add it to the collection of
* references to headers and footers in the section properties.
*
* @param relationship
*/
private static void createFooterReference(Relationship relationship) {
List<SectionWrapper> sections = wordMLPackage.getDocumentModel().getSections();
SectPr sectionProperties = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectionProperties==null ) {
sectionProperties = factory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectionProperties);
sections.get(sections.size() - 1).setSectPr(sectionProperties);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectionProperties.getEGHdrFtrReferences().add(footerReference);
}
示例8: main
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Docx4J_简单例子 t = new Docx4J_简单例子();
WordprocessingMLPackage wordMLPackage = t
.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
//图片页眉
//Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);
//文字页眉
Relationship relationship =t.createTextHeaderPart(wordMLPackage, mp, factory, "我是页眉,多创造,少抄袭", JcEnumeration.CENTER);
t.createHeaderReference(wordMLPackage, mp, factory, relationship);
t.addParagraphTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory);
t.createNormalTableTest(wordMLPackage, mp, factory);
//页脚
relationship =t.createFooterPageNumPart(wordMLPackage, mp, factory);
t.createFooterReference(wordMLPackage, mp, factory, relationship);
t.saveWordPackage(wordMLPackage, new File(
"f:/saveFile/temp/s5_simple.docx"));
}
示例9: createHeaderReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public void createHeaderReference(
WordprocessingMLPackage wordprocessingMLPackage,
MainDocumentPart t, ObjectFactory factory, Relationship relationship)
throws InvalidFormatException {
List<SectionWrapper> sections = wordprocessingMLPackage
.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = factory.createSectPr();
t.addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
HeaderReference headerReference = factory.createHeaderReference();
headerReference.setId(relationship.getId());
headerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(headerReference);
}
示例10: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public void createFooterReference(
WordprocessingMLPackage wordprocessingMLPackage,
MainDocumentPart t, ObjectFactory factory, Relationship relationship)
throws InvalidFormatException {
List<SectionWrapper> sections = wordprocessingMLPackage
.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = factory.createSectPr();
t.addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
示例11: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
/**
* This method fetches the document final section properties, and adds a newly
* created footer reference to them.
*
* @param relationship
*/
public static void createFooterReference(Relationship relationship){
List<SectionWrapper> sections =
wordMLPackage.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr==null ) {
sectPr = factory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
示例12: walk
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
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());
}
}
示例13: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
/**
* This method fetches the document final section properties, and adds a
* newly created footer reference to them.
*
* @param relationship
*/
public static void createFooterReference(WordprocessingMLPackage wordMLPackage, Relationship relationship, ObjectFactory factory) {
List<SectionWrapper> sections = wordMLPackage.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr == null) {
sectPr = factory.createSectPr();
wordMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = factory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);
}
示例14: main
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.createPackage();
// Delete the Styles part, since it clutters up our output
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
Relationship styleRel = mdp.getStyleDefinitionsPart().getSourceRelationships().get(0);
mdp.getRelationshipsPart().removeRelationship(styleRel);
// OK, the guts of this sample:
// The 2 things you need:
// 1. the Header part
Relationship relationship = createFooterPart(wordMLPackage);
// 2. an entry in SectPr
createFooterReference(wordMLPackage, relationship);
// Display the result as Flat OPC XML
FlatOpcXmlCreator worker = new FlatOpcXmlCreator(wordMLPackage);
worker.marshal(System.out);
// Now save it
wordMLPackage.save(new java.io.File(dataPath + "OUT_Footer.docx") );
}
示例15: createFooterReference
import org.docx4j.relationships.Relationship; //导入依赖的package包/类
public static void createFooterReference(
WordprocessingMLPackage wordprocessingMLPackage,
Relationship relationship )
throws InvalidFormatException {
List<SectionWrapper> sections = wordprocessingMLPackage.getDocumentModel().getSections();
SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
// There is always a section wrapper, but it might not contain a sectPr
if (sectPr==null ) {
sectPr = objectFactory.createSectPr();
wordprocessingMLPackage.getMainDocumentPart().addObject(sectPr);
sections.get(sections.size() - 1).setSectPr(sectPr);
}
FooterReference footerReference = objectFactory.createFooterReference();
footerReference.setId(relationship.getId());
footerReference.setType(HdrFtrRef.DEFAULT);
sectPr.getEGHdrFtrReferences().add(footerReference);// add header or
// footer references
}