0

I'm trying to output a csv file with the following format

="1000402999574",6456,="21, Street, Town"

The reason is that I need the long number to be loaded as text in excel so it isn't converted to a scientific notation.

What are the settings required output a file in this format? It is the prefixed =" that is causing me the problem here

muttonUp
  • 6,351
  • 2
  • 42
  • 54
  • A CSV file is just a text file with an optional header. The only thing that really matters in CSV is the comma `,`. The rest is up to how your application interprets it. The first value is valid `="1000402999574"`, but If you don't want `="21` and ` Street` and ` Town` as separate values, then don't use a comma to separate them, use another character, for example, a semi colon `;` – sorifiend Jun 30 '21 at 12:24
  • As for how to output it, why not just use a regular `PrintWriter` and simply use the print method `yourPrintWriter.println(yourStringOrLine);` – sorifiend Jun 30 '21 at 12:31
  • yes, I can skip commons-csv and just go straight to the Writer interface, but I wanted to see if/how it can be done via Apache-Commons-CSV as that has some nice features I want to make use of. – muttonUp Jun 30 '21 at 14:31
  • You can make use of the Apache CSV printer as shown here https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVPrinter.html specifically `CSVPrinter printer = new CSVPrinter(new FileWriter("csv.txt"), CSVFormat.EXCEL);` and `printer.printRecord("id", "userName", "firstName", "lastName", "birthday");` – sorifiend Jun 30 '21 at 20:17
  • Hi @sorifiend can I draw your attention to the last line of my question. – muttonUp Jul 24 '21 at 20:05

0 Answers0