View Full Version : Excel corruption of .csv file data

22nd November 2015, 15:17
I've become aware of the limitations of opening .csv data files into Excel 2007 (earlier versions have the same issue). Various changes are made to the data as the file is opened, including at least the following:
* Fields that appear to be numeric and have leading or trailing zeroes have the leading/trailing zeroes removed
* Values that Excel thinks match a date such as 5-10 get assigned a data type of date. Reformatting the field's data type to text gives a crazy value such as 40308 (probably the number of days from 1/1/1970 to the date 5/10 in the current year)

Saving changes to the original .csv file causes permanent data loss as the above changes are saved back to the file (What were they thinking?!).

This issue can be worked around by using the Data -> Get External Data From Text tool, but I deal with .csv files so frequently that I want an easier way of getting my data opened without corruption. I came up with the below set of actions:

When right clicking on a .csv file in Windows Explorer, a context menu appears with various options. It would be useful to have an option “Open without corruption using Excel” or similar, which does the following:

1. Opens Excel
2. Creates a blank spreadsheet
3. Imports the select .csv file similar to the following commands:
a. Select Data -> From Text
b. Select the .csv file to be imported
c. Choose the “Delimited” option
d. Use comma as the delimiter character
e. Select all columns (hold shift and click the right-most column header)
f. Change the “Column data format” to Text
g. Click Finish
h. Put the data into cell A1
4. And possibly even alter the currently open Excel file name from “Book1” (or whatever it is) to the name of the .csv file that was opened.

I have a colleague trying to learn to program with .NET that can attempt this, but the key questions are:

1. Will it be possible to perform the above actions with .NET?
2. What is a general programming plan (perhaps which modules to use, etc?) that I can pass on to my colleague for development?

23rd November 2015, 01:40
create a quick (vba) macro to import the csv data, also sometimes it might become handy to change the file extension into .txt and handle it is as a txt file. Worth a try

23rd November 2015, 07:33
You can do this if you open a new spreadsheet, go to the Data tab, and press import from text.

Set the different options (comma-delimited) and change the Column data format to Text instead of General to stop excel dicking around with it.

This should help.

25th November 2015, 16:58
Manual solution in 6 steps:
1. Rename the file and remove the .xlsx or .xls extension etc. e.g. if my file is called test.xlsx I remove the '.xlsx' - you will get a warning message saying this could make the document unstable - accept it
2. The document icon should now have turned white (the document won't look like an excel document anymore)
3. Open a blank excel document by hitting start -> all programs -> Microsoft office -> excel (this may be different if you’re not on windows 7)
4. In your blank excel document hit file -> open
5. Navigate to the document you renamed above and select it, now click open
6. It should now open the document

I hope this helps someone, if not, visit an authoritative resource...
Recovery Whatever for Excel - paid, but fast and very effective method