当前位置: 首页>>代码示例>>Java>>正文


Java Relationship类代码示例

本文整理汇总了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"));
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:21,代码来源:Docx4J_简单例子.java

示例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();  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:17,代码来源:Docx4jUtils.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:Docx4J_例子2.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:Docx4J_例子2.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:26,代码来源:Docx4jTest.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:26,代码来源:Docx4jTest.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:29,代码来源:AddingAFooter.java

示例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"));  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:24,代码来源:Docx4J_简单例子2.java

示例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);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:Docx4J_简单例子2.java

示例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);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:Docx4J_简单例子2.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:25,代码来源:AddingPageNrToFooter.java

示例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());
        }
    }
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:22,代码来源:CoordinatesWalker.java

示例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);
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:24,代码来源:AddPageNrToFooter.java

示例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") );

	}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:25,代码来源:Docx4jFooterCreate.java

示例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
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:22,代码来源:Docx4jFooterCreate.java


注:本文中的org.docx4j.relationships.Relationship类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。