I'm thinking that you should be able to reorder things using an XMLBeans 
cursor, and maybe a quicksort.

-----Original Message-----
From: pj.fanning [mailto:fannin...@yahoo.com] 
Sent: Tuesday, July 10, 2018 3:40 PM
To: dev@poi.apache.org
Subject: reordering xssf rows

I've been looking at
https://github.com/apache/poi/blob/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java#L344

The test fails with: java.lang.AssertionError: Row 3 (1-based) is not in 
ascending order; previously saw 5

After shifting the xssf rows as part of the test, the underlying CTRows are not 
reordered.

wb.getSheetAt(0).getCTWorksheet().getSheetData().getRowList()

When the workbook is output, the rows in the output are out of order.

XMLBeans doesn't seem to make it easy to fix this.
I've tried to empty the rows on SheetData and to recreate them but this orphans 
the existing CTRows and leads to errors if I try to read off the data from the 
old rows when trying to create new ones.

org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
        at
org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1258)
        at
org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl.getR(Unknown
Source)

It seems like the best solution to completely recreate the sheet by adding a 
new sheet, copying on all the items related to the initial sheet (with the rows 
shifted) and then removing the old sheet before then renaming the new sheet and 
putting in the right sheet order.

This does seem like a lot of work and there are risks that even this approach 
won't work.

Anyone have any thoughts on alternative solutions?



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-Dev-f2312866.html

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


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

Reply via email to