supercsv

Java CSV parser with unescaped quotes [closed]

随声附和 提交于 2019-11-29 22:35:09
问题 I have a CSV file that has some quoting issues: "Albanese Confectionery","157137","ALBANESE BULK ASST. MINI WILD FRUIT WORMS 2" 4/5LB",9,90,0,0,0,.53,"21",50137,"3441851137","5 lb",1,4,4,$6.7,$6.7,$26.8 SuperCSV is choking on these fruit worms (pun intended). I know that the 2" should probably be 2"" , but it's not. LibreOffice actually parses this correctly (which surprises me). I was thinking of just writing my own little parser but other rows have commas inside the string: "Albanese

Validate every field in a single pass with SuperCSV

爷,独闯天下 提交于 2019-11-29 09:42:56
I'm trying to write a large number of rows (~2 million) from a database to a CSV file using SuperCSV. I need to perform validation on each cell as it is written, and the built-in CellProcessors do very nicely. I want to capture all the exceptions that are thrown by the CellProcessors so that I can go back to the source data and make changes. The problem is that when there are multiple errors in a single row (e.g. The first value is out of range, the second value is null but shouldn't be), only the first CellProcessor will execute, and so I'll only see one of the errors. I want to process the

Validate every field in a single pass with SuperCSV

旧街凉风 提交于 2019-11-28 03:20:19
问题 I'm trying to write a large number of rows (~2 million) from a database to a CSV file using SuperCSV. I need to perform validation on each cell as it is written, and the built-in CellProcessors do very nicely. I want to capture all the exceptions that are thrown by the CellProcessors so that I can go back to the source data and make changes. The problem is that when there are multiple errors in a single row (e.g. The first value is out of range, the second value is null but shouldn't be),

Java - Write hashmap to a csv file

感情迁移 提交于 2019-11-28 02:03:20
I have a hashmap with a String key and String value. It contains a large number of keys and their respective values. For example: key | value abc | aabbcc def | ddeeff I would like to write this hashmap to a csv file such that my csv file contains rows as below: abc,aabbcc def,ddeeff I tried the following example here using the supercsv library: http://javafascination.blogspot.com/2009/07/csv-write-using-java.html . However, in this example, you have to create a hashmap for each row that you want to add to your csv file. I have a large number of key value pairs which means that several

Using CsvBeanReader to read a CSV file with a variable number of columns

亡梦爱人 提交于 2019-11-27 16:05:10
So I'm working on parsing a .csv file. I took the advice of another thread somewhere on StackOverflow and downloaded SuperCSV. I finally got pretty much everything working, but now I've run into a bug that seems difficult to fix. The problem occurs because the last two columns of data may or may not be populated. Here is an example of a .csv file with the first row missing the last column, and the second row entirely complete: 2012:07:25,11:48:20,922,"uLog.exe","",Key pressed,1246,341,-1.00,-1.00,1.00,Shift 2012:07:25,11:48:21,094,"uLog.exe","",Key pressed,1246,341,-1.00,-1.00,1.00,b,Shift

OpenCSV - How to map selected columns to Java Bean regardless of order?

你离开我真会死。 提交于 2019-11-27 08:16:08
I have a CSV file with the following columns: id , fname , telephone , lname , address . I have a Person class with id , fname and lname data members. I want to map only these columns to Person object from a CSV file and discard telephone and address columns. How can I do this? The solution must scale as more columns are added in future. And should work regardless of column position. In an ideal solution user will only specify columns to read and it should just work. You can use HeaderColumnNameTranslateMappingStrategy . Lets assume your CSV has the following columns: Id , Fname , Telephone ,

Creating multiple sheets in CSV file

╄→гoц情女王★ 提交于 2019-11-27 07:44:17
问题 I am using superCSV to write data in csv format in my code. Its working absolutely fine and very efficiently , but now my requirement changed . I need to write multiple sheets in single xls file which is very time consuming task. So is there is any way in supercsv by which i can write multiple sheet data in single csv file and will send it to client, so that when client open this csv file in MS-Excel, he can see multiple sheets rather than me generating the excel file with with multiple

Unwanted double quotes in generated csv file

▼魔方 西西 提交于 2019-11-27 03:03:48
问题 I have created a CSV file using the Java code below: String csv = rs.getString("UPLOAD_FOLDER_PATH")+".csv"; CSVWriter writer = new CSVWriter(new FileWriter(csv)); String [] filevalues = new String[filevaluesarray.size()]; filevalues=filevaluesarray.toArray(filevalues); writer.writeNext(filevalues); writer.close(); I am getting the CSV file, but the content of the file has unwanted double quotes. Eg. "ABC","123","KDNJ" I don't get from where these double quotes are added. 回答1: This worked for

Java - Write hashmap to a csv file

假如想象 提交于 2019-11-26 22:09:23
问题 I have a hashmap with a String key and String value. It contains a large number of keys and their respective values. For example: key | value abc | aabbcc def | ddeeff I would like to write this hashmap to a csv file such that my csv file contains rows as below: abc,aabbcc def,ddeeff I tried the following example here using the supercsv library: http://javafascination.blogspot.com/2009/07/csv-write-using-java.html. However, in this example, you have to create a hashmap for each row that you

Using CsvBeanReader to read a CSV file with a variable number of columns

跟風遠走 提交于 2019-11-26 18:34:46
问题 So I'm working on parsing a .csv file. I took the advice of another thread somewhere on StackOverflow and downloaded SuperCSV. I finally got pretty much everything working, but now I've run into a bug that seems difficult to fix. The problem occurs because the last two columns of data may or may not be populated. Here is an example of a .csv file with the first row missing the last column, and the second row entirely complete: 2012:07:25,11:48:20,922,"uLog.exe","",Key pressed,1246,341,-1.00,