From Table to CSV

I need some advice to make a string contains every row of the table.
The string is used to write to a csv file. My doubt is the function “for”:

private String writeFileCsv() {
String data = “”;
if(!(table.getItemIds().isEmpty())) {
Container c = table.getContainerDataSource();
Object ids = c.getItemIds().toArray();
for(Object rowid : ids) {
Item item = c.getItem(rowid);

                for(int i = 0; ....... ; i++) {
                    data +=  ......... + " ";
                data += "\n";
        return data;

Take a look at the TableExport add-on -

If that doesn’t work for you, take a look at one of the Java CSV libraries out there, so you don’t have to reinvent the wheel. I like csveed. There’s a good matrix on the csveed site ( that lists a lot of the other libraries. I’ve used opencsv and Super CSV as well.

Hi Luca,

what about the TableExport-AddOn? Link:

thanks :slight_smile: