import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFClientAnchor; import org.apache.poi.hssf.usermodel.HSSFComment; import org.apache.poi.hssf.usermodel.HSSFPatriarch; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import excel.ExcelHelper; //This test file has only one comment for three cells and the output is comment in only one cell //this happens even after writing in ByteArrayOutputStream and then reading from ByteArrayInputStream public class Test { public static void main(String[] args) throws IOException { HSSFWorkbook wb=new HSSFWorkbook(); HSSFSheet finalsheet=wb.createSheet(); HSSFCell cell1=finalsheet.createRow(0).createCell((short) 5); HSSFCell cell2=finalsheet.createRow(0).createCell((short) 6); HSSFCell cell3=finalsheet.createRow(1).createCell((short) 6); HSSFPatriarch patr = finalsheet.createDrawingPatriarch(); HSSFComment comment1 = patr.createComment(new HSSFClientAnchor(0, 100, 0, 0, (short)4, 2, (short) 6, 5)); comment1.setString(new HSSFRichTextString("help me")); comment1.setAuthor("SUMIT"); cell1.setCellComment(comment1); cell2.setCellComment(comment1); cell3.setCellComment(comment1); ByteArrayOutputStream out= new ByteArrayOutputStream(); wb.write(out); out.close(); HSSFWorkbook wbNew=new HSSFWorkbook(); wbNew = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); FileOutputStream out1 = new FileOutputStream("workbook3.xls"); wbNew.write(out1); out1.close(); System.out.println("end of test"); } }