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";
            }
        }
        System.out.println(data);
        return data;
    }

Take a look at the TableExport add-on - http://vaadin.com/addon/tableexport

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 (http://csveed.org/comparison-matrix.html) 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: https://vaadin.com/directory#addon/tableexport:vaadin

thanks :slight_smile: