I have a CGI that calls a C++ executable (running on AIX) that generates a report in XML that applies a stylesheet already present on the user's local machine.

I then feed the report back to the browser with the following function.

sub retrieveFile { my $file = shift; if(not -e $file) { croak "Could not locate file: $file)"; } if(not open(FH, $file)) { croak "Could not open file: $file"; } my $filesize = -s $file; print $cgi->header(-type=>'application/vnd.ms-excel', -Content-Disposition=>"attachment; filename +=$file", -Content_Length=>$filesize); while(<FH>) { print; } close FH; }

So when this is run, you get the standard "Open or Save" windows dialog.

If you choose "Save" and then open it, you get the dialog to apply the stylesheet. It opens in Excel and all is right with the world.

But if you choose "Open", you get the dialog, then an error message that says: "The download of the specified resource has failed.", then you get the stylesheet dialog AGAIN, then the file opens and looks fine.

Since the file is fine when you save, I don't see how the problem could be in the XML being generated, which means that the problem is in my Perl somewhere.

Any thoughts, please? Thanks.


In reply to Openning XML in Excel using CGI by rashley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.