poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 49940] Sometimes writing twice to a .xlsx file throws org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
Date Thu, 26 Sep 2013 12:19:34 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=49940

--- Comment #19 from Dean Walker <dean.walker@friendslife.co.uk> ---
I've seen this behaviour in various places (I'm using POI 3.10 Beta 1).
This disconnection happens during the first save where new 'container' objects
are created.
For example:
        // Fonts
        CTFonts ctFonts = CTFonts.Factory.newInstance();
        ctFonts.setCount(fonts.size());
        CTFont[] ctfnt = new CTFont[fonts.size()];
        idx = 0;
        for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
        ctFonts.setFontArray(ctfnt);
        styleSheet.setFonts(ctFonts);

Here CTFonts is a container for a CTFont array.
If we reuse the existing container, the problem goes away, example:

        // Fonts
        CTFonts ctFonts = styleSheet.getFonts();
        if (ctFonts == null) {
            ctFonts = CTFonts.Factory.newInstance();
        }
        ctFonts.setCount(fonts.size());
        CTFont[] ctfnt = new CTFont[fonts.size()];
        idx = 0;
        for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
        ctFonts.setFontArray(ctfnt);
        styleSheet.setFonts(ctFonts);

This works for my use case where I read an existing spreadsheet, update cell
values only, and then save the modified spreadsheet. I've not tried the use
case where fonts (or other objects) are programatically modified or added or
deleted.
There are numerous places in StylesTable.writeTo() where I have applied this
same solution.
I also encountered the same problem with named ranges and applied the same
solution to XSSFWorkBook.saveNamedRanges().
There may be other places where the same symptom appears depending on the
features you use in your spreadsheet.
This solution is not ideal (it cures the symptom rather than the cause) but I
hope this information will help resolve this bug.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message