Solved

Loading Excel

Posted on 1997-03-05
9
436 Views
Last Modified: 2013-12-25
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
excel.  
Any help would be greatly appreciated.

I am using NETSCAPE GOLD 3.01
           EXCEL 5.0
           WINDOWs NT 3.51

Thanks,
Gary
0
Comment
Question by:knopp
9 Comments
 

Author Comment

by:knopp
Comment Utility
Adjusted points to 50
0
 

Author Comment

by:knopp
Comment Utility
Adjusted points to 100
0
 

Author Comment

by:knopp
Comment Utility
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?
0
 

Author Comment

by:knopp
Comment Utility
Adjusted points to 150
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:knopp
Comment Utility
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
filename....V09????.TMP
0
 

Author Comment

by:knopp
Comment Utility
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????
0
 
LVL 3

Expert Comment

by:pc012197
Comment Utility
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.

0
 

Accepted Solution

by:
firefox032697 earned 190 total points
Comment Utility
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

firefox

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)?

0
 
LVL 1

Expert Comment

by:subbaiah
Comment Utility
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?

Regards
A. Subbaiah
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now