开发者

CSV file creation without exponential numbers

开发者 https://www.devze.com 2023-01-05 22:24 出处:网络
How do you get around the exponential conversion that takes place when inserting a value into a csv file.I have a process that creates a csv file and then starts entering rows into it.One of those fie

How do you get around the exponential conversion that takes place when inserting a value into a csv file. I have a process that creates a csv file and then starts entering rows into it. One of those fields inside a row inserts a value similar to this:

123,45,45,466,6656,23423,2455,234,2454

These are just a string of id's i need to preserve on the csv file in order to import them into another program that expects a comma separated number of values in this field.

Of course when i open excel and look at this csv it gives me something like this: 123,45,45,466,6656,000,000,000,000

so those last few values mean nothing开发者_Go百科 to the import process and it fails.

My question is how do i write to a csv file and get around my values being converted to exponential numbers as well as preserving the comma separated number values like above?

Thanks in advance Billy


Put quotes around them

"123","45","45","466","6656","23423","2455","234","2454"


In order to get around this issue i used the following steps in MS Excel 2007:

  1. Open a Blank Workbook in Excel.
  2. Choose Data, Get External Data, Import Data. (Excel 2007 is Data, Get External Data, Data from Text)
  3. Browse to your .csv file and Select "Import".
  4. Import Wizard should appear.
  5. Page 1 Select "Delimited"
  6. Select the row which you want to start the import.
  7. click "Next"
  8. In the Delimiters, select "comma" and/or other delimiters you are using. Note: The bottom half of the window will preview the way the data is to be imported.
  9. click "Next"
  10. highlight each column of your data in the window below. For each column you can specify "General", "Text", "Data", or "do not import column" using the radio buttons in the top left of the Wizard box. I used the "Text" option. This is an optional step.
  11. Click Finish.


place the value in single quotes while using data

Eg:

String[] abc = {"0123455677888", "154758768969", "abcsdhfsdj", ""abcsdhfsdj3725423", "62343664268abcsdhfsdj"};

CSVWriter csvWriter = new CSVWriter(String fileName);

//csvWriter.writeNext(String[] stringArray)

csvWriter.writeNext(" \' "+abc[0]+" \' ", " \' "+abc[1]+" \' ", abc[2], abc[3], abc[4]);

Try this It will store the data perfectly

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号