本文整理了Java中org.apache.poi.xssf.usermodel.XSSFDrawing
类的一些代码示例,展示了XSSFDrawing
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSSFDrawing
类的具体详情如下:
包路径:org.apache.poi.xssf.usermodel.XSSFDrawing
类名称:XSSFDrawing
[英]Represents a SpreadsheetML drawing
[中]表示电子表格图形
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public Iterator<XSSFShape> iterator() {
return _drawing.getShapes().iterator();
}
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
return _drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Creates a chart.
*
* @param anchor
* the client anchor describes how this chart is attached to the
* sheet.
* @return the newly created chart
*/
public XSSFChart createChart(ClientAnchor anchor) {
return createChart((XSSFClientAnchor) anchor);
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Add the indexed picture to this drawing relations
*
* @param pictureIndex
* the index of the picture in the workbook collection of
* pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()}
* .
*/
@SuppressWarnings("resource")
protected PackageRelationship addPictureReference(int pictureIndex) {
XSSFWorkbook wb = (XSSFWorkbook) getParent().getParent();
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
XSSFPictureData pic = new XSSFPictureData(data.getPackagePart());
RelationPart rp = addRelation(null, XSSFRelation.IMAGES, pic);
return rp.getRelationship();
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Creates a chart.
*
* @param anchor
* the client anchor describes how this chart is attached to the
* sheet.
* @return the newly created chart
* @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor)
*/
public XSSFChart createChart(XSSFClientAnchor anchor) {
int chartNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.CHART.getContentType())
.size() + 1;
RelationPart rp = createRelationship(XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber, false);
XSSFChart chart = rp.getDocumentPart();
String chartRelId = rp.getRelationship().getId();
XSSFGraphicFrame frame = createGraphicFrame(anchor);
frame.setChart(chart, chartRelId);
frame.getCTGraphicalObjectFrame().setXfrm(createXfrm(anchor));
return chart;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Creates a picture.
*
* @param anchor
* the client anchor describes how this picture is attached to
* the sheet.
* @param pictureIndex
* the index of the picture in the workbook collection of
* pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()}
* .
*
* @return the newly created picture shape.
*/
public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) {
PackageRelationship rel = addPictureReference(pictureIndex);
long shapeId = newShapeId();
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTPicture ctShape = ctAnchor.addNewPic();
ctShape.set(XSSFPicture.prototype());
ctShape.getNvPicPr().getCNvPr().setId(shapeId);
XSSFPicture shape = new XSSFPicture(this, ctShape);
shape.anchor = anchor;
shape.setPictureReference(rel);
ctShape.getSpPr().setXfrm(createXfrm(anchor));
return shape;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public XSSFObjectData createObjectData(ClientAnchor anchor, int storageId, int pictureIndex) {
XSSFSheet sh = getSheet();
PackagePart sheetPart = sh.getPackagePart();
XSSFSheet sheet = getSheet();
XSSFWorkbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet);
long shapeId = (sheetIndex + 1L) * 1024 + newShapeId();
PackageRelationship imgSheetPR = sheetPart.addRelationship(imgPN, TargetMode.INTERNAL,
PackageRelationshipTypes.IMAGE_PART);
PackageRelationship imgDrawPR = getPackagePart().addRelationship(imgPN, TargetMode.INTERNAL,
PackageRelationshipTypes.IMAGE_PART);
cur1.insertAttributeWithValue("moveWithCells", "1");
CTTwoCellAnchor ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor);
ctShape.getSpPr().setXfrm(createXfrm((XSSFClientAnchor) anchor));
代码示例来源:origin: org.apache.poi/poi-examples
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
XSSFChart chart = drawing.createChart(anchor);
XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Returns the shapes associated with this sheet,
* an empty list or null if there is an exception
*/
public List<XSSFShape> getShapes() {
PackagePart sheetPkg = getSheetPart();
List<XSSFShape> shapes = new LinkedList<>();
// Do we have a comments relationship? (Only ever one if so)
try {
PackageRelationshipCollection drawingsList = sheetPkg.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation());
for (int i = 0; i < drawingsList.size(); i++) {
PackageRelationship drawings = drawingsList.getRelationship(i);
PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI());
PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName);
if (drawingsPart == null) {
//parts can go missing; Excel ignores them silently -- TIKA-2134
LOGGER.log(POILogger.WARN, "Missing drawing: " + drawingsName + ". Skipping it.");
continue;
}
XSSFDrawing drawing = new XSSFDrawing(drawingsPart);
shapes.addAll(drawing.getShapes());
}
} catch (XmlException|InvalidFormatException|IOException e) {
LOGGER.log(POILogger.WARN, e);
return null;
}
return shapes;
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
/**
* Creates a chart.
* @param anchor the client anchor describes how this chart is attached to
* the sheet.
* @return the newly created chart
* @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor)
*/
public XSSFChart createChart(XSSFClientAnchor anchor) {
int chartNumber = getPackagePart().getPackage().
getPartsByContentType(XSSFRelation.CHART.getContentType()).size() + 1;
XSSFChart chart = (XSSFChart) createRelationship(
XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber);
String chartRelId = chart.getPackageRelationship().getId();
XSSFGraphicFrame frame = createGraphicFrame(anchor);
frame.setChart(chart, chartRelId);
return chart;
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
/**
* Add the indexed picture to this drawing relations
*
* @param pictureIndex the index of the picture in the workbook collection of pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} .
*/
protected PackageRelationship addPictureReference(int pictureIndex){
XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
PackagePartName ppName = data.getPackagePart().getPartName();
PackageRelationship rel = getPackagePart().addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
addRelation(rel.getId(),new XSSFPictureData(data.getPackagePart(), rel));
return rel;
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
clonedDg.getCTDrawing().set(dg.getCTDrawing());
List<POIXMLDocumentPart> srcRels = srcSheet.createDrawingPatriarch().getRelations();
for (POIXMLDocumentPart rel : srcRels) {
PackageRelationship relation = rel.getPackageRelationship();
clonedSheet
.createDrawingPatriarch()
.getPackagePart()
.addRelationship(relation.getTargetURI(), relation.getTargetMode(),
relation.getRelationshipType(), relation.getId());
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
/**
* Creates a picture.
*
* @param anchor the client anchor describes how this picture is attached to the sheet.
* @param pictureIndex the index of the picture in the workbook collection of pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} .
*
* @return the newly created picture shape.
*/
public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex)
{
PackageRelationship rel = addPictureReference(pictureIndex);
long shapeId = newShapeId();
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTPicture ctShape = ctAnchor.addNewPic();
ctShape.set(XSSFPicture.prototype());
ctShape.getNvPicPr().getCNvPr().setId(shapeId);
XSSFPicture shape = new XSSFPicture(this, ctShape);
shape.anchor = anchor;
shape.setPictureReference(rel);
return shape;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Imports the chart from the <code>srcChart</code> into this drawing.
*
* @param srcChart
* the source chart to be cloned into this drawing.
* @return the newly created chart.
* @throws XmlException
* @throws IOException
* @since 4.0.0
*/
public XSSFChart importChart(XSSFChart srcChart) throws IOException, XmlException {
CTTwoCellAnchor anchor = ((XSSFDrawing) srcChart.getParent()).getCTDrawing().getTwoCellAnchorArray(0);
CTMarker from = (CTMarker) anchor.getFrom().copy();
CTMarker to = (CTMarker) anchor.getTo().copy();
XSSFClientAnchor destAnchor = new XSSFClientAnchor(from, to);
destAnchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
XSSFChart destChart = createChart(destAnchor);
destChart.getCTChartSpace().set(srcChart.getCTChartSpace().copy());
destChart.getCTChart().set(srcChart.getCTChart().copy());
return destChart;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
/*
* Saved drawings must have the following namespaces set: <xdr:wsDr
* xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
* xmlns:xdr=
* "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing">
*/
xmlOptions
.setSaveSyntheticDocumentElement(new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr"));
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
drawing.save(out, xmlOptions);
out.close();
}
代码示例来源:origin: org.apache.poi/poi-ooxml
clonedDg.getCTDrawing().set(dg.getCTDrawing());
List<RelationPart> srcRels = srcSheet.createDrawingPatriarch().getRelationParts();
for (RelationPart rp : srcRels) {
addRelation(rp, clonedDg);
代码示例来源:origin: stackoverflow.com
XSSFShapeGroup group = draw.createGroup(draw.createAnchor(0, 0, 0, 0, colStart, 11, colStart + 6, 11+7));
group.setCoordinates(colStart, 11, colStart + 6, 11+7);
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public Comment createCellComment(ClientAnchor anchor) {
return _drawing.createCellComment(anchor);
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Creates a picture.
*
* @param anchor the client anchor describes how this picture is attached to the sheet.
* @param pictureIndex the index of the picture in the workbook collection of pictures,
* {@link XSSFWorkbook#getAllPictures()} .
* @return the newly created picture shape.
*/
public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) {
PackageRelationship rel = getDrawing().addPictureReference(pictureIndex);
CTPicture ctShape = ctGroup.addNewPic();
ctShape.set(XSSFPicture.prototype());
XSSFPicture shape = new XSSFPicture(getDrawing(), ctShape);
shape.parent = this;
shape.anchor = anchor;
shape.setPictureReference(rel);
return shape;
}
代码示例来源:origin: stackoverflow.com
//Call the partiarch to start drawing
XSSFDrawing drawing = ((XSSFSheet)currentSheet).createDrawingPatriarch();
//Create CTMarket for anchor
CTMarker chartEndCoords = CTMarker.Factory.newInstance();
//The coordinates are set in columns and rows, not pixels.
chartEndCoords.setCol(column);
//Set Column offset
chartEndCoords.setColOff(0);
chartEndCoords.setRow(row);
chartEndCoords.setRowOff(0);
//drawing.getCTDrawing().getTwoCellAnchorArray(0).setFrom(chartStartCoords);
drawing.getCTDrawing().getTwoCellAnchorArray(0).setTo(chartEndCoords);
/*
This line of code allows to resize the chart:
The Patriarch is what allows to get control over the drawings, since
a chart is considered a graph in xlsx you can access it with getCTDrawing.
Each graph is stored in the tag getTwoCellAnchorArray, where the array position
is the chart you have; for example getTwoCellAnchorArray(3) would refer to the
forth graph within the sheet.
Each getTwoCellAnchorArray has several properties as FROM and TO, which define
where the existing graph starts and ends.
*/
内容来源于网络,如有侵权,请联系作者删除!