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


Java WorksheetPart类代码示例

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


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

示例1: inlineToXlsx

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
@Override
public void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher) {
    try {
        Image image = new Image(paramValue, matcher);
        if (image.isValid()) {
            BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(pkg, worksheetPart, image.imageContent);
            CTOneCellAnchor anchor = new CTOneCellAnchor();
            anchor.setFrom(new CTMarker());
            CellReference cellReference = new CellReference("", newCell.getR());
            anchor.getFrom().setCol(cellReference.getColumn() - 1);
            anchor.getFrom().setRow(cellReference.getRow() - 1);
            anchor.setExt(new CTPositiveSize2D());
            anchor.getExt().setCx(XlsxUtils.convertPxToEmu(image.width));
            anchor.getExt().setCy(XlsxUtils.convertPxToEmu(image.height));
            newCell.setV(null);
            putImage(worksheetPart, pkg, imagePart, anchor);
        }
    } catch (Exception e) {
        throw new ReportFormattingException("An error occurred while inserting bitmap to xlsx file", e);
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:22,代码来源:AbstractInliner.java

示例2: addContent

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
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();
    vmlPart.setContents(getVml(0,0));  // corresponds to A1
      // 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);

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

示例3: main

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

示例4: main

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

示例5: addContent

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
private static void addContent(WorksheetPart sheet) {
	
	// Minimal content already present
	SheetData sheetData = sheet.getJaxbElement().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);
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:17,代码来源:NewSpreadSheetXlsx4j.java

示例6: main

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

示例7: traverse

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
private void traverse(Part parent, RelationshipsPart rp) {
    int chartNum = 0;
    for (Relationship r : rp.getRelationships().getRelationship()) {
        Part part = rp.getPart(r);
        if (handled.contains(part)) {
            continue;
        }

        if (part instanceof JaxbXmlPart) {
            Object o = ((JaxbXmlPart) part).getJaxbElement();

            if (o instanceof CTChartSpace) {
                Drawing drawing = (Drawing) parent;
                CTDrawing ctDrawing = drawing.getJaxbElement();
                Object anchorObj = ctDrawing.getEGAnchor().get(chartNum++);

                Range range = null;
                CTTwoCellAnchor ctTwoCellAnchor = null;
                if (anchorObj instanceof CTTwoCellAnchor) {
                    ctTwoCellAnchor = (CTTwoCellAnchor) anchorObj;
                    CTMarker from = ctTwoCellAnchor.getFrom();
                    CTMarker to = ctTwoCellAnchor.getTo();
                    String sheetName = worksheets.get(worksheets.size() - 1).name;
                    range = new Range(sheetName, from.getCol() + 1, from.getRow() + 1, to.getCol() + 1, to.getRow() + 1);
                }

                chartSpaces.put(range, new ChartWrapper((CTChartSpace) o, drawing, ctTwoCellAnchor));
            }

            if (o instanceof CTStylesheet) {
                styleSheet = new StyleSheet((CTStylesheet)o);

            }

            if (o instanceof Workbook) {
                workbook = (Workbook) o;
            }
        }

        if (part instanceof WorksheetPart) {
            for (Relationship relationship : part.getSourceRelationships()) {
                if (relationship.getType().endsWith("worksheet")) {
                    String sheetId = relationship.getId();
                    for (Sheet sheet : workbook.getSheets().getSheet()) {
                        if (sheet.getId().equals(sheetId)) {
                            worksheets.add(new SheetWrapper((WorksheetPart) part, sheet.getName()));
                        }
                    }

                }
            }
        } else if (part instanceof SharedStrings) {
            sharedStrings = (SharedStrings) part;
        } else if (part instanceof PivotCacheDefinition) {
            pivotCacheDefinitions.add((PivotCacheDefinition) part);
        }

        handled.add(part);

        if (part.getRelationshipsPart() != null) {
            traverse(part, part.getRelationshipsPart());
        }
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:65,代码来源:Document.java

示例8: SheetWrapper

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
public SheetWrapper(WorksheetPart worksheet, String name) {
    this.worksheet = worksheet;
    this.name = name;
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:5,代码来源:Document.java

示例9: getWorksheet

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
public WorksheetPart getWorksheet() {
    return worksheet;
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:4,代码来源:Document.java

示例10: putImage

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

示例11: inlineToXlsx

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
@Override
public void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher) {
    throw new UnsupportedOperationException("Inline html content to XSLX is not supported");
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:5,代码来源:HtmlContentInliner.java

示例12: copyCells

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
protected List<Cell> copyCells(Range templateRange, BandData bandData, Row newRow, List<Cell> templateCells) {
    List<Cell> resultCells = new ArrayList<>();

    Worksheet resultWorksheet = getWorksheet(newRow);
    for (Cell templateCell : templateCells) {
        checkThreadInterrupted();
        Cell newCell = copyCell(templateCell);

        if (newCell.getF() != null) {
            addFormulaForPostProcessing(templateRange, bandData, newRow, templateCell, newCell);
        }

        resultCells.add(newCell);

        CellReference tempRef = new CellReference(templateRange.getSheet(), templateCell);
        CellReference newRef = new CellReference(templateRange.getSheet(), newCell.getR());
        newRef.move(newRow.getR().intValue(), newRef.getColumn());

        //if we have vertical band or horizontal band right after vertical band - it should be shifted
        //only if there is vertical intersection with vertical band?
        newRef.shift(0, previousRangesRightOffset);

        newCell.setR(newRef.toReference());

        newRow.getC().add(newCell);
        newCell.setParent(newRow);

        WorksheetPart worksheetPart = null;
        for (Document.SheetWrapper sheetWrapper : result.getWorksheets()) {
            if (sheetWrapper.getWorksheet().getJaxbElement() == resultWorksheet) {
                worksheetPart = sheetWrapper.getWorksheet();
            }
        }

        updateCell(worksheetPart, bandData, newCell);

        Col templateColumn = template.getColumnForCell(templateRange.getSheet(), tempRef);
        Col resultColumn = result.getColumnForCell(templateRange.getSheet(), newRef);

        if (templateColumn != null && resultColumn == null) {
            resultColumn = XmlUtils.deepCopy(templateColumn, Context.jcSML);
            resultColumn.setMin(newRef.getColumn());
            resultColumn.setMax(newRef.getColumn());
            resultColumn.setOutlineLevel(templateColumn.getOutlineLevel());

            resultWorksheet.getCols().get(0).getCol().add(resultColumn);
        }

        hintProcessor.add(tempRef, templateCell, newCell, bandData);

    }
    return resultCells;
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:54,代码来源:XlsxFormatter.java

示例13: main

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	
	String outputfilepath = "data/xlsx4j/newWorksheet_Xlsx4j.xlsx";
	
	SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
	
	WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
	
	addContent(sheet);
	
	SaveToZipFile saver = new SaveToZipFile(pkg);
	saver.save(outputfilepath);
			
	System.out.println("\n\n done .. " + outputfilepath);	
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:16,代码来源:NewSpreadSheetXlsx4j.java

示例14: inlineToXlsx

import org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart; //导入依赖的package包/类
/**
 * Inline content to xlsx template
 */
void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher);
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:5,代码来源:ContentInliner.java


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