Android - Generate CSV file from table values

后端 未结 5 863
半阙折子戏
半阙折子戏 2020-12-01 04:47

I have a database containing one table, i want to generate CSV file with values of this table.

Actually, I want to email this CSV file as an attachment. I know about

5条回答
  •  攒了一身酷
    2020-12-01 05:21

    Adding to @Cocos2dx answer:

    When querying from db you may have null fields, in my case i use a Controller to fetch the data in an object list, but either if you don`t you should check for null or empty values and proper format them (or they can make your table look weird):

    String[] details = { 
            replaceNull(someObject.getId()),
            replaceNull(someObject.getName())
    };
    
    
    public static String replaceNull(String input) {
        return ((input == null || input.isEmpty()) ? " " : input);
    }
    
    writer.writeNext(details);
    

提交回复
热议问题