• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PartName类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.docx4j.openpackaging.parts.PartName的典型用法代码示例。如果您正苦于以下问题:Java PartName类的具体用法?Java PartName怎么用?Java PartName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PartName类属于org.docx4j.openpackaging.parts包,在下文中一共展示了PartName类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: insertDocx

import org.docx4j.openpackaging.parts.PartName; //导入依赖的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


示例2: getComments

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public int getComments(WordprocessingMLPackage wordMLPackage){
	 Parts parts = wordMLPackage.getParts();  
 HashMap<PartName, Part> partMap = parts.getParts();  
 CommentsPart commentPart = (CommentsPart) partMap.get(new CommentsPart().getPartName());  
 Comments comments = commentPart.getContents();  
 List<Comment> commentList = comments.getComment();  
 for (Comment comment : commentList) {  
     StringBuffer sb = new StringBuffer();  
     sb.append(" ID: ").append(comment.getId());  
     sb.append(" 作者:").append(comment.getAuthor());  
     sb.append(" 时间: ").append(comment.getDate().toGregorianCalendar().getTime());  
     sb.append(" 内容:").append(comment.getContent());  
     sb.append(" 文中内容:").append(docCmtMap.get(comment.getId().toString()));  
     System.out.println(sb.toString());  
 }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:17,代码来源:Docx4j_工具类_S3_Test.java


示例3: saveDocxImg

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
/** 
 * @Description: 提取word图片 
 */  
public void saveDocxImg(String filePath, String savePath) throws Exception {  
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage  
            .load(new File(filePath));  
    for (Entry<PartName, Part> entry : wordMLPackage.getParts().getParts()  
            .entrySet()) {  
        if (entry.getValue() instanceof BinaryPartAbstractImage) {  
            BinaryPartAbstractImage binImg = (BinaryPartAbstractImage) entry  
                    .getValue();  
            // 图片minetype  
            String imgContentType = binImg.getContentType();  
            PartName pt = binImg.getPartName();  
            String fileName = null;  
            if (pt.getName().indexOf("word/media/") != -1) {  
                fileName = pt.getName().substring(  
                        pt.getName().indexOf("word/media/")  
                                + "word/media/".length());  
            }  
            System.out.println(String.format("mimetype=%s,filePath=%s",  
                    imgContentType, pt.getName()));  
            FileOutputStream fos = new FileOutputStream(savePath + fileName);  
            ((BinaryPart) entry.getValue()).writeDataToOutputStream(fos);  
            fos.close();  
        }  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:29,代码来源:Docx4j_SaveDocxImg_S3_Test.java


示例4: collectComments

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
private static void collectComments(final Map<BigInteger, CommentWrapper> comments,
		WordprocessingMLPackage document) {
	try {
		CommentsPart commentsPart = (CommentsPart) document.getParts()
				.get(new PartName("/word/comments.xml"));
		if (commentsPart != null) {
			for (Comments.Comment comment : commentsPart.getContents().getComment()) {
				CommentWrapper commentWrapper = comments.get(comment.getId());
				if (commentWrapper != null) {
					commentWrapper.setComment(comment);
				}
			}
		}
	}
	catch (Docx4JException e) {
		throw new IllegalStateException(e);
	}
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:19,代码来源:CommentUtil.java


示例5: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		String dataPath = "src/featurescomparison/workingwithpresentations/createnewpresentation/data/";

		// Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
		PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage(); 
		
		// Need references to these parts to create a slide
		// Please note that these parts *already exist* - they are
		// created by createPackage() above.  See that method
		// for instruction on how to create and add a part.
		MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
				new PartName("/ppt/presentation.xml"));		
		SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
				new PartName("/ppt/slideLayouts/slideLayout1.xml"));
		
		// OK, now we can create a slide
		SlidePart slidePart = presentationMLPackage.createSlidePart(pp, layoutPart, 
				new PartName("/ppt/slides/slide1.xml"));

		presentationMLPackage.save(new java.io.File(dataPath + "Pptx4j-New Presentation.pptx"));
		
		System.out.println("\n\n done .. \n\n");
		
	}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:26,代码来源:Pptx4jCreateNewPresentation.java


示例6: insertDocx

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
private static 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.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,代码行数:16,代码来源:WMLPackageUtils.java


示例7: removeAllComment

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public void removeAllComment(String filePath, String savePath)  
        throws Exception {  
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage  
            .load(new java.io.File(filePath));  
    //清空comments.xml内容   
    Parts parts = wordMLPackage.getParts();  
    HashMap<PartName, Part> partMap = parts.getParts();  
    CommentsPart commentPart = (CommentsPart) partMap.get(new PartName(  
            "/word/comments.xml"));  
    Comments comments = commentPart.getContents();  
    List<Comment> commentList = comments.getComment();  
    for (int i = 0, len = commentList.size(); i < len; i++) {  
        commentList.remove(0);  
    }  
      
    //清空document.xml文件中批注  
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();  
    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart  
            .getContents();  
    Body body = wmlDocumentEl.getBody();  
    CommentFinder cf = new CommentFinder();  
    new TraversalUtil(body, cf);  
    for (Child commentElement : cf.commentElements) {  
        System.out.println(commentElement.getClass().getName());  
        Object parent = commentElement.getParent();  
        List<Object> theList = ((ContentAccessor) parent).getContent();  
        boolean removeResult = remove(theList, commentElement);  
        System.out.println(removeResult);  
    }  
    wordMLPackage.save(new FileOutputStream(savePath));  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:Docx4j_删除所有批注_S3_Test.java


示例8: getNumberingPart

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
/**
 * Extracts the numbering parts of the docx file
 * 
 * @return
 */
private org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart getNumberingPart() {
	org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart numbering = null;
	try {
		numbering = (org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) this.wordMLPackage
				.getParts().get(new PartName("/word/numbering.xml"));
		if (numbering == null) {
			HashMap<org.docx4j.openpackaging.parts.PartName, org.docx4j.openpackaging.parts.Part> mp = this.wordMLPackage
					.getParts().getParts();
			Iterator<java.util.Map.Entry<org.docx4j.openpackaging.parts.PartName, org.docx4j.openpackaging.parts.Part>> it = mp
					.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry<org.docx4j.openpackaging.parts.PartName, org.docx4j.openpackaging.parts.Part> pair = (Map.Entry<org.docx4j.openpackaging.parts.PartName, org.docx4j.openpackaging.parts.Part>) it
						.next();
				if (pair.getValue() instanceof org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) {
					numbering = (org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) pair
							.getValue();
					break;
				}
				it.remove();
			}
		}
	} catch (InvalidFormatException e) {
		System.err.println("Couldn't load numbering part.");
	}
	return numbering;
}
 
开发者ID:mjza,项目名称:MSThesis_Fidus_Docx_Converter,代码行数:32,代码来源:DocxToFidus.java


示例9: insertDocx

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
private static 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.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:cornerpirate,项目名称:ReportCompilerSource,代码行数:16,代码来源:DocxService.java


示例10: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
/**
 * @param args
 * @throws JAXBException 
 * @throws Docx4JException 
 */
public static void main(String[] args) throws JAXBException, Docx4JException {
	// TODO Auto-generated method stub
	SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
      
	WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/sheet1.xml"), "Sheet1", 1);
	      
	CTSheetFormatPr format = Context.getsmlObjectFactory().createCTSheetFormatPr();
	format.setDefaultRowHeight(5);
	format.setCustomHeight(Boolean.TRUE);
	sheet.getJaxbElement().setSheetFormatPr(format);
	      
	SheetData sheetData = sheet.getJaxbElement().getSheetData();
	            
	Row row = Context.getsmlObjectFactory().createRow();
	      
	row.setHt(66.0);
	row.setCustomHeight(Boolean.TRUE);
	row.setR(1L);
	      
	Cell cell1 = Context.getsmlObjectFactory().createCell();
	cell1.setV("1234");
	row.getC().add(cell1);
	      
	Cell cell2 = Context.getsmlObjectFactory().createCell();
	cell2.setV("56");
	row.getC().add(cell2);
	sheetData.getRow().add(row);
	            
	SaveToZipFile saver = new SaveToZipFile(pkg);
	saver.save( System.getProperty("user.dir") + "/data/xlsx4j/RowHeight-Xlsx4j.xlsx");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:37,代码来源:HeightAdjustmentXlsx4j.java


示例11: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
		
		String outputfilepath = System.getProperty("user.dir") + "/data/xlsx4j/AddImage-Xlsx4j.xlsx";
		String imagefilePath  = System.getProperty("user.dir") + "/data/xlsx4j/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);	
	}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:39,代码来源:AddImageXlsx4j.java


示例12: createSlidePart

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
/**
 * Create a slide and add it to the package
 * 
 * @param pp
 * @param layoutPart
 * @param i
 * @return the slide
 * @throws InvalidFormatException
 * @throws JAXBException
 */
private static SlidePart createSlidePart(MainPresentationPart pp, SlideLayoutPart layoutPart, int i) 
	throws InvalidFormatException, JAXBException {
	
	// Slide part
	SlidePart slidePart = new SlidePart(new PartName("/ppt/slides/slide" + i +".xml") );
	pp.addSlideIdListEntry(slidePart);

	slidePart.setJaxbElement( SlidePart.createSld() );
	
	// Slide layout part
	slidePart.addTargetPart(layoutPart);
	
	return slidePart;
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:25,代码来源:Pptx4jAutoShapes.java


示例13: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public static void main(String[] args) throws Exception 
{
	String dataPath = "src/featurescomparison/workingwithpresentations/createtable/data/";
	
	// Where will we save our new .ppxt?
	String outputfilepath = dataPath + "Tables-Pptx4j.pptx";
	
	// Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
	PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage(); 
	
	// Need references to these parts to create a slide
	// Please note that these parts *already exist* - they are
	// created by createPackage() above.  See that method
	// for instruction on how to create and add a part.
	MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
			new PartName("/ppt/presentation.xml"));		
	SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
			new PartName("/ppt/slideLayouts/slideLayout1.xml"));
	
	// OK, now we can create a slide
	SlidePart slidePart = presentationMLPackage.createSlidePart(pp, layoutPart, 
			new PartName("/ppt/slides/slide1.xml"));
			
	// Method 1 - programmatic
	slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add( getTable() );
	
	// Method 2 - from string - on slide 2
	SlidePart slide2 = presentationMLPackage.createSlidePart(pp, layoutPart, 
			new PartName("/ppt/slides/slide2.xml"));
	slide2.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add( createGraphicFrameFromString() );
	
	// All done: save it
	presentationMLPackage.save(new java.io.File(outputfilepath));

	System.out.println("\n\n done .. saved " + outputfilepath);
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:37,代码来源:Pptx4jCreateTable.java


示例14: getCalculationChain

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
protected CTCalcChain getCalculationChain() {
    CTCalcChain calculationChain = null;
    try {
        CalcChain part = (CalcChain) result.getPackage().getParts().get(new PartName("/xl/calcChain.xml"));
        if (part != null) {
            calculationChain = part.getJaxbElement();
            calculationChain.getC().clear();
        }
    } catch (InvalidFormatException e) {
        //do nothing
    }
    return calculationChain;
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:14,代码来源:XlsxFormatter.java


示例15: mergeUsingCTAltChunk

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
/**
 * Merge two docx files using an approach that is based on CTAltChunk.
 * 
 * @param separatorTexts
 * @param topFile
 * @param bottomFile
 * @param outputFile
 * @return
 * @throws Exception
 */
protected static File mergeUsingCTAltChunk(
		WordprocessingMLPackage topPackage, File bottomFile,
		File outputFile) throws Exception {

	/*
	 * Based on
	 * https://stackoverflow.com/questions/2494549/is-there-any-java-library
	 * -maybe-poi-which-allows-to-merge-docx-files
	 * 
	 */

	FileInputStream bottomIs = new FileInputStream(bottomFile);

	MainDocumentPart topMainPart = topPackage.getMainDocumentPart();

	// Get binary representation of bottom file
	byte[] bottomAsBytes = IOUtils.toByteArray(bottomIs);

	/*
	 * Determine a suitable name for the new part, one that is not already
	 * taken (in case of multiple merges).
	 */
	Parts docParts = topPackage.getParts();
	Set<PartName> docPartsNames = docParts.getParts().keySet();
	Set<String> plainPartNames = new HashSet<String>();
	for (PartName pn : docPartsNames) {
		plainPartNames.add(pn.getName());
	}

	String partName = null;
	int index = 0;
	do {
		partName = "/part" + index + ".docx";
		index++;
	} while (plainPartNames.contains(partName));

	/*
	 * Now add the bottom file as another part to the top package, and add a
	 * CTAltChunk to the main document of the top package that references
	 * this new part.
	 */

	AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(
			new PartName(partName));
	afiPart.setContentType(new ContentType(CONTENT_TYPE));
	afiPart.setBinaryData(bottomAsBytes);
	Relationship altChunkRel = topMainPart.addTargetPart(afiPart);

	CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk();
	chunk.setId(altChunkRel.getId());

	topMainPart.addObject(chunk);

	topMainPart.convertAltChunks();

	/*
	 * Finally, save the modified top package to the output file and return
	 * that file.
	 */
	topPackage.save(outputFile);

	return outputFile;
}
 
开发者ID:ShapeChange,项目名称:ShapeChange,代码行数:74,代码来源:DocxUtil.java


示例16: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {

    try { 

        String outputfilepath = System.getProperty("user.dir") + "/data/xlsx4j/AddComments-Xlsx4j.xlsx";

        SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();

        WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
        addContent(sheet);

        pkg.save(new File(outputfilepath));

        System.out.println("\n\n done .. " + outputfilepath);   

    } 
    catch (Exception e) 
    { 
        e.printStackTrace();
    }
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:25,代码来源:AddCommentsXlsx4j.java


示例17: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		final Logger log = LoggerFactory.getLogger(Pptx4jAddImageToSlide.class);
		
		String dataPath = "src/featurescomparison/workingwithslides/addimagetoslide/data/";
		
		// Where will we save our new .pptx?
		String outputfilepath = dataPath + "ImageInSlide-Pptx4j.pptx";
		
		// Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
		PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage(); 
		
		// Need references to these parts to create a slide
		// Please note that these parts *already exist* - they are
		// created by createPackage() above.  See that method
		// for instruction on how to create and add a part.
		MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
				new PartName("/ppt/presentation.xml"));		
		SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
				new PartName("/ppt/slideLayouts/slideLayout1.xml"));
		
		// OK, now we can create a slide
		SlidePart slidePart = presentationMLPackage.createSlidePart(pp, layoutPart, 
				new PartName("/ppt/slides/slide1.xml"));
				
		// Add image part
		File file = new File(dataPath + "greentick.png" );
        BinaryPartAbstractImage imagePart 
        	= BinaryPartAbstractImage.createImagePart(presentationMLPackage, slidePart, file);
		
		        
        // Add p:pic to slide
		slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(
				createPicture(imagePart.getSourceRelationship().getId()));
		

		// Do it again on another slide
		SlidePart slidePart2 = presentationMLPackage.createSlidePart(pp, layoutPart, 
				new PartName("/ppt/slides/slide2.xml"));
		Relationship rel = slidePart2.addTargetPart(imagePart);
		
		slidePart2.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(
				createPicture(rel.getId()));
		
		// All done: save it
		presentationMLPackage.save(new java.io.File(outputfilepath));

		System.out.println("\n\n done .. saved " + outputfilepath);
		
	}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:51,代码来源:Pptx4jAddImageToSlide.java


示例18: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public static void main(String[] args) throws Exception 
{
	String dataPath = "src/featurescomparison/workingwithslides/addautoshapes/data/";
	
	// Where will we save our new .ppxt?
	String outputfilepath = dataPath + "Pptx4jAutoShapes.pptx";
	
	// Create skeletal package
	PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage(); 
	
	MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
			new PartName("/ppt/presentation.xml"));
	
	SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
			new PartName("/ppt/slideLayouts/slideLayout1.xml"));
	
	boolean noLine = false;
	
	/* ST_ShapeType has 203 values
	 * 
	 * Create a slide for each shape */
	int i = 1;  
	for (STShapeType st : STShapeType.values() ) {
	
		System.out.println("Adding slide for shape: " + st.value() );
		
		SlidePart slidePart = createSlidePart(pp, layoutPart, i);
		
		// Create and add shapes
		Shape title = ((Shape)XmlUtils.unmarshalString(
				getSlideTitle(st.value()), Context.jcPML) );
		slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(title);
		
		
		Shape sample = ((Shape)XmlUtils.unmarshalString(
				getPresetShape(st.value(), noLine), Context.jcPML) );
		slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);
		
		i++;
	}
	// All done: save it
	presentationMLPackage.save(new java.io.File(outputfilepath));

	System.out.println("\n\n done .. saved " + outputfilepath);
	
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:47,代码来源:Pptx4jAutoShapes.java


示例19: main

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		String dataPath = "src/featurescomparison/workingwithpresentations/helloworld/data/";
		
		// Where will we save our new .ppxt?
		String outputfilepath = dataPath + "Pptx4jHelloWorld.pptx";
		if (MACRO_ENABLE) outputfilepath += "m";
		
		// Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
		PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage(); 
		
		if (MACRO_ENABLE) {
			ContentTypeManager ctm = presentationMLPackage.getContentTypeManager();
			ctm.removeContentType(new PartName("/ppt/presentation.xml") );
			ctm.addOverrideContentType(new URI("/ppt/presentation.xml"), ContentTypes.PRESENTATIONML_MACROENABLED);
		}
		 
		// Need references to these parts to create a slide
		// Please note that these parts *already exist* - they are
		// created by createPackage() above.  See that method
		// for instruction on how to create and add a part.
		MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
				new PartName("/ppt/presentation.xml"));		
		SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
				new PartName("/ppt/slideLayouts/slideLayout1.xml"));
		
		// OK, now we can create a slide
		SlidePart slidePart = new SlidePart(new PartName("/ppt/slides/slide1.xml"));
		slidePart.setContents( SlidePart.createSld() );		
		pp.addSlide(0, slidePart);
		
		// Slide layout part
		slidePart.addTargetPart(layoutPart);
		
				
		// Create and add shape
		Shape sample = ((Shape)XmlUtils.unmarshalString(SAMPLE_SHAPE, Context.jcPML) );
		slidePart.getContents().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);
		
		// All done: save it
		presentationMLPackage.save(new java.io.File(outputfilepath));

		System.out.println("\n\n done .. saved " + outputfilepath);
		
	}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:46,代码来源:Pptx4jHelloWorld.java


示例20: putImage

import org.docx4j.openpackaging.parts.PartName; //导入依赖的package包/类
private void putImage(WorksheetPart worksheetPart, SpreadsheetMLPackage pkg, BinaryPartAbstractImage imagePart, CTOneCellAnchor anchor) throws Docx4JException {
    PartName drawingPart = new PartName(worksheetPart.getPartName().getName().replace("worksheets/sheet", "drawings/drawing"));
    String imagePartName = imagePart.getPartName().getName();
    Drawing drawing = (Drawing) pkg.getParts().get(drawingPart);
    int currentId = 0;
    if (drawing == null) {
        drawing = new Drawing(drawingPart);
        drawing.setContents(new org.docx4j.dml.spreadsheetdrawing.CTDrawing());
        Relationship relationship = worksheetPart.addTargetPart(drawing);
        org.xlsx4j.sml.CTDrawing smlDrawing = new org.xlsx4j.sml.CTDrawing();
        smlDrawing.setId(relationship.getId());
        smlDrawing.setParent(worksheetPart.getContents());
        worksheetPart.getContents().setDrawing(smlDrawing);
    } else {
        currentId = drawing.getContents().getEGAnchor().size();
    }

    CTPicture picture = new CTPicture();

    CTBlipFillProperties blipFillProperties = new CTBlipFillProperties();
    blipFillProperties.setStretch(new CTStretchInfoProperties());
    blipFillProperties.getStretch().setFillRect(new CTRelativeRect());
    blipFillProperties.setBlip(new CTBlip());
    blipFillProperties.getBlip().setEmbed("rId" + (currentId + 1));
    blipFillProperties.getBlip().setCstate(STBlipCompression.PRINT);

    picture.setBlipFill(blipFillProperties);

    CTNonVisualDrawingProps nonVisualDrawingProps = new CTNonVisualDrawingProps();
    nonVisualDrawingProps.setId(currentId + 2);
    nonVisualDrawingProps.setName(imagePartName.substring(imagePartName.lastIndexOf("/") + 1));
    nonVisualDrawingProps.setDescr(nonVisualDrawingProps.getName());

    CTNonVisualPictureProperties nonVisualPictureProperties = new CTNonVisualPictureProperties();
    nonVisualPictureProperties.setPicLocks(new CTPictureLocking());
    nonVisualPictureProperties.getPicLocks().setNoChangeAspect(true);
    CTPictureNonVisual nonVisualPicture = new CTPictureNonVisual();

    nonVisualPicture.setCNvPr(nonVisualDrawingProps);
    nonVisualPicture.setCNvPicPr(nonVisualPictureProperties);

    picture.setNvPicPr(nonVisualPicture);

    CTShapeProperties shapeProperties = new CTShapeProperties();
    CTTransform2D transform2D = new CTTransform2D();
    transform2D.setOff(new CTPoint2D());
    transform2D.setExt(new CTPositiveSize2D());
    shapeProperties.setXfrm(transform2D);
    shapeProperties.setPrstGeom(new CTPresetGeometry2D());
    shapeProperties.getPrstGeom().setPrst(STShapeType.RECT);
    shapeProperties.getPrstGeom().setAvLst(new CTGeomGuideList());

    picture.setSpPr(shapeProperties);

    anchor.setPic(picture);
    anchor.setClientData(new CTAnchorClientData());

    drawing.getContents().getEGAnchor().add(anchor);

    Relationship rel = new Relationship();
    rel.setId("rId" + (currentId + 1));
    rel.setType(Namespaces.IMAGE);
    rel.setTarget(imagePartName);

    drawing.getRelationshipsPart().addRelationship(rel);
    RelationshipsPart relPart = drawing.getRelationshipsPart();
    pkg.getParts().remove(relPart.getPartName());
    pkg.getParts().put(relPart);
    pkg.getParts().remove(drawing.getPartName());
    pkg.getParts().put(drawing);
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:72,代码来源:AbstractInliner.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LaunchSession类代码示例发布时间:2022-05-23
下一篇:
Java Screen类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap