CSV file creation without exponential numbers
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:
- Open a Blank Workbook in Excel.
- Choose Data, Get External Data, Import Data. (Excel 2007 is Data, Get External Data, Data from Text)
- Browse to your .csv file and Select "Import".
- Import Wizard should appear.
- Page 1 Select "Delimited"
- Select the row which you want to start the import.
- click "Next"
- 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.
- click "Next"
- 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.
- 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
精彩评论