java - opening the csv with Excel with the leading zero without stripping -


i creating csv file contains data when opening excel ms leading zeros being stripped. should write in csv file prevent occuring?

part of code

for (int i=0; < rows.size(); i++) {     object[] row = (object[]) rows.get(i);     bufferedwriter.write(row[0]);        bufferedwriter.write(";" + row[1]);      bufferedwriter.write(";" + row[2]);      bufferedwriter.write(";" + row[3]);      bufferedwriter.write(";" + row[4]);                  if(row[4].startswith("0")){                //i want add here tp prevent happen.             }     bufferedwriter.write(";" + row[5]);      bufferedwriter.write(";" + row[6]);     try { bufferedwriter.write(";" + df.format(row[7])); }       catch (exception ex) { bufferedwriter.write(";0"); }     try { bufferedwriter.write(";" + df.format(double.parsedouble(row[8]))); }       catch (exception ex) { bufferedwriter.write(";0"); }     string text = (row[9] != null) ? row[9].replace(';', ',') : "";     bufferedwriter.write(";" + text);      bufferedwriter.writeline(";" + row[10]);  } 

this isn't full answer, don't think java problem, @ least not entirely. assuming write string data csv file contains leading zeroes want, when import data excel information should still there.

read this post number of methods how preserve leading zeroes when importing csv. may able simple formatting column in question fixed width text.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -