Worksheet has corrupt name after download of csv

R

roel.schreurs

I am offering visitors of a website the possibilty to download a csv
formatted file of data. Visitors may normally choose to save the
download or to open it directly with Excel.

I have noticed that if they choose to open it, the Worksheet will have
a name containing brackets, which is considered invalid by Excel and
this prevents users to:
1) rename the woksheet
2) use the data in the sheet for reference form other sheets, for pivot
tables, e.t.c.
If the file is suqsequently saved, the worksheet is renamed and all
works fine.

Below is a sample that reproduces the behaviour:
1. Start VS.NET and create a new VB.NET Web Application.
2. On the aspx page, place an button named Download.
3. Double click the button and modify the event handler to look as
follows:

Private Sub Download_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Download.Click
Response.Clear()
'Indicated by Q260519 http://support.microsoft.com/kb/q260519/
Response.AddHeader("content-disposition",
"attachment;filename=test.csv")
Response.ContentType = "text/csv"
Response.Write("These;are;some;cells")
Response.End()
End Sub

(Note the comment about Q260519)

4. Run the application and click the Download button.
5. Choose Open with Excel.

The worksheet that is opened will be named .csv]test(1)

Notes:
1. The problem only occurs with IE. It appears that the downloaded
files are stored in a location like:
C:\Documents and Settings\<account>\Local Settings\Temporary Internet
Files\<B4645LS9>
2. Downloads using Firefox do not show this problem.

Of course, I could notify visitors about this problem, but I would
really like a solution. Does anybody have it?
 
H

Harlan Grove

(e-mail address removed) wrote...
....
The worksheet that is opened will be named .csv]test(1)

Notes:
1. The problem only occurs with IE. It appears that the downloaded
files are stored in a location like:
C:\Documents and Settings\<account>\Local Settings\Temporary Internet
Files\<B4645LS9>
2. Downloads using Firefox do not show this problem.
....

The problem is the filename IE uses when saving the file, test[1].csv.
IE always seems to add [#] to the end of the base filename when saving
files locally. The only way to fix this is saving the file without the
[#] suffix or somehow renaming the file after it's been saved are your
only options.

If you open any text file with square brackets in the filename in
Excel, Excel will mung the worksheet name. While this is a problem with
Excel, there's no way to fix this *in* Excel other than by saving the
file under a different filename. If you save the file as a CSV file,
Excel will change the worksheet name to match the file's base filename
(without the .xls extension). If you save the file as an XLS file, you
should then be able to rename the worksheet.

That's a lot to expect from your users, so you should concentrate on
fixing this OUTSIDE Excel. That makes this no longer an Excel issue but
a ASP/IE one. You should post in a newsgroup appropriate for either (or
crosspost to newsgroups for both) asking how to download temporary
files WITHOUT the added [#] suffix.
 
R

roel.schreurs

Thanks for your reply.

I have 'forwarded' the question to
microsoft.public.windows.inetexplorer.ie6.browser under the same
subject.

Harlan Grove schreef:
(e-mail address removed) wrote...
...
The worksheet that is opened will be named .csv]test(1)

Notes:
1. The problem only occurs with IE. It appears that the downloaded
files are stored in a location like:
C:\Documents and Settings\<account>\Local Settings\Temporary Internet
Files\<B4645LS9>
2. Downloads using Firefox do not show this problem.
...

The problem is the filename IE uses when saving the file, test[1].csv.
IE always seems to add [#] to the end of the base filename when saving
files locally. The only way to fix this is saving the file without the
[#] suffix or somehow renaming the file after it's been saved are your
only options.

If you open any text file with square brackets in the filename in
Excel, Excel will mung the worksheet name. While this is a problem with
Excel, there's no way to fix this *in* Excel other than by saving the
file under a different filename. If you save the file as a CSV file,
Excel will change the worksheet name to match the file's base filename
(without the .xls extension). If you save the file as an XLS file, you
should then be able to rename the worksheet.

That's a lot to expect from your users, so you should concentrate on
fixing this OUTSIDE Excel. That makes this no longer an Excel issue but
a ASP/IE one. You should post in a newsgroup appropriate for either (or
crosspost to newsgroups for both) asking how to download temporary
files WITHOUT the added [#] suffix.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top