how to write to csv with a leading zero?

前端 未结 6 1271
北海茫月
北海茫月 2020-12-21 11:47

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 so

相关标签:
6条回答
  • 2020-12-21 11:53

    Append tab to the number

    ex: "\t"+"01234"

    0 讨论(0)
  • 2020-12-21 11:54

    When one opens a CSV file in excel 2007, it opens the Text Import Wizard. In step 3, you can specify the column data format of the column to be 'Text'. Just select the appropriate column header in the 'Data preview' pane. Then select the 'Text' radio button in the 'Column data format' pane.

    0 讨论(0)
  • 2020-12-21 11:57

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

    0 讨论(0)
  • You should use:

    String.format("%08d", 13);
    
    0 讨论(0)
  • 2020-12-21 12:07

    Try:

    String.format("%08d", 13)
    

    Note the 0 in the format string, that tells Java to prefix the number with zeroes up to the length indicated in the field (8 in this case).

    0 讨论(0)
  • 2020-12-21 12:15

    Even better way is to print your number as ="0000000013"

    String value = "0000000013"; 
    printWriter.println("=\"" + value + "\"");
    
    0 讨论(0)
提交回复
热议问题