tags:

views:

129

answers:

4

Is this at all possible?

If I open up my file in standard text editor e.g. notepad the preceeding zeros are displayed.

e.g. 000485001 shows up.

Although this doesn't happen in excel. All that's displayed is 485001

Just wondering if there's a way around this?

Thanks,

A: 

Yes, when you're importing (or using 'Text to columns') you can explicitly indicate the data type for a column (instead of General). If you select 'Text' the zeros will not be dropped.

Unfortunately you only see the dialog to specify this option when Excel is already open and you use either File/Open or Data/Text to Columns. If you just double click a .csv in the explorer you don't get this choice.

Fried Hoeben
A: 

Excel tries very hard to determine the type of value it's importing. If it looks like a number, it will treat it like a number, and drop all the leading zeros as it reads it in. There's no way to get them back once they're lost.

You might try to import the file using the wizard that lets you set the data type for each column.

Mark Ransom
the thing is I'm generating this file and outputting it as a standard text file, and naming it e.g. report.csv. Because a csv is automatically opened by excel (which is what I want) the zeros are lost. I'm not really importing it from anywhere etc, just wanted the zeros to be displayed. They will be displayed if opened in notepad or notepad++ etc....I'm not sure if there is a way round this but thought I'd post it on here to make sure.
thegunner
A: 

Rather than writing your data as a CSV file, use the SYLK (Symbolic Link) format instead. This format includes information about the style of a column, so that Excel will not try to auto-guess the type of data.

The easiest way to get started with this format is to export a small file from Excel and use that as a template.

Mark Ransom
I've renamed it as an .slk file. But unfortunately the zeros are still gone and the columns are also gone. It's displaying it as if it were a text file.
thegunner
It's not enough to rename the file, you must write it in a completely different format. I presumed from your earlier comments that you were in control of the program that writes the data.
Mark Ransom
A: 

Ok got around this by inserting a text character before the number i.e. #000485001

Simple enough!

thegunner