@Override public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) { return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2); }
/** * Creates a XSSFClientAnchor. Use this object to position drawing object in * a sheet * * @return a XSSFClientAnchor instance * @see org.apache.poi.ss.usermodel.Drawing */ @Override public XSSFClientAnchor createClientAnchor() { return new XSSFClientAnchor(); }
@Override public ClientAnchor getClientAnchor() { if(_vmlShape == null) { return null; } String position = _vmlShape.getClientDataArray(0).getAnchorArray(0); int[] pos = new int[8]; int i = 0; for (String s : position.split(",")) { pos[i++] = Integer.parseInt(s.trim()); } return new XSSFClientAnchor(pos[1]*EMU_PER_PIXEL, pos[3]*EMU_PER_PIXEL, pos[5]*EMU_PER_PIXEL, pos[7]*EMU_PER_PIXEL, pos[0], pos[2], pos[4], pos[6]); }
private XSSFAnchor getAnchorFromParent(XmlObject obj) { XSSFAnchor anchor = null; XmlObject parentXbean = null; XmlCursor cursor = obj.newCursor(); if (cursor.toParent()) { parentXbean = cursor.getObject(); } cursor.dispose(); if (parentXbean != null) { if (parentXbean instanceof CTTwoCellAnchor) { CTTwoCellAnchor ct = (CTTwoCellAnchor) parentXbean; anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo()); } else if (parentXbean instanceof CTOneCellAnchor) { CTOneCellAnchor ct = (CTOneCellAnchor) parentXbean; anchor = new XSSFClientAnchor(getSheet(), ct.getFrom(), ct.getExt()); } else if (parentXbean instanceof CTAbsoluteAnchor) { CTAbsoluteAnchor ct = (CTAbsoluteAnchor) parentXbean; anchor = new XSSFClientAnchor(getSheet(), ct.getPos(), ct.getExt()); } } return anchor; }
/** * 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; }
/** * Creates a XSSFClientAnchor. Use this object to position drawing object in * a sheet * * @return a XSSFClientAnchor instance * @see org.apache.poi.ss.usermodel.Drawing */ public XSSFClientAnchor createClientAnchor() { return new XSSFClientAnchor(); } }
/** * Creates a XSSFClientAnchor. Use this object to position drawing object in * a sheet * * @return a XSSFClientAnchor instance * @see org.apache.poi.ss.usermodel.Drawing */ @Override public XSSFClientAnchor createClientAnchor() { return new XSSFClientAnchor(); }
@Override public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) { return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2); }
public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) { return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2); }
@Override public ClientAnchor getClientAnchor() { if(_vmlShape == null) { return null; } String position = _vmlShape.getClientDataArray(0).getAnchorArray(0); int[] pos = new int[8]; int i = 0; for (String s : position.split(",")) { pos[i++] = Integer.parseInt(s.trim()); } return new XSSFClientAnchor(pos[1]*EMU_PER_PIXEL, pos[3]*EMU_PER_PIXEL, pos[5]*EMU_PER_PIXEL, pos[7]*EMU_PER_PIXEL, pos[0], pos[2], pos[4], pos[6]); }
/** * Creates a new comment for this sheet. You still * need to assign it to a cell though * * @deprecated since Nov 2009 this method is not compatible with the common SS interfaces, * use {@link org.apache.poi.xssf.usermodel.XSSFDrawing#createCellComment * (org.apache.poi.ss.usermodel.ClientAnchor)} instead */ @Deprecated public XSSFComment createComment() { return createDrawingPatriarch().createCellComment(new XSSFClientAnchor()); }
private XSSFAnchor getAnchorFromParent(XmlObject obj) { XSSFAnchor anchor = null; XmlObject parentXbean = null; XmlCursor cursor = obj.newCursor(); if (cursor.toParent()) { parentXbean = cursor.getObject(); } cursor.dispose(); if (parentXbean != null) { if (parentXbean instanceof CTTwoCellAnchor) { CTTwoCellAnchor ct = (CTTwoCellAnchor) parentXbean; anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo()); } else if (parentXbean instanceof CTOneCellAnchor) { CTOneCellAnchor ct = (CTOneCellAnchor) parentXbean; anchor = new XSSFClientAnchor(getSheet(), ct.getFrom(), ct.getExt()); } else if (parentXbean instanceof CTAbsoluteAnchor) { CTAbsoluteAnchor ct = (CTAbsoluteAnchor) parentXbean; anchor = new XSSFClientAnchor(getSheet(), ct.getPos(), ct.getExt()); } } return anchor; }
anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1);
if (includeComment && StringUtils.hasText(commentStr)) { Comment comment = this.sheet.createDrawingPatriarch().createCellComment( new XSSFClientAnchor(0, 0, 0, 0, (short) i, rownum - 1, (short) i, rownum - 1)); comment.setString(new XSSFRichTextString(commentStr)); cell.setCellComment(comment);
private void createHeader() { // Create header Row headerRow = sheet.createRow(rownum++); headerRow.setHeightInPoints(16); for (int i = 0; i < excelFieldDescriptions.size(); i++) { ExcelFieldDescription excelFieldDescription = excelFieldDescriptions.get(i); ExcelField excelField = excelFieldDescription.getExcelField(); Cell cell = headerRow.createCell(i); String t = excelField.title(); cell.setCellValue(t); cell.setCellStyle(getCellStyle(CellStyleType.HEADER)); String commentStr = excelField.comment(); if (includeComment && StringUtils.hasText(commentStr)) { Comment comment = this.sheet.createDrawingPatriarch().createCellComment( new XSSFClientAnchor(0, 0, 0, 0, (short) i, rownum - 1, (short) i, rownum - 1)); comment.setString(new XSSFRichTextString(commentStr)); cell.setCellComment(comment); } if (sheet instanceof SXSSFSheet) { ((SXSSFSheet) sheet).trackAllColumnsForAutoSizing(); } sheet.autoSizeColumn(i); int colWidth = sheet.getColumnWidth(i) * 2; sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); } }
/** * 功能:拷贝comment * @param targetCell * @param sourceCell * @param targetPatriarch */ public static void copyComment(SXSSFCell targetCell,XSSFCell sourceCell,Drawing targetPatriarch)throws Exception{ if(targetCell == null || sourceCell == null || targetPatriarch == null){ throw new IllegalArgumentException("调用PoiUtil.copyCommentr()方法时,targetCell、sourceCell、targetPatriarch都不能为空,故抛出该异常!"); } //处理单元格注释 Comment comment = sourceCell.getCellComment(); if(comment != null){ Comment newComment = targetPatriarch.createCellComment(new XSSFClientAnchor()); newComment.setAuthor(comment.getAuthor()); newComment.setColumn(comment.getColumn()); newComment.setRow(comment.getRow()); newComment.setString(comment.getString()); newComment.setVisible(comment.isVisible()); targetCell.setCellComment(newComment); } }
row.getRowNum() + 1); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1);
new XSSFClientAnchor(0, 0, 0, 0, i, 0, i, 0)); XSSFRichTextString xssfRichTextString = new XSSFRichTextString( property.getComment());
/** * 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; }
/** * 图片类型的Cell */ public void createImageCell(Cell cell, double height, String imagePath, byte[] data) throws Exception { if (height > cell.getRow().getHeight()) { cell.getRow().setHeight((short) height); } ClientAnchor anchor; if (type.equals(ExcelType.HSSF)) { anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); } if (StringUtils.isNotEmpty(imagePath)) { data = ImageCache.getImage(imagePath); } if (data != null) { PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture(anchor, cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); } }