本文整理汇总了Java中org.apache.poi.ss.usermodel.Comment类的典型用法代码示例。如果您正苦于以下问题:Java Comment类的具体用法?Java Comment怎么用?Java Comment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Comment类属于org.apache.poi.ss.usermodel包,在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setComment
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* See the comment for the given cell
*
* @param cell
* the cell
* @param message
* the comment message
*/
public static void setComment(HSSFCell 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(1000);
anchor.setDy1(100);
anchor.setDy2(1000);
// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(message);
comment.setString(str);
comment.setAuthor("TURNUS");
// Assign the comment to the cell
cell.setCellComment(comment);
}
示例2: hasComments
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* シートにコメントが設定されているかを取得する。
*
* @param sheet シート
* @return 有:true/無:false
*/
private boolean hasComments( Sheet sheet) {
if ( sheet instanceof XSSFSheet) {
XSSFSheet xssfSheet = ( XSSFSheet) sheet;
return xssfSheet.hasComments();
} else if ( sheet instanceof HSSFSheet) {
Iterator<Row> rowIterator = sheet.iterator();
while ( rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.iterator();
while ( cellIterator.hasNext()) {
Cell cell = cellIterator.next();
Comment comment = cell.getCellComment();
if ( comment != null) {
return true;
}
}
}
}
return false;
}
示例3: createCellComment
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
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;
}
示例4: createCellComment
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
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;
}
示例5: getCommentTopic
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
public Topic getCommentTopic(Cell cell, TopicMap tm) throws TopicMapException {
Comment comment = cell.getCellComment();
if(comment != null) {
RichTextString rts = comment.getString();
String str = rts.getString();
String basename = str.replace('\n', ' ');
basename = basename.replace('\r', ' ');
basename = basename.replace('\t', ' ');
Topic topic=getOrCreateTopic(tm, EXCEL_COMMENT_SI_PREFIX+"/"+urlEncode(basename), basename);
topic.setData(getCommentTypeTopic(tm), tm.getTopic(XTMPSI.getLang(DEFAULT_LANG)), str);
topic.addType(getCommentTypeTopic(tm));
return topic;
}
return null;
}
示例6: getAndRemove
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* セルのコメントを取得する。その際に、コメントを削除する。
* @param cell
* @return コメントが設定されていない場合は、nullを返す。
*/
public static CellCommentStore getAndRemove(final Cell cell) {
ArgUtils.notNull(cell, "cell");
final Comment comment = cell.getCellComment();
if(comment == null) {
return null;
}
final CellCommentStore commentStore = get(comment);
cell.removeCellComment();
return commentStore;
}
示例7: get
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* セルのコメントを取得する。
* @param comment 元となるPOIのセルノコメント。
* @return
* @throws IllegalArgumentException comment is null.
*/
public static CellCommentStore get(final Comment comment) {
ArgUtils.notNull(comment, "comment");
final CellCommentStore dest = new CellCommentStore();
dest.column = comment.getColumn();
dest.row = comment.getRow();
dest.author = comment.getAuthor();
dest.text = TextStore.get(comment.getString());
dest.visible = comment.isVisible();
dest.anchor = AnchorStore.get(comment.getClientAnchor());
return dest;
}
示例8: writeHeader
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
protected void writeHeader(Sheet sheet, Drawing drawing, Row nameRow, Row labelRow, int i, ExcelColumn column, CellStyle boldStyle)
{
CreationHelper helper = sheet.getWorkbook().getCreationHelper();
// Notify the listeners
for (ExcelExportListener listener : listeners)
{
listener.preHeader(column);
}
nameRow.createCell(i).setCellValue(helper.createRichTextString(column.getAttributeName()));
Cell cell = labelRow.createCell(i);
cell.setCellValue(helper.createRichTextString(column.getDisplayLabel()));
if (column.isRequired() && boldStyle != null)
{
cell.setCellStyle(boldStyle);
}
if (column.getDescription() != null && column.getDescription().length() > 0)
{
ClientAnchor anchor = helper.createClientAnchor();
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(0);
anchor.setDy2(0);
anchor.setCol1(0);
anchor.setRow1(0);
anchor.setCol2(0);
anchor.setRow2(4);
Comment comment = drawing.createCellComment(anchor);
comment.setString(helper.createRichTextString(column.getDescription()));
cell.setCellComment(comment);
}
sheet.autoSizeColumn((short) i);
}
示例9: getComment
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
private String getComment() {
if (this.cell == null || this.cell.getCellComment() == null) {
return null;
}
Comment comment = this.cell.getCellComment();
String value = comment.getString() == null ? null : comment.getString().getString();
if (value != null) {
value = convertHtml(value);
}
return value;
}
示例10: initialize
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* 初始化函数
* @param title 表格标题,传“空值”,表示无标题
* @param headerList 表头列表
*/
private void initialize(String title, List<String> headerList) {
this.wb = new SXSSFWorkbook(500);
this.sheet = wb.createSheet("Export");
this.styles = createStyles(wb);
// Create title
if (StringUtils.isNotBlank(title)){
Row titleRow = sheet.createRow(rownum++);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title"));
titleCell.setCellValue(title);
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(),
titleRow.getRowNum(), titleRow.getRowNum(), headerList.size()-1));
}
// Create header
if (headerList == null){
throw new RuntimeException("headerList not null!");
}
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
for (int i = 0; i < headerList.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellStyle(styles.get("header"));
String[] ss = StringUtils.split(headerList.get(i), "**", 2);
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]));
cell.setCellComment(comment);
}else{
cell.setCellValue(headerList.get(i));
}
sheet.autoSizeColumn(i);
}
for (int i = 0; i < headerList.size(); i++) {
int colWidth = sheet.getColumnWidth(i)*2;
sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
}
log.debug("Initialize success.");
}
示例11: initialize
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* 初始化函数
* @param title 表格标题,传“空值”,表示无标题
* @param headerList 表头列表
*/
private void initialize(String title, List<String> headerList) {
this.wb = new SXSSFWorkbook(500);
this.sheet = wb.createSheet("Export");
this.styles = createStyles(wb);
// Create title
if (StringUtils.isNotBlank(title)){
Row titleRow = sheet.createRow(rownum++);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get("title"));
titleCell.setCellValue(title);
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(),
titleRow.getRowNum(), titleRow.getRowNum(), headerList.size()-1));
}
// Create header
if (headerList == null){
throw new RuntimeException("headerList not null!");
}
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
for (int i = 0; i < headerList.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellStyle(styles.get("header"));
String[] ss = StringUtils.split(headerList.get(i), "**", 2);
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]));
cell.setCellComment(comment);
}else{
cell.setCellValue(headerList.get(i));
}
sheet.autoSizeColumn(i);
}
for (int i = 0; i < headerList.size(); i++) {
int colWidth = sheet.getColumnWidth(i)*2;
sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
}
log.debug("Initialize success.");
}
示例12: getNext
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
@Override
public Object[] getNext() {
SpreadSheetCellDAO[] result=null;
// all sheets?
if (this.sheets==null) { // go on with all sheets
if (!nextAllSheets()) {
return result;
}
} else { // go on with specified sheets
if (!nextSpecificSheets()) {
return result;
}
}
// read row from the sheet currently to be processed
Sheet rSheet = this.currentWorkbook.getSheetAt(this.currentSheet);
Row rRow = rSheet.getRow(this.currentRow);
if (rRow==null) {
this.currentRow++;
return new SpreadSheetCellDAO[0]; // emtpy row
}
result = new SpreadSheetCellDAO[rRow.getLastCellNum()];
for (int i=0;i<rRow.getLastCellNum();i++) {
Cell currentCell=rRow.getCell(i);
if (currentCell==null) {
result[i]=null;
} else {
String formattedValue=useDataFormatter.formatCellValue(currentCell,this.formulaEvaluator);
String formula = "";
if (currentCell.getCellTypeEnum()==CellType.FORMULA) {
formula = currentCell.getCellFormula();
}
Comment currentCellComment = currentCell.getCellComment();
String comment = "";
if (currentCellComment!=null) {
comment = currentCellComment.getString().getString();
}
String address = currentCell.getAddress().toString();
String sheetName = currentCell.getSheet().getSheetName();
SpreadSheetCellDAO mySpreadSheetCellDAO = new SpreadSheetCellDAO(formattedValue,comment,formula,address,sheetName);
result[i]=mySpreadSheetCellDAO;
}
}
// increase rows
this.currentRow++;
return result;
}
示例13: write
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
/**
* Add a cell to the current Workbook
*
* @param newDAO cell to add. If it is already existing an exception will be thrown. Note that the sheet name is sanitized using org.apache.poi.ss.util.WorkbookUtil.createSafeSheetName. The Cell address needs to be in A1 format. Either formula or formattedValue must be not null.
*
*/
@Override
public void write(Object newDAO) throws OfficeWriterException {
SpreadSheetCellDAO sscd = checkSpreadSheetCellDAO(newDAO);
String safeSheetName=WorkbookUtil.createSafeSheetName(sscd.getSheetName());
Sheet currentSheet=this.currentWorkbook.getSheet(safeSheetName);
if (currentSheet==null) {// create sheet if it does not exist yet
currentSheet=this.currentWorkbook.createSheet(safeSheetName);
if (!(safeSheetName.equals(sscd.getSheetName()))) {
LOG.warn("Sheetname modified from \""+sscd.getSheetName()+"\" to \""+safeSheetName+"\" to correspond to Excel conventions.");
}
// create drawing anchor (needed for comments...)
this.mappedDrawings.put(safeSheetName,currentSheet.createDrawingPatriarch());
}
// check if cell exist
CellAddress currentCA = new CellAddress(sscd.getAddress());
Row currentRow = currentSheet.getRow(currentCA.getRow());
if (currentRow==null) { // row does not exist? => create it
currentRow=currentSheet.createRow(currentCA.getRow());
}
Cell currentCell = currentRow.getCell(currentCA.getColumn());
if ((currentCell!=null) && (this.hasTemplate==false)) { // cell already exists and no template loaded ? => throw exception
throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA);
}
// create cell if no template is loaded or cell not available in template
if ((this.hasTemplate==false) || (currentCell==null)) {
currentCell=currentRow.createCell(currentCA.getColumn());
}
// set the values accordingly
if (!("".equals(sscd.getFormula()))) { // if formula exists then use formula
currentCell.setCellFormula(sscd.getFormula());
} else {
// else use formattedValue
currentCell.setCellValue(sscd.getFormattedValue());
}
// set comment
if ((sscd.getComment()!=null) && (!("".equals(sscd.getComment())))) {
/** the following operations are necessary to create comments **/
/** Define size of the comment window **/
ClientAnchor anchor = this.currentWorkbook.getCreationHelper().createClientAnchor();
anchor.setCol1(currentCell.getColumnIndex());
anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth());
anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
/** create comment **/
Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
currentComment.setAuthor(this.howc.getCommentAuthor());
currentCell.setCellComment(currentComment);
}
}
示例14: write
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
@Override
public void write(Object newDAO) throws OfficeWriterException {
SpreadSheetCellDAO sscd = MSExcelWriter.checkSpreadSheetCellDAO(newDAO);
String safeSheetName=WorkbookUtil.createSafeSheetName(sscd.getSheetName());
SXSSFSheet currentSheet=this.currentWorkbook.getSheet(safeSheetName);
if (currentSheet==null) {// create sheet if it does not exist yet
currentSheet=this.currentWorkbook.createSheet(safeSheetName);
if (!(safeSheetName.equals(sscd.getSheetName()))) {
LOG.warn("Sheetname modified from \""+sscd.getSheetName()+"\" to \""+safeSheetName+"\" to correspond to Excel conventions.");
}
// create drawing anchor (needed for comments...)
this.mappedDrawings.put(safeSheetName,currentSheet.createDrawingPatriarch());
}
// check if cell exist
CellAddress currentCA = new CellAddress(sscd.getAddress());
SXSSFRow currentRow = currentSheet.getRow(currentCA.getRow());
if (currentRow==null) { // row does not exist? => create it
currentRow=currentSheet.createRow(currentCA.getRow());
}
SXSSFCell currentCell = currentRow.getCell(currentCA.getColumn());
if ((currentCell!=null)) { // cell already exists and no template loaded ? => throw exception
throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA);
}
// create cell if no template is loaded or cell not available in template
currentCell=currentRow.createCell(currentCA.getColumn());
// set the values accordingly
if (!("".equals(sscd.getFormula()))) { // if formula exists then use formula
currentCell.setCellFormula(sscd.getFormula());
} else {
// else use formattedValue
currentCell.setCellValue(sscd.getFormattedValue());
}
// set comment
if ((sscd.getComment()!=null) && (!("".equals(sscd.getComment())))) {
/** the following operations are necessary to create comments **/
/** Define size of the comment window **/
ClientAnchor anchor = this.currentWorkbook.getCreationHelper().createClientAnchor();
anchor.setCol1(currentCell.getColumnIndex());
anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth());
anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
/** create comment **/
Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
currentComment.setAuthor(this.howc.getCommentAuthor());
currentCell.setCellComment(currentComment);
}
}
示例15: getAttributeSource
import org.apache.poi.ss.usermodel.Comment; //导入依赖的package包/类
@Override
protected Comment getAttributeSource(PoiExcelColumnBean bean, Cell cell) {
return cell.getCellComment();
}