Donate SIGN UP

Excel CSV files

Avatar Image
R1Geezer | 16:03 Fri 04th Mar 2011 | Technology
14 Answers
Here's what I'd like to do. I have a CSV file that is generated by another program, the problem is that when I open it in excel, Excel applies it's formatting based on what it thinks the data is, eg I have text fields that can also be numbers but I want them to be text and retain leading zeroes etc but excell is determined they are numeric and strips off the leading zeroes. Is there some sort of inbedded command I can use to tell it what type each colum is for example? The result must open correctly without any need to fancy importing etc as the target audience are IT iIliterate. thanks
Gravatar

Answers

1 to 14 of 14rss feed

Best Answer

No best answer has yet been selected by R1Geezer. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
I don't think there is anything easy. You need to use the Data | Import function to open the file. You get the option at one stage to select the type of data for each column. If you set this to 'text' leading zeroes will be retained.
In XL 2003 that is Data | Import External Data | Import Data
Could you not click the top of each column, and change the cell format to text/date/number/whatever. If this works, save as in Excel format and test that it re-opens OK. (Unless you mean the users get the CSV and need to open it themselves, in which case: don't know!)
Can you do a global edit in a text editor first ? Maybe find numbers somehow, and put an apostrophe in front of each ?
R1G

What you suggest is probably possible but sounds more complicated than learning how Data Import works.
Question Author
I can do all the things you suggest but this has to be idiot proof so it should just open and be correct. I am well aware of the import manipulations etc but what I really want is some way of telling excel, in the data, to leave it alone. Eg I can put double quotes around text and that works I can even imbed commas inside quotes but when I put quotes around a number it ignores them and interprets it as numeric eg I have one field like this "000123" and it becomes 123 in general format.
If the CSV is for Excel use only there is a trick which works but other apps would treat as corrupted data... place an = sign before the number in quotes thus:

data1,data2,="000001",data4,data5
Thanks for that tip ABerrant, I have tested that and it works OK in XL 2003.
Question Author
ABerrant, pure genius, you get life time membership of the Loyal order the Geezer club, many thanks! It's only going to excel so that's perfect!
R1G

Glad that ABe has fixed it for you but I am still unsure how you intend to make this feature appear in the CSV file.
Question Author
Spoc, I just generate the numbers with leading 0's and then wrap the quotes and = sign round, when the file is openned the leading 0's are still there, eg ="000123" gets put in it's cell as 000123, perfect, where as before I was getting 123 without the leading 0's and annoyingly it was left justified. The CSV file is generated from a database and then uploaded via email and sent to the users who should just be able to open it and it will look right.

ABerrant are there any other "magic" characters that do things when loaded from a CSV?
Question Author
sorry the above was for scotman.
R1G

Fair enough if you can arrange for the = & "" to be there automatically. I am keeping an eye on this for ABerrant to supply more tips too.
Question Author
Yes I can generate anything I like into the CSV so no problem, works a treat now!

1 to 14 of 14rss feed

Do you know the answer?

Excel CSV files

Answer Question >>

Related Questions

Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.