javastringcsvformatprintwriter

how to write to csv with a leading zero?


I wish to write to a CSV file some data. One of the column that I input the information is in the form of an integer with leading zeros, example: 0000000013.

For some reason, excel 'converts' it to 13, and I must have it with 10 digits (0000000013). Can anyone tell how this can be circumvented?

String value = "0000000013"; //I tried String.format("%8d", 13) doesn't work
printWriter.println(value);

Thanks!!!


Solution

  • Add a single quote, ', at the start of the line. This informs Excel to not treat the value as a number.