How to set cell comments on Excel Sheet Using JExcel APIs.
Previous | Home | Next |
In this tutorial we will acquaint with how to set cell comments on Excel Sheet Using JExcel APIs.
For setting the comments in the cells of an excel sheet using the JExcel API, we have to import the jxl.write.WritableCellFeatures class. In this class we have different methods availble in which one is setComment(), which is used for settng the comment in a worksheet's cell.. The various methods available in the WritableCellFeatures class are,
void removeComment()
This method removes the comments which are set.
void removeDataValidation()
This method removes any data validation which is present in the sheet.
void setComment(String s)
This method sets the cell comment.
void setComment(String s, double width, double height)
This method sets the cell comment and sets the size of the text box in which the comment will be displayed.
void setDataValidationList(java.util.Collection c)
It set the list of items to validate for this cell.
void setDataValidationRange(int col1, int row1, int col2, int row2)
This method sets the list of items to validate for this cell in the form of a cell range.
void setDataValidationRange(java.lang.String namedRange)
This method sets the data validation based upon a named range.
void setNumberValidation(double val, jxl.biff.BaseCellFeatures.ValidationCondition c)
This method sets the numeric value against which to validate.
void setNumberValidation(double val1, double val2, jxl.biff.BaseCellFeatures.ValidationCondition c)
This method sets the numeric range against which to validate the data.
For writting the comments inside a cell we have use the setComment() method available in the jxl.write.WritableCellFeatures class. The following code snippet will demonstrate how can we set comments in a worksheet,
WritableWorkbook workbook=Workbook.createWorkbook(new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls"));
WritableSheet sheet=workbook.createSheet("mysheet", 0);
WritableCellFeatures wcff=new WritableCellFeatures(); // created an object of WritableCellFeatures class
wcff.setComment("This is a comment!!", 1, 2); // we have set a comment which spans to one row and two columns
Label lbl=new Label(0,0,"comment"); // created a label
lbl.setCellFeatures(wcff); // added the cell features to the sheet
sheet.addCell(lbl); // finally added the cell to sheet
Previous | Home | Next |