本文整理了Java中org.apache.poi.ss.usermodel.Cell.setCellComment()
方法的一些代码示例,展示了Cell.setCellComment()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.setCellComment()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:setCellComment
[英]Assign a comment to this cell
[中]为此单元格分配注释
代码示例来源:origin: pentaho/pentaho-kettle
String author = data.commentauthorfieldnrs[ fieldNr ] >= 0
? data.inputRowMeta.getValueMeta( data.commentauthorfieldnrs[ fieldNr ] ).getString( row[ data.commentauthorfieldnrs[ fieldNr ] ] ) : "Kettle PDI";
cell.setCellComment( createCellComment( author, comment ) );
代码示例来源:origin: tobyweston/simple-excel
private static void copyCellComment(Cell oldCell, Cell newCell) {
if (newCell.getCellComment() != null)
newCell.setCellComment(oldCell.getCellComment());
}
代码示例来源:origin: stackoverflow.com
Cell c = this.currentRow.createCell(thisCol);
c.setCellValue(formattedValue);
c.setCellComment(comment);
代码示例来源:origin: openl-tablets/openl-tablets
public void setCellComment(int col, int row, ICellComment comment) {
Comment poiComment = null;
Cell poiCell = PoiExcelHelper.getOrCreateCell(col, row, getSheet());
if (comment != null) {
poiComment = ((XlsCellComment) comment).getXlxComment();
}
poiCell.setCellComment(poiComment);
}
代码示例来源:origin: stackoverflow.com
public void setComment(String text, Cell cell) {
final Map<Sheet, HSSFPatriarch> drawingPatriarches = new HashMap<Sheet, HSSFPatriarch>();
CreationHelper createHelper = cell.getSheet().getWorkbook().getCreationHelper();
HSSFSheet sheet = (HSSFSheet) cell.getSheet();
HSSFPatriarch drawingPatriarch = drawingPatriarches.get(sheet);
if (drawingPatriarch == null) {
drawingPatriarch = sheet.createDrawingPatriarch();
drawingPatriarches.put(sheet, drawingPatriarch);
}
Comment comment = drawingPatriarch.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
comment.setString(createHelper.createRichTextString(text));
cell.setCellComment(comment);
}
代码示例来源:origin: zhangdaiscott/jeasypoi
private static void cloneCell(Cell cNew, Cell cOld) {
cNew.setCellComment(cOld.getCellComment());
cNew.setCellStyle(cOld.getCellStyle());
switch (cNew.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN: {
cNew.setCellValue(cOld.getBooleanCellValue());
break;
}
case Cell.CELL_TYPE_NUMERIC: {
cNew.setCellValue(cOld.getNumericCellValue());
break;
}
case Cell.CELL_TYPE_STRING: {
cNew.setCellValue(cOld.getStringCellValue());
break;
}
case Cell.CELL_TYPE_ERROR: {
cNew.setCellValue(cOld.getErrorCellValue());
break;
}
case Cell.CELL_TYPE_FORMULA: {
cNew.setCellFormula(cOld.getCellFormula());
break;
}
}
}
}
代码示例来源:origin: cn.afterturn/easypoi-base
private static void cloneCell(Cell cNew, Cell cOld) {
cNew.setCellComment(cOld.getCellComment());
cNew.setCellStyle(cOld.getCellStyle());
代码示例来源: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: org.jeecg/easypoi-base
private static void cloneCell(Cell cNew, Cell cOld) {
cNew.setCellComment(cOld.getCellComment());
cNew.setCellStyle(cOld.getCellStyle());
switch (cNew.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN: {
cNew.setCellValue(cOld.getBooleanCellValue());
break;
}
case Cell.CELL_TYPE_NUMERIC: {
cNew.setCellValue(cOld.getNumericCellValue());
break;
}
case Cell.CELL_TYPE_STRING: {
cNew.setCellValue(cOld.getStringCellValue());
break;
}
case Cell.CELL_TYPE_ERROR: {
cNew.setCellValue(cOld.getErrorCellValue());
break;
}
case Cell.CELL_TYPE_FORMULA: {
cNew.setCellFormula(cOld.getCellFormula());
break;
}
}
}
}
代码示例来源:origin: xiaolanglang/easypoi
private static void cloneCell(Cell cNew, Cell cOld) {
cNew.setCellComment(cOld.getCellComment());
cNew.setCellStyle(cOld.getCellStyle());
switch (cNew.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN: {
cNew.setCellValue(cOld.getBooleanCellValue());
break;
}
case Cell.CELL_TYPE_NUMERIC: {
cNew.setCellValue(cOld.getNumericCellValue());
break;
}
case Cell.CELL_TYPE_STRING: {
cNew.setCellValue(cOld.getStringCellValue());
break;
}
case Cell.CELL_TYPE_ERROR: {
cNew.setCellValue(cOld.getErrorCellValue());
break;
}
case Cell.CELL_TYPE_FORMULA: {
cNew.setCellFormula(cOld.getCellFormula());
break;
}
}
}
}
代码示例来源: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: hyberbin/J-Excel
public static void copyCell(Cell srcCell, Cell distCell){
distCell.setCellStyle(srcCell.getCellStyle());
if(srcCell.getCellComment() != null) {
distCell.setCellComment(srcCell.getCellComment());
}
int srcCellType = srcCell.getCellType();
distCell.setCellType(srcCellType);
if (srcCellType == Cell.CELL_TYPE_NUMERIC) {
if (DateUtil.isCellDateFormatted(srcCell)) {
distCell.setCellValue(srcCell.getDateCellValue());
} else {
distCell.setCellValue(srcCell.getNumericCellValue());
}
} else if (srcCellType == Cell.CELL_TYPE_STRING) {
distCell.setCellValue(srcCell.getRichStringCellValue());
} else if (srcCellType == Cell.CELL_TYPE_BLANK) {
//nothing
} else if (srcCellType == Cell.CELL_TYPE_BOOLEAN) {
distCell.setCellValue(srcCell.getBooleanCellValue());
} else if (srcCellType == Cell.CELL_TYPE_ERROR) {
distCell.setCellErrorValue(srcCell.getErrorCellValue());
} else if (srcCellType == Cell.CELL_TYPE_FORMULA) {
distCell.setCellFormula(srcCell.getCellFormula());
} else {
//nothing
}
}
代码示例来源:origin: org.apache.poi/poi-examples
comment1.setString(str1);
comment1.setAuthor("Apache POI");
cell1.setCellComment(comment1);
代码示例来源:origin: com.github.nic-luo/rober-office
distCell.setCellComment(srcCell.getCellComment());
代码示例来源:origin: com.gitee.zhaohuihua/zhh-tools
public static void copyCell(Cell src, Cell target, boolean copyValue) {
if (src == null || target == null) {
return;
}
// 复制样式
target.setCellStyle(src.getCellStyle());
// 单元格类型
int cellType = src.getCellType();
target.setCellType(cellType);
if (cellType == Cell.CELL_TYPE_FORMULA) { // 公式
target.setCellFormula(src.getCellFormula());
} else if (copyValue) { // 复制内容
if (cellType == Cell.CELL_TYPE_ERROR) { // 错误
target.setCellErrorValue(src.getErrorCellValue());
} else {
Object value = getCellValue(src);
setCellValue(target, value);
}
// 评论
Comment comment = src.getCellComment();
if (comment == null) {
target.removeCellComment();
} else {
target.setCellComment(comment);
}
}
}
代码示例来源: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: 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: 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: 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;
}
内容来源于网络,如有侵权,请联系作者删除!