Loading Excel

I created a C program MYPROGRAM on an ultrix machine that loads data
from a database query into an EXCEL spreadsheet.  

The problem i'm having is the first time the program runs after
entering NETSCAPE it fails.  It opens EXCEL, however EXCEL returns
a message that it could not open MYPROGRAM.XLS..  It should be trying
to load the data generated by MYPROGRAM not MYPROGRAM itself.  All
subsequent program runs work fine.  If I exit NETSCAPE and re-enter
the error repeats itself on the first run of the executable.

I'm guessing that the problem has somthing to do with my mime type, but
i'm not sure.  I created my own mime application/excel that launches
Any help would be greatly appreciated.

I am using NETSCAPE GOLD 3.01
           EXCEL 5.0
           WINDOWs NT 3.51

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knoppAuthor Commented:
Adjusted points to 50
knoppAuthor Commented:
Adjusted points to 100
knoppAuthor Commented:
The first time the excel option is used, the program does create
a file in the C:\temp directory.  The file gets the same name as
my executable MYPROGRAM. When EXCEL opens it tries to open
MYPROGRAM.XLS which doesn't exist and so it fails.
All subsequent tries while in the same NETSCAPE session work fine.  However, the files that get created which EXCEL open get
some sort of random file name, such as VP0GMMK4.TMP  
What piece of software creates the random file name, since the data is being generated by a server executable MYPROGRAM.  Is it
the web server?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

knoppAuthor Commented:
Adjusted points to 150
knoppAuthor Commented:
If I access the program using...

   WINDOWS NT 4.0  and MSOFFICE 97

the program loads EXCEL on the first try but uses the MYPROGRAM
as the filename.  I'm guessing the version of EXCEL in MSOFFICE
97 doesn't care about requiring an .XLS extention before opening.
However, on all subsequent tries the file loaded has a random
knoppAuthor Commented:
I found one way around the problem, although its not the final answer that I was looking for.  If I add an extention to the executable MYPROGRAM on the server, I'm able to load EXCEL on the
first try after opening NETSCAPE.  However, it works a little
strange.  If I append extention .cgi to MYPROGRAM, when EXCEL
is called the first time it opens a workbook with the same name
as my executable MYPROGRAM.cgi.  All subsequent calls will get
get the random filename with my extention, for ex: V09??????.cgi

Is this a bug with the server software or NETSCAPE????
This has nothing to do with the server. Whenever you download a document with a MIME type that is handled by an application, Netscape creates a temporary file with the same name as the file on the server and calls the application with that temporary file as an argument. I don't know if you can force Netscape to use a different name or extension on the temp file.

I have recently had exactly the same requirement as you although my requirements are a little more general. My requirement was to be able to output the results of a CGI application to any spread sheet (as opposed to Excel) from any Browser  (although I will only be testing with Internet Exploder and Netscape browsers) for any platform. For this reason I am outputing files in Symbolic Link (aka SYLK and .SLK) format, this is a format that most spreadsheet packages can read (I hope) but still allows column formating and inclusion of formulas. SYLK is also "fairly" easy to read because it only uses printable ASCII characters.

As you have noted, whenever you generate output from your app, a "random" file name is generated except for the very first time. This is because (as pc indicated) the Netscape browser uses the name of the cgi application (or ftp'd file) when saving the output of the application (or the ftp'd file). If the file name is already used, Netscape generates a "random" name something along the lines of a V followed by some letters and numbers, my experience is that Netscape will try to retain the extension of the file. I think Internet Exploder works a little differently in that it keeps the file name but if the name is already in use it appends a sequential number in brackets eg. fred.txt, fred (1).txt, fred (2).txt and so on. In both cases the extension of the file is retained to support recognition of the file type by the extension (eg. a .XLS file is associated with Excel, .BMP with paint and so on)

I too attempted to research the idea of specifying a file name in the mime type without success. I don't believe that this is actually possible - directly specifying the name of the file in the mime type that is. In certain circumstances, it is possible to specify a file name (eg. in uuencoded data), but not in the mime type itself.

Well that was all very (un?)interesting, but what does it mean for you?

Firstly, if you must generate your spreadsheet from a cgi program don't make it a .EXE because Netscape will probably either save or try to run the output of your cgi program (i.e. a spreadsheet data file) as an application. This is analgous to creating a spreadsheet, saving it, renaming it to something.exe and running it from the start menu / program manager. Something that computer text books usually refer to as having "unpredictable results".

The solution I implemented was to have my cgi application output the results of the spreadsheet as an HTML document. Do I hear you say "Thanks very much I could have thought of that"? Well, wait there is more.

Whilst outputing the results of your application in HTML, simultaneously write the data away to a file somewhere in your HTML documents directory (eg. .../htdocs/tmp/ssfile0002.xls). This file is the Excel version of output with an appropriately GENERATED name and extension (eg. ssfilennnn.XLS), in my case (Unix), I used a combination of the description and the processID for the file name. Now the last step (and this is the neat part) is to include a link to the excel spreadsheet as part of the HTML output. This link offers the user the "opportunity to download the displayed information in Excel format for further analysis".

What the user sees is the results of the "query" together with a clickable offer to download the results in Excel format. Presumably the results displayed in the browser would be in the same format as you would provide them in Excel, or if the spreadsheet is wide, just the significant columns.

You will need to do a little housekeeping to clean up old spreadsheets, but that is fairly easy. On unix I just created a cron job that simply deleted files in the TEMP HTML documents directory that hadn't been accessed for more than a day. In Unix this is a one liner command.


So why would you want to do this. I don't know your application so I will give you a list of the benefits that I identified for my application.

1. It gives the user the opportunity to peruse or print the results from the browser before loading Excel (i.e. relatively quickly and easily). On my laptop (16MB Pentium 120), it takes bloody ages to load Excel 7 under Windows 95. Or at least it seems to while I wait for it to come up.

2. In Netscape's case (2.02 Gold), Netscape launches a fresh copy of Excel for each new set of results rather than using an existing instance. This I personally find irritating due to the number of applications (windows) on the desktop.

3. If the user is clicking on the back and forward buttons, and accidentaly stop on your page they won't get another copy of Excel loaded.

4. The downloaded file's extension will be preserved/correct. This means that applications which judge the type of the file by the extension, eg. Internet Exploder, Windows File Manager, Windows Explorer and some older applications, will still work correctly i.e. less user confusion.

As mentioned, the above reasons suit my circumstance, you will have to judge the suitability to your own circumstance. My application is "research oriented" a typical session would be to run the cgi Excel generator a number of times with different parameters and download only a few sets of results for subsequent analysis. If your requirement is to allow users to graph results, then there are freely available graph producing packages available (eg. GNUPLOT).

If you want me to send you one of the scripts that I am, email me.  My script is written in PERL on a Unix system, but it should work on an NT system with little or no modification.

I hope this is of help


P.S. Now a question for you. What format are you using for your generated Excel Spreadsheets and how do you produce it (eg. is your data file in native Excel format, or something simpler like Comma seperated variables - do you use Excel itself to write the data file via OLE or the like)?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dear Friends,

I am doing Server Side Programming using JSP. I want to give "download in Excel Format" option in my website to download some statistical data. Can u please tell me how to create a Excel file(what control characters i should use to create excel headers & formatting, etc) in JSP? or please give me URL which explains the control characters used for creating Excel file?

A. Subbaiah
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.