Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we programmatically sort entries alphabetically in an excel sheet based on a certain column value

I have programmatically created an excel sheet in which there are many rows of entries using Apache POI.

Is it possible to programmatically sort the entries in an excel sheet (alphabetically) based on the value in a certain column, by using any APIs? I need to implement this in an android app. So far I have observed that we can do this manually in the excel sheet, but is it possible to do this programmatically?

Any suggestions with regard to any .jar file (not necessarily Apache POI) will be appreciated.

like image 673
SoulRayder Avatar asked Nov 11 '22 12:11

SoulRayder


1 Answers

Apache POI does not have a convenient way of inserting rows: basically if you insert a row you have to shift down all following rows by 1. This is computationally expensive and tedious.

I therefore usually create a list of old rows, sort the rows using a custom comparator (which would then compare your certain column) and then create a new sheet where I would write the newly sorted list of rows in the right order. Then I would delete the old sheet and rename the new one using the old sheet's name.

like image 76
Volokh Avatar answered Nov 14 '22 22:11

Volokh