Search in sources :

Example 11 with PartName

use of org.docx4j.openpackaging.parts.PartName in project docx4j-template by vindell.

the class Docx4jUtils method insertDocx.

// 插入文档
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();
    }
}
Also used : PartName(org.docx4j.openpackaging.parts.PartName) ContentType(org.docx4j.openpackaging.contenttype.ContentType) Relationship(org.docx4j.relationships.Relationship) CTAltChunk(org.docx4j.wml.CTAltChunk) AlternativeFormatInputPart(org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart) IOException(java.io.IOException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Aggregations

PartName (org.docx4j.openpackaging.parts.PartName)11 File (java.io.File)4 SpreadsheetMLPackage (org.docx4j.openpackaging.packages.SpreadsheetMLPackage)4 Part (org.docx4j.openpackaging.parts.Part)4 WorksheetPart (org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart)4 IOException (java.io.IOException)3 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)3 SaveToZipFile (org.docx4j.openpackaging.io.SaveToZipFile)3 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)3 Parts (org.docx4j.openpackaging.parts.Parts)3 Relationship (org.docx4j.relationships.Relationship)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 JAXBException (javax.xml.bind.JAXBException)2 ContentType (org.docx4j.openpackaging.contenttype.ContentType)2 AlternativeFormatInputPart (org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart)2 BinaryPart (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart)2 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)2 CommentsPart (org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart)2 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)2