How to set comments for 3 cells using apache poi?

For once you've asked a question which had me trying out the code for a while.

Up vote 0 down vote favorite 1 share g+ share fb share tw.

I want to set comments for 3 excel cells using apache poi. This is my source code... import java.io. ; import org.apache.poi.hssf.usermodel.

; import org.apache.poi.hssf.util. HSSFColor; public class CellComments { public static void main(String args) throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb. CreateSheet("Cell comments in POI HSSF"); HSSFPatriarch patr = sheet.

CreateDrawingPatriarch(); HSSFCell cell1 = sheet. CreateRow(3). CreateCell((short)1); cell1.

SetCellValue(new HSSFRichTextString(" World")); //anchor defines size and position of the comment in worksheet HSSFComment comment1 = patr. CreateComment(new HSSFClientAnchor(100, 100, 100, 100, (short)1, 1, (short) 6, 5)); comment1. SetString(new HSSFRichTextString("FirstComments")); cell1.

SetCellComment(comment1); System.out. Println("Cell comments: "+cell1.getCellComment().getString()); patr = sheet. CreateDrawingPatriarch(); comment1 = patr.

CreateComment(new HSSFClientAnchor(100, 100, 100, 100, (short)1, 1, (short) 6, 5)); //HSSFComment comment2=patr. CreateComment(new HSSFClientAnchor(100, 100, 100, 100, (short)1, 1, (short) 6, 5)); HSSFCell cell2 = sheet. CreateRow(6).

CreateCell((short)1); cell2. SetCellValue(36.6); comment1. SetString(new HSSFRichTextString("second commetns")); cell2.

SetCellComment(comment1); System.out. Println("Cell comments: "+cell2.getCellComment().getString()); patr = sheet. CreateDrawingPatriarch(); comment1 = patr.

CreateComment(new HSSFClientAnchor(100, 100, 100, 100, (short)1, 1, (short) 6, 5)); //HSSFComment comment3=patr. CreateComment(new HSSFClientAnchor(100, 100, 100, 100, (short)1, 1, (short) 6, 5)); cell2 = sheet. CreateRow(10).

CreateCell((short)1); cell2. SetCellValue(150); comment1. SetString(new HSSFRichTextString("Third commetns")); cell2.

SetCellComment(comment1); System.out. Println("Cell comments: "+cell2.getCellComment().getString()); FileOutputStream out = new FileOutputStream("C:/Documents and Settings/saravanan/Desktop/cellcomments. Xls"); wb.

Write(out); out.close(); } } while run the program, comments set only for last cell. But I printed the comments for the first two cells it was printed fine. But not shown in the excel sheet.

Anybody help me... thanks a lot to all Saravanan java apache-poi link|improve this question edited Oct 6 '10 at 8:19JoseK12k41030 asked Oct 4 '10 at 13:43Saravanan1,241624 98% accept rate.

For once you've asked a question which had me trying out the code for a while. Your problem is this line appears 3 times, once before each comment. Patr = sheet.

CreateDrawingPatriarch(); From the docs for this method, Creates the top-level drawing patriarch. This will have the effect of removing any existing drawings on this sheet. So whats happening is that your earlier comments are getting removed each time you create the DrawingPatriarch.

So do this only once, before comment1. The other 2 times, remove or comment out this line.

Thanks jose.... – Saravanan Oct 6 '10 at 9:37 may I know your mailid....this is mine...saravanan. Palanisami@gmail.com – Saravanan Oct 6 '10 at 9:39 @Saravanan: no private tuitions on offer here. Ask a proper question, you will get a reply from the community.

See this URL for how to ask good questions. Www.tinyurl.com/so-hints – JoseK Oct 7 '10 at 5:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions