Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

On my browser, this (1) prompts "do you want to open or save this downloaded file?" and (2) opens TWO windows, one blank.

As to why you see two windows, I cannot say. I cannot replicate this behaviour. Maybe someone with more CGI experience could explain this. However, I have noted some small differences in the way Netscape and IE handle the example program. The joys of CGI and browsers, I guess. %^)

If you wish to stream the file to Excel you can set the Content-type as follows:     print "Content-type: application/\n\n";
If you wish to prompt the user to view the file or save it with a specified filename you can do something like the following:
my $filename ="cgitest.xls"; print "Content-type: application/\n"; print "Content-Disposition: attachment; filename=$filename\n\n";
The example that you posted has been updated in more recent versions of the module to highlight these options. However, the view or save options can be overridden by the client browser.

Can you comment on your tie soln above, and the alternative as per

In a CGI program you have to redirect the Excel file to STDOUT. The easiest way to do this is to use the "Minus" file as a file name in the constructor:     my $workbook = Spreadsheet::WriteExcel->new("-");
The "Minus" file is documented in perlopentut*. The comment in the above example refers to it as a filehandle but it isn't, it is a file name.

As such you do not need to use tie at all in this situation. You would only need to use the above technique if you wanted to do something unusual such as stream the file to a browser and save a local copy.

The option of passing filehandles to the constructor was introduced mainly to allow the files to be streamed over sockets and to allow Spreadsheet::WriteExcel to work with mod_perl.

* Does anyone know of anywhere else that this is documented?

In reply to Re: Re: Re: capturing STDOUT by jmcnamara
in thread capturing STDOUT by nop

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (6)
    As of 2018-06-24 20:58 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.