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

x33g5p2x  于2022-01-18 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(267)

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

Drawing.createCellComment介绍

[英]Creates a comment.
[中]创建注释。

代码示例

代码示例来源:origin: kiegroup/optaplanner

void nextMeetingAssignmentListCell(List<MeetingAssignment> meetingAssignmentList,
    Function<MeetingAssignment, String> stringFunction, List<String> filteredConstraintNames) {
  if (meetingAssignmentList == null) {
    meetingAssignmentList = Collections.emptyList();
  }
  HardMediumSoftScore score = meetingAssignmentList.stream()
      .map(indictmentMap::get).filter(Objects::nonNull)
      .flatMap(indictment -> indictment.getConstraintMatchSet().stream())
      // Filter out filtered constraints
      .filter(constraintMatch -> filteredConstraintNames == null
          || filteredConstraintNames.contains(constraintMatch.getConstraintName()))
      .map(constraintMatch -> (HardMediumSoftScore) constraintMatch.getScore())
      // Filter out positive constraints
      .filter(indictmentScore -> !(indictmentScore.getHardScore() >= 0 && indictmentScore.getSoftScore() >= 0))
      .reduce(Score::add).orElse(HardMediumSoftScore.ZERO);
  XSSFCell cell = getXSSFCellOfScore(score);
  if (!meetingAssignmentList.isEmpty()) {
    ClientAnchor anchor = creationHelper.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 4);
    anchor.setRow1(currentRow.getRowNum());
    anchor.setRow2(currentRow.getRowNum() + 4);
    Comment comment = currentDrawing.createCellComment(anchor);
    String commentString = getMeetingAssignmentListString(meetingAssignmentList);
    comment.setString(creationHelper.createRichTextString(commentString));
    cell.setCellComment(comment);
  }
  cell.setCellValue(meetingAssignmentList.stream().map(stringFunction).collect(joining("\n")));
  currentRow.setHeightInPoints(Math.max(currentRow.getHeightInPoints(), meetingAssignmentList.size() * currentSheet.getDefaultRowHeightInPoints()));
}

代码示例来源:origin: kiegroup/optaplanner

anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum() + 4);
Comment comment = currentDrawing.createCellComment(anchor);
StringBuilder commentString = new StringBuilder(talkList.size() * 200);
for (Talk talk : talkList) {

代码示例来源: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: stackoverflow.com

Drawing drawing_master = sheet_master.createDrawingPatriarch();
Comment comment_master = drawing_master.createCellComment(anchor);
comment_master.setString(row_slave_a.getCell(0).getCellComment().getString());
row_master_a.createCell(0).setCellComment(comment_master);

代码示例来源:origin: org.optaplanner/optaplanner-examples

anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum() + 4);
Comment comment = currentDrawing.createCellComment(anchor);
StringBuilder commentString = new StringBuilder(talkList.size() * 200);
for (Talk talk : talkList) {

代码示例来源:origin: org.optaplanner/optaplanner-examples

void nextMeetingAssignmentListCell(List<MeetingAssignment> meetingAssignmentList,
    Function<MeetingAssignment, String> stringFunction, List<String> filteredConstraintNames) {
  if (meetingAssignmentList == null) {
    meetingAssignmentList = Collections.emptyList();
  }
  HardMediumSoftScore score = meetingAssignmentList.stream()
      .map(indictmentMap::get).filter(Objects::nonNull)
      .flatMap(indictment -> indictment.getConstraintMatchSet().stream())
      // Filter out filtered constraints
      .filter(constraintMatch -> filteredConstraintNames == null
          || filteredConstraintNames.contains(constraintMatch.getConstraintName()))
      .map(constraintMatch -> (HardMediumSoftScore) constraintMatch.getScore())
      // Filter out positive constraints
      .filter(indictmentScore -> !(indictmentScore.getHardScore() >= 0 && indictmentScore.getSoftScore() >= 0))
      .reduce(Score::add).orElse(HardMediumSoftScore.ZERO);
  XSSFCell cell = getXSSFCellOfScore(score);
  if (!meetingAssignmentList.isEmpty()) {
    ClientAnchor anchor = creationHelper.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 4);
    anchor.setRow1(currentRow.getRowNum());
    anchor.setRow2(currentRow.getRowNum() + 4);
    Comment comment = currentDrawing.createCellComment(anchor);
    String commentString = getMeetingAssignmentListString(meetingAssignmentList);
    comment.setString(creationHelper.createRichTextString(commentString));
    cell.setCellComment(comment);
  }
  cell.setCellValue(meetingAssignmentList.stream().map(stringFunction).collect(joining("\n")));
  currentRow.setHeightInPoints(Math.max(currentRow.getHeightInPoints(), meetingAssignmentList.size() * currentSheet.getDefaultRowHeightInPoints()));
}

代码示例来源: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: com.github.javahaohao/utils

if (ss.length==2){
  cell.setCellValue(ss[0]);
  Comment comment = this.sheet.createDrawingPatriarch().createCellComment(
      new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
  comment.setString(new XSSFRichTextString(ss[1]));

代码示例来源: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: org.apache.poi/poi-examples

Comment comment1 = drawing.createCellComment(anchor);
RichTextString str1 = factory.createRichTextString("Hello, World!");
comment1.setString(str1);
cell2.setCellValue("C3");
Comment comment2 = drawing.createCellComment(anchor);
RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");

代码示例来源:origin: xiaour/SpringBootDemo

/**
 * 功能:拷贝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);
  }
}

代码示例来源:origin: ZuInnoTe/hadoopoffice

anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
  currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
  currentComment.setAuthor(this.howc.getCommentAuthor());

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

clientAnchor.setCol2(6);
clientAnchor.setRow2(5);
Comment comment1 = patr.createCellComment(clientAnchor);
clientAnchor.setCol2(6);
clientAnchor.setRow2(11);
Comment comment2 = patr.createCellComment(clientAnchor);

代码示例来源: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: ZuInnoTe/hadoopoffice

anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
  currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
  currentComment.setAuthor(this.howc.getCommentAuthor());

代码示例来源: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;
}

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

protected void setCellComment(Cell cell, String message) {
  Drawing drawing = cell.getSheet().createDrawingPatriarch();
  CreationHelper factory = cell.getSheet().getWorkbook()
      .getCreationHelper();
  // When the comment box is visible, have it show in a 1x3 space
  ClientAnchor anchor = factory.createClientAnchor();
  anchor.setCol1(cell.getColumnIndex());
  anchor.setCol2(cell.getColumnIndex() + 1);
  anchor.setRow1(cell.getRowIndex());
  anchor.setRow2(cell.getRowIndex() + 1);
  anchor.setDx1(100);
  anchor.setDx2(100);
  anchor.setDy1(100);
  anchor.setDy2(100);

  // Create the comment and set the text+author
  Comment comment = drawing.createCellComment(anchor);
  RichTextString str = factory.createRichTextString(message);
  comment.setString(str);
  comment.setAuthor("Apache POI");
  // Assign the comment to the cell
  cell.setCellComment(comment);
}

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

anchor.setRow1(newCell.getRow().getRowNum());
anchor.setRow2(newCell.getRow().getRowNum() + 3);
Comment comment = sheet.createDrawingPatriarch().createCellComment(anchor);
comment.setAuthor(xlxComment.getAuthor());
comment.setString(xlxComment.getString());

相关文章