poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fermin Da Costa Gomez <dacostago...@dcgconsultancy.nl>
Subject Re: Sorting by column(s)
Date Mon, 18 Jan 2010 19:23:03 GMT
Thx for the extensive reply.

I have thought about using a collection but the effect on memory can be
quite detrimental ..
Esp since one never knows how big the files will be.

So i had already started work on an alternate solution:
- Export file to csv format
- Do a *nix sort on it (fastest there is, afaik)
- clear the workbook-sheet (or would overwriting the old entries be
cheaper?)
- Repopulate by means of file import and write the workbook back to disk (or
just use it outright)

OR (and this just popped into my head ;-) ) would the following be more
efficient and faster:
- Add a column to the sheet to be sorted that makes each row uniquely
identifiable
- Push the columns to be sorted on into a collection (incl the unique id
column)
- Sort the collection
- Use the collection as a 'view' for the sheet or create a new sheet and
fill it with links to the original rows (assuming this works?)
* If the collection becomes to large one could do the csv export/ import
thing as well (just with the required cols however.)

I know the 1st solution will work, even with 50G files. But would the second
solution be feasible as well, referring to the row links.

Tia,

Fermin DCG


On Mon, Jan 18, 2010 at 5:40 PM, MSB <markbrdsly@tiscali.co.uk> wrote:

>
> As far as I am aware, it is not possible to sort the data in columns using
> POI.
>
> Have you considered using Java's support for collections to help you
> overcome this problem - the Arrays.sort() method may be of some help and if
> not, it is always possible to create your own sorting algorithms. Then all
> you would need to do is write the data into one of the collections classes,
> sort that and then retrieve the data to populate the worksheet. Thinking
> about this further, the JTable class may be the way to go; I know that it
> is
> possible to sort this on columns and I can see that it should be possible
> to
> create a JTable, populate it with data, sort the model and then retrieve
> the
> sorted data to populate the worksheet. Sadly, it has been a long time since
> I used Java to create GUIs and so I cannot remember all of the details but
> I
> am confident it is possible, here is a good place to start
> http://www.java2s.com/Tutorial/Java/0240__Swing/1100__JTable-Sort.htm. You
> may not even need to use the complex JTable object but can simply use the
> model part of it's MCV design pattern, the
> javax.swing.table.DefaultTableModel class.
>
> Yours
>
> Mark B
>
>
> dcg wrote:
> >
> > Hi,
> >
> > How does one sort by one or more columns in POI?
> >
> > Undoubtfully this is a very basic (and simple?) question but for some
> > reason
> > i can't find any mention of it anywhere, nor am i able to locate a method
> > in
> > the API the suggests column-sorting.
> > I sincerely hope its due to the fact that i'm overlooking something
> > bacause
> > sorting a sheet seems quite basic.
> >
> > Any suggestions/ links as to how to sort columns would be much
> > appreciated.
> >
> > Tia,
> >
> > Fermin DCG
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Sorting-by-column%28s%29-tp27209292p27213160.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>


-- 
“The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.”
- George Bernard Shaw (1856 - 1950)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message