org.apache.poi.ss.usermodel.Sheet.createDrawingPatriarch()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(393)

本文整理了Java中org.apache.poi.ss.usermodel.Sheet.createDrawingPatriarch()方法的一些代码示例,展示了Sheet.createDrawingPatriarch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sheet.createDrawingPatriarch()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Sheet
类名称:Sheet
方法名:createDrawingPatriarch

Sheet.createDrawingPatriarch介绍

[英]Creates the top-level drawing patriarch.

This may then be used to add graphics or charts.

Note that this will normally have the effect of removing any existing drawings on this sheet.
[中]创建顶级图形父权制。
然后可以使用它添加图形或图表。
请注意,这通常会导致删除此图纸上的任何现有图纸。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

private Comment createCellComment( String author, String comment ) {
 // comments only supported for XLSX
 if ( data.sheet instanceof XSSFSheet ) {
  CreationHelper factory = data.wb.getCreationHelper();
  Drawing drawing = data.sheet.createDrawingPatriarch();
  ClientAnchor anchor = factory.createClientAnchor();
  Comment cmt = drawing.createCellComment( anchor );
  RichTextString str = factory.createRichTextString( comment );
  cmt.setString( str );
  cmt.setAuthor( author );
  return cmt;
 }
 return null;
}

代码示例来源:origin: youseries/ureport

Drawing<?> drawing=sheet.createDrawingPatriarch();
  List<Row> rows=page.getRows();
  for(Row r:rows){
Drawing<?> drawing=sheet.createDrawingPatriarch();
List<Row> rows=report.getRows();
int rowNumber=0;

代码示例来源:origin: youseries/ureport

Drawing<?> drawing=sheet.createDrawingPatriarch();
List<Row> rows=page.getRows();
for(int rowIndex=0;rowIndex<rows.size();rowIndex++){

代码示例来源:origin: youseries/ureport

int columnSize=columns.size();
Sheet sheet=createSheet(wb, paper, null);
Drawing<?> drawing=sheet.createDrawingPatriarch();
List<Row> rows=report.getRows();
int rowNumber=0;

代码示例来源:origin: pentaho/pentaho-reporting

public Drawing getDrawingPatriarch() {
 if ( patriarch == null ) {
  patriarch = getSheet().createDrawingPatriarch();
 }
 return patriarch;
}

代码示例来源:origin: cn.afterturn/easypoi-base

/**
 * 获取画布,没有就创建一个
 * @param sheet
 * @return
 */
public static Drawing getDrawingPatriarch(Sheet sheet){
  if(sheet.getDrawingPatriarch() == null){
    sheet.createDrawingPatriarch();
  }
  return sheet.getDrawingPatriarch();
}

代码示例来源:origin: org.jeecg/easypoi-base

/**
 * 构建图形对象
 * @param workbook
 * @param dataSourceSheet
 * @param tragetSheet
 * @param graph
 */
private static void buildExcelChart(Sheet dataSourceSheet,Sheet tragetSheet,ExcelGraph graph){
  Drawing drawing = tragetSheet.createDrawingPatriarch();
  ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 0, 15, 20);
  buildExcelChart(drawing, anchor, dataSourceSheet, graph);
}

代码示例来源:origin: org.jeecg/easypoi-base

/**
 * 构建多个图形对象
 * @param dataSourceSheet
 * @param tragetSheet
 * @param graphList
 */
private static void buildExcelChart(Sheet dataSourceSheet,Sheet tragetSheet,List<ExcelGraph> graphList){
  int len=graphList.size();
  if(len==1)
  {
    buildExcelChart(dataSourceSheet, tragetSheet, graphList.get(0));
  }
  else
  {
    int drawStart=0;
    int drawEnd=20;
    Drawing drawing = tragetSheet.createDrawingPatriarch();
    for(int i=0;i<len;i++){
      ExcelGraph graph=graphList.get(i);
      ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, drawStart, 15, drawEnd);
      buildExcelChart(drawing, anchor, dataSourceSheet, graph);
      drawStart=drawStart+drawEnd;
      drawEnd=drawEnd+drawEnd;
    }
  }
}

代码示例来源:origin: stackoverflow.com

Drawing drawing = sheet.createDrawingPatriarch();

代码示例来源:origin: stackoverflow.com

Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();

/* Here is the thing: the line will go from top left in cell (0,0) to down left 
of cell (0,1) */
HSSFClientAnchor anchor = new HSSFClientAnchor(
 0, 0, 0, 255, (short) 0, 0,(short) 1, 0);

HSSFSimpleShape shape = patriarch.createSimpleShape(anchor);
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
shape.setLineStyleColor(10, 10, 10);
shape.setFillColor(90, 10, 200);
shape.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT);
shape.setLineStyle(HSSFShape.LINESTYLE_SOLID);

// you don't even need the cell, but if you also want to write anything...
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Test");

代码示例来源:origin: com.sqlapp/sqlapp-core

public static void setComment(CreationHelper helper, Cell cell, String text){
  int dx1 = 200, dy1 = 100, dx2 = 200, dy2 = 100;
  int col1 = cell.getColumnIndex() + 1;
  int row1 = cell.getRowIndex();
  int col2 = col1 + 3;
  String[] args=text.split("\n");
  int row2 = row1 + args.length+1;
  Drawing<?> drawing = cell.getSheet().createDrawingPatriarch();
  ClientAnchor anchor = drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
  Comment comment = drawing.createCellComment(anchor);
  //comment.setAuthor(author);
  comment.setString(helper.createRichTextString(text));
  cell.setCellComment(comment);
}

代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web

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);
 }
}

代码示例来源:origin: GZWgssmart/zywork

/**
 * 在指定工作表的指定位置插入图片
 * @param sheet 工作表
 * @param imageInputStream 图片输入流
 * @param imageType 图片文件类型枚举,推荐使用png或jpg图片
 * @param beginRow 图片开始的行
 * @param beginCol 图片开始的列
 */
public void insertPicture(Sheet sheet, InputStream imageInputStream, MIMETypeEnum imageType,
             int beginRow, int beginCol) {
  Drawing drawing = sheet.createDrawingPatriarch();
  ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
  clientAnchor.setRow1(beginRow);
  clientAnchor.setCol1(beginCol);
  Picture picture = drawing.createPicture(clientAnchor,
      workbook.addPicture(ImageUtils.getImageData(imageInputStream, imageType), getImageType(imageType)));
  picture.resize();
}

代码示例来源:origin: GZWgssmart/zywork

/**
 * 在指定工作表的指定位置插入图片
 * @param sheet 工作表
 * @param imagePath 图片路径
 * @param beginRow 图片开始的行
 * @param beginCol 图片开始的列
 */
public void insertPicture(Sheet sheet, String imagePath,
             int beginRow, int beginCol) {
  Drawing drawing = sheet.createDrawingPatriarch();
  ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
  clientAnchor.setRow1(beginRow);
  clientAnchor.setCol1(beginCol);
  Picture picture = drawing.createPicture(clientAnchor,
      workbook.addPicture(ImageUtils.getImageData(imagePath), getImageType(imagePath)));
  picture.resize();
}

代码示例来源:origin: openl-tablets/openl-tablets

protected static void setCellComment(Cell cell, String message) {
  CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
  ClientAnchor anchor = factory.createClientAnchor();
  anchor.setCol1(cell.getColumnIndex());
  anchor.setCol2(cell.getColumnIndex() + 3);
  anchor.setRow1(cell.getRowIndex());
  anchor.setRow2(cell.getRowIndex() + 3);
  Comment comment = cell.getSheet().createDrawingPatriarch().createCellComment(anchor);
  comment.setString(factory.createRichTextString(message));
  comment.setAuthor("OpenL");
  // Assign the comment to the cell
  cell.setCellComment(comment);
}

代码示例来源:origin: org.jxls/jxls-poi

public static void setCellComment(Cell cell, String commentText, String commentAuthor, ClientAnchor anchor){
  Sheet sheet = cell.getSheet();
  Workbook wb = sheet.getWorkbook();
  Drawing drawing = sheet.createDrawingPatriarch();
  CreationHelper factory = wb.getCreationHelper();
  if( anchor == null ){
    anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex() + 1);
    anchor.setCol2(cell.getColumnIndex() + 3);
    anchor.setRow1(cell.getRowIndex());
    anchor.setRow2(cell.getRowIndex() + 2);
  }
  Comment comment = drawing.createCellComment(anchor);
  comment.setString(factory.createRichTextString(commentText));
  comment.setAuthor(commentAuthor != null ? commentAuthor : "");
  cell.setCellComment( comment );
}

代码示例来源:origin: org.jxls/jxls-poi

private void addImage(AreaRef areaRef, int imageIdx) {
  CreationHelper helper = workbook.getCreationHelper();
  Sheet sheet = workbook.getSheet(areaRef.getSheetName());
  if(sheet == null) {
    sheet = workbook.createSheet(areaRef.getSheetName());
  }
  Drawing drawing = sheet.createDrawingPatriarch();
  ClientAnchor anchor = helper.createClientAnchor();
  anchor.setCol1(areaRef.getFirstCellRef().getCol());
  anchor.setRow1(areaRef.getFirstCellRef().getRow());
  anchor.setCol2(areaRef.getLastCellRef().getCol());
  anchor.setRow2(areaRef.getLastCellRef().getRow());
  drawing.createPicture(anchor, imageIdx);
}

代码示例来源:origin: GZWgssmart/zywork

/**
 * 在指定工作表的指定位置插入图片
 * @param sheet 工作表
 * @param imagePath 图片路径
 * @param leftDX 图片在单元格中离左上角的x距离
 * @param topDY 图片在单元格中离左上角的y距离
 * @param widthDX 图片的宽度
 * @param heightDY 图片的高度
 * @param beginRow 图片开始的行
 * @param beginCol 图片开始的列
 * @param endRow 图片结束的行
 * @param endCol 图片结束的列
 */
public void insertPicture(Sheet sheet, String imagePath,
            int leftDX, int topDY, int widthDX ,int heightDY,
            int beginRow, int beginCol, int endRow, int endCol) {
  Drawing drawing = sheet.createDrawingPatriarch();
  ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
  clientAnchor.setDx1(leftDX);
  clientAnchor.setDy1(topDY);
  clientAnchor.setDx2(widthDX);
  clientAnchor.setDy2(heightDY);
  clientAnchor.setRow1(beginRow);
  clientAnchor.setCol1(beginCol);
  clientAnchor.setRow2(endRow);
  clientAnchor.setCol2(endCol);
  drawing.createPicture(clientAnchor,
      workbook.addPicture(ImageUtils.getImageData(imagePath), getImageType(imagePath)));
}

代码示例来源:origin: com.bitplan.simplegraph/com.bitplan.simplegraph.excel

/**
 * set the cellComment for the given cell to the given text see
 * https://stackoverflow.com/q/16099912/1497139
 * 
 * @param cell
 * @param text
 */
@SuppressWarnings("rawtypes")
public static void setComment(Cell cell, String text) {
 Drawing drawing = cell.getSheet().createDrawingPatriarch();
 CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
 ClientAnchor anchor = factory.createClientAnchor();
 anchor.setCol1(cell.getColumnIndex());
 anchor.setCol2(cell.getColumnIndex() + 1);
 anchor.setRow1(cell.getRowIndex());
 anchor.setRow2(cell.getRowIndex() + 3);
 Comment comment = drawing.createCellComment(anchor);
 RichTextString str = factory.createRichTextString(text);
 comment.setVisible(Boolean.TRUE);
 comment.setString(str);
 cell.setCellComment(comment);
}

代码示例来源:origin: Appendium/objectlabkit

public ExcelCell comment(String commentText) {
  CreationHelper factory = row().sheet().poiWorkbook().getCreationHelper();
  Cell cell = currentCell;
  ClientAnchor anchor = factory.createClientAnchor();
  anchor.setCol1(cell.getColumnIndex());
  anchor.setCol2(cell.getColumnIndex() + 25);
  anchor.setRow1(cell.getRowIndex());
  anchor.setRow2(cell.getRowIndex() + 6);
  anchor.setAnchorType(AnchorType.DONT_MOVE_DO_RESIZE);
  Drawing drawing = row().sheet().poiSheet().createDrawingPatriarch();
  Comment comment = drawing.createCellComment(anchor);
  comment.setString(factory.createRichTextString(commentText));
  cell.setCellComment(comment);
  return this;
}

相关文章

微信公众号

最新文章

更多