(4) How to manipulate Excel files with Apache POI-----found POI-3.12 a regression bug

Source: Internet
Author: User

Finally hope that the final version of POI-3.12 can come out, this month eventually out, so first plugging for fast, from this address (https://poi.apache.org/download.html#POI-3.12) Download the latest POI-3.12 version.

Then, ran a program, on an Excel first cell (A0) plus annotations (comments), unfortunately, it throws the following error,

Exception in thread "main" java.lang.IllegalArgumentException:Multiple cell comments in one cell is not allowed, cell:a 1
At Org.apache.poi.xssf.usermodel.XSSFDrawing.createCellComment (xssfdrawing.java:318)
At Org.apache.poi.xssf.usermodel.XSSFDrawing.createCellComment (xssfdrawing.java:52)
At Com.tibco.poi.xssf.CellComments.main (cellcomments.java:49)


Then the same code, in the POI-3.10 version of the test, did not find any problems, so, it is a regression problem. Here is the code to reproduce the problem (using the code of my last article, just a little bit of code on line 33rd, http://blog.csdn.net/chancein007/article/details/46238217, Add annotations (comment) to the A1 cell). So how do we deal with this kind of regression problem? At this point, we can create a new bug for the Apache POI Bugzilla system, so that after they see it, maybe the next version will help us out. For details on how to open Bugzilla, see the next section.

Import Org.apache.poi.ss.usermodel.*;import Org.apache.poi.xssf.usermodel.xssfsheet;import Org.apache.poi.xssf.usermodel.xssfworkbook;import Java.io.ioexception;import java.io.FileOutputStream;/** * Demonstrates how to work with Excel cell comments.  * <p> * Excel comment is a kind of a text shape, * So inserting a comment are very similar to placing a text box in a Worksheet * </p> * * @author Yegor Kozlov */public class Cellcomments {public static void main (string[] args) t    Hrows IOException {//1. Create a Workbook object Xssfworkbook wb = new Xssfworkbook ();        2. Get a POI tool class Creationhelper factory = Wb.getcreationhelper (); 3.                Create a worksheet Xssfsheet sheet = Wb.createsheet ();        4. Get an object for Drawing Drawing = Sheet.createdrawingpatriarch (); 5.        Clientanchor is an object attached to the worksheet, which is fixed in the upper-left and lower-right corners of a cell.                Clientanchor anchor = Factory.createclientanchor (); 6. Create a cell (A0 cell) Cell cell0 = Sheet.createrow (0). CreateCell (0); 6.1.        Set the value for this cell cell0.setcellvalue ("Test"); 6.2.        Add annotations to this cell Comment comment0 = drawing.createcellcomment (anchor);        Richtextstring STR0 = factory.createrichtextstring ("Hello, world!");        Comment0.setstring (STR0);        Comment0.setauthor ("Apache POI");                Cell0.setcellcomment (COMMENT0); 7.        Create a cell (4F cell) Cell cell1 = Sheet.createrow (3). Createcell (5); 7.1.        Set the value for this cell cell1.setcellvalue ("F4"); 7.2.        Add annotations to this cell Comment comment1 = drawing.createcellcomment (anchor);        Richtextstring str1 = factory.createrichtextstring ("Hello, world!");        Comment1.setstring (STR1);        Comment1.setauthor ("Apache POI");        Cell1.setcellcomment (COMMENT1); 8.        Create a cell (4F cell) Cell cell2 = Sheet.createrow (2). Createcell (2);        Cell2.setcellvalue ("C3");        Comment Comment2 = drawing.createcellcomment (anchor); Richtextstring str2 = factory.createrichtextstring ("XSSF can set cell comments "); 9.        Set fonts for annotations font font = Wb.createfont ();        Font.setfontname ("Arial");        Font.setfontheightinpoints ((short) 14);        Font.setboldweight (Font.boldweight_bold);        Font.setcolor (IndexedColors.RED.getIndex ());        Str2.applyfont (font);        Comment2.setstring (STR2);        Comment2.setauthor ("Apache POI");        Comment2.setcolumn (2);        Comment2.setrow (2); 10.        Save As Excel file String fname = "comments.xlsx";        FileOutputStream out = new FileOutputStream (fname);        Wb.write (out);    Out.close (); }}




(4) How to manipulate Excel files with Apache POI-----found POI-3.12 a regression bug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.