csv files / MIME types / pies

Author
Discussion

lanciachris

Original Poster:

3,357 posts

242 months

Wednesday 16th March 2005
quotequote all
So. My magical web app generates reports in a csv format. You click the button to generate it, and you get your open / save dialog.

If you hit open you get into your dodgy browser/excel hybrid and it opens it as a .csv file and the data is all formatted correctly.

If you hit save it saves it as an xls file and thus the data is not formatted correctly.

What gives? why is deciding to save a csv as an xls? fresh install of xp.

ps. there are no pies. If you just came here for pies, bad luck.

Plotloss

67,280 posts

271 months

Wednesday 16th March 2005
quotequote all
Who wrote this magical webapp?

The FileOpen dialog Save method has a parameter for extension.

This is probably being hard coded somewhere...

lanciachris

Original Poster:

3,357 posts

242 months

Wednesday 16th March 2005
quotequote all
I wrote it.

Im sending the user off to the csv file, but somewhere along the line some microshaftness is deciding it will pretend its an xls file. Ive tried various mime type but so far no success.

Plotloss

67,280 posts

271 months

Wednesday 16th March 2005
quotequote all
Are you using Excels save method?

dilbert

7,741 posts

232 months

Wednesday 16th March 2005
quotequote all
I'm wondering exactly how you invoked Excel.

Have you actually "Given" excel a filename/type.

I'm not sure what you're doing, but the Microshaftness is usually fine as long as it knows what the Megamoron driving it is actually doing.

No offence is intended, it's just that I've been through the Microshftness/Megamoron loop myself..... On more than one occasion!

lanciachris

Original Poster:

3,357 posts

242 months

Wednesday 16th March 2005
quotequote all
More complete run down.

My magical web app is a questionnaire system. Questionnaires get taken, results stored in xml, reports available, yadda yadda yadda.

A requirement is that the system should be able to export the results to excel and appear similarly to the persons existing manual reports.

So im making a csv file out of my results and saving it, then simply sending the client off to that point. Excel is not involved other than the fact that its standard software on all the client machines and ie thinks it will be fun to get excel involved when it picks up a file that could possibly be opened by it.

I thought giving it a different mime type would make ie treat it differently, but so far no luck.

dilbert

7,741 posts

232 months

Wednesday 16th March 2005
quotequote all
Well, this is microsoft.

Someone will probably flame me, but isn't mime for Unix types?


I'm thinking that this is more of a client side JAVA applet than a server side script?

If so I'm not surprised about what you're saying. That's not so much my bag, but I can believe proper I/O (disk and so on) is difficult in that environment.

If you're looking to get data from clients to a central server, I'd be tempted to go the CGI Server Side Script route (perl, or even C to handle HTML Get and Post). I'm sure I'm pretty archaic in that view though.

The other option that is probably more suited to data gathering like this, over a JAVA applet, is ASP.net.

Another idea is to write a Java server application that runs on your server machine and opens a listener port. It is capable of saving stuff to disk.

Then have your client side applet squirt the data back to the server by TCP. This way you avoid IE altogether.



>> Edited by dilbert on Wednesday 16th March 20:46

>> Edited by dilbert on Wednesday 16th March 20:51

lanciachris

Original Poster:

3,357 posts

242 months

Wednesday 16th March 2005
quotequote all
Think this has come across as a windows app that uses the net, which its not. oops. its an asp.net / c# site.

dilbert

7,741 posts

232 months

Wednesday 16th March 2005
quotequote all
Well I think I'm more confused now!


I did say that I was a Megamoron though. I'm not at all sure about all this new stuff coming out of the Bill Gates camp. It just seems like MFC gone even badder to me.

The only things I rely on these days are the Win32 API's. In real terms this is a step backwards, but as I move forward, I have bigger and bigger libraries of my own. This means that some of the tasks that most would consider arduous, can be made straightforward.

I hope you find a way through. It is pants that a giant like MS can leave one with so few options sometimes!

I think this is one of the reasons I'm relatively happy to be out of work. Everyone seems to be going on about .NET and forcing their developers to use it. It seems to me that it was put there to help people to get to the stage where they can use the guts of windows directly. I'd rather be unemployed than forced to use a platform which is further from the place to be than closer to it.

Maybe one day I'll have to learn it anyway.


>> Edited by dilbert on Wednesday 16th March 22:42

pdV6

16,442 posts

262 months

Thursday 17th March 2005
quotequote all
Are you making this more complicated than it needs to be?
CSV format is simply a text file with data separated by commas.

Excel is happy to read CSVs and simply dump the values into a grid and (as you say) highjacks the .CSV file extension by default.

As you're storing the data in XML to start with, that would seem to be the ideal way to send the data to a report. You could write yourself a transform that would take the "raw" XML and produce a report formatted in any way you so choose (HTML?).

lanciachris

Original Poster:

3,357 posts

242 months

Thursday 17th March 2005
quotequote all
It does provide html versions etc already, it just has this silly legacy format that the person wants. It works fine when it decides to recognise it as a csv file, but the trouble is when you choose save it saves it as an xls by default, and thus you open it it treats it as an xls when its actually a csv file. If that makes any sense. I think its because im redirecting to the file that my mime headers are making no odds. trying to remember how ive solved it in the past.

KITT

5,339 posts

242 months

Thursday 17th March 2005
quotequote all
I've written some php that generate's cvs files at runtime and saves them on the server. Then the user simply downloads them. This works fine and Excel will open them without trying to change the extension.