Bug 51850 - Error adding comments to sheet
Summary: Error adding comments to sheet
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-20 11:03 UTC by Alex Panayotopoulos
Modified: 2011-09-22 10:38 UTC (History)
0 users



Attachments
The problematic spreadsheet (11.50 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2011-09-20 11:03 UTC, Alex Panayotopoulos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Panayotopoulos 2011-09-20 11:03:57 UTC
Created attachment 27541 [details]
The problematic spreadsheet

I have a spreadsheet which has been created with Apache POI and edited in Excel. (See attached.) When I open it with POI and attempt to add a comment to the first sheet, I get the following error message:

	org.apache.poi.openxml4j.exceptions.InvalidOperationException: A part with the name '/xl/comments1.xml' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]

Tested against 3.8-beta4, with the following code:

    public static void bugtest() {
        FileInputStream inp = null;
        
        try {
            inp = new FileInputStream(new File(OUTPUT_FOLDER, "comments-notworking.xlsx"));
            Workbook wb = WorkbookFactory.create(inp);
            Sheet s = wb.getSheet("comments");
            Cell c = s.getRow(0).getCell(0);
            
            CreationHelper factory = wb.getCreationHelper();
            Drawing drawing = s.createDrawingPatriarch();
            
            ClientAnchor anchor = factory.createClientAnchor();
            anchor.setCol1(0);
            anchor.setCol2(4);
            anchor.setRow1(0);
            anchor.setRow2(1);
            
            Comment excelComment = drawing.createCellComment(anchor);
            excelComment.setString(factory.createRichTextString("I like this cell. It's my favourite."));
            excelComment.setAuthor("Bob T. Fish");
            
            c.setCellComment(excelComment);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            try { inp.close(); }
            catch (Exception e) {}
        }
    }
Comment 1 Nick Burch 2011-09-22 10:38:31 UTC
Fixed in r1174048.

We try to give the new comments part the same ID as the sheet has, but if someone has already claimed that name then we just take the next available one