I am trying to use the Apache CSV library to work with CSV files from another company. Sometimes the header line and other lines have trailing commas. The header also has a variable set of fields. If I use CSVParser to parse the header, it throws an exception because of the duplicate (empty) column headers created from the trailing commas. If I parse the header line manually, I am not sure how to supply the column names to the parser. It accepts an Enum, ResultSet artifacts or specific String values, but not a List, Collection or Iterable. Is there a solution that lets me use CSVParser and column titles?
-
1Stackoverflow is for when you encounter problems while attempting to do something, not for such broad questions. You need to show what code you've written to tackle the problem and where you've gotten stuck.Paul Ghiran– Paul Ghiran2017-09-06 14:47:15 +00:00Commented Sep 6, 2017 at 14:47
-
I respectfully disagree. I think the problem was more clearly described conceptually, but looking for a specific call on a specific class does not seem like a broad question.Chris94– Chris942017-09-06 15:05:46 +00:00Commented Sep 6, 2017 at 15:05
-
I think you should change your question title to be in a question form and actually more accurately describe your problem. For example, "How to use Apache CSV library with column titles?", would likely be much more better.tambre– tambre2017-09-06 15:53:45 +00:00Commented Sep 6, 2017 at 15:53
-
Okay, title updated.Chris94– Chris942017-09-06 18:47:39 +00:00Commented Sep 6, 2017 at 18:47
Add a comment
|
1 Answer
You need to set the below parameter to true.
withAllowMissingColumnNames(true)
API is here. And make sure you are using version 1.1 or greater. Looks like this was fixed as part of a bug
1 Comment
Chris94
I saw the discussion of that but then did not see this method. Maybe I somehow had the 1.0 javadoc. Anyway, looks like that did it.