I use this code in a script:
#! /usr/bin/perl use strict; use warnings; use diagnostics; use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; use Data::Dumper; use lib qw(/data/perllib); use Spreadsheet::WriteExcel; use Conf; my $cgi = CGI->new(); my %params = $cgi->Vars(); print $cgi->header(-type => 'application/vnd.ms-excel',); # general settings for database-connection my $USER = $Conf::USER; my $PASSWORD = $Conf::PASSWORD; my $HOST = $Conf::HOST; my $DATABASE = $Conf::DATABASE; my $DBMS = $Conf::DBMS; my $driver = "dbi:$DBMS:$DATABASE:$HOST"; # create connection to database my $dbh = DBI->connect($driver,$USER,$PASSWORD); my $statement = "SELECT * FROM table;"; #---------------------------------------------------# # write EXCEL-file # #---------------------------------------------------# binmode(\*STDOUT); my $EXCEL = new Spreadsheet::WriteExcel(\*STDOUT); my $sheet = $EXCEL->addworksheet("Features"); my $state_h = $dbh->prepare($statement); $state_h->execute(); my $col_h = 1; $sheet->write(0,0,'Header1'); shift(@wanted_cols); foreach my $th(@wanted_cols){ $sheet->write(0,$col_h,$th); $col_h++; } my $row = 1; while(my @res_array = $state_h->fetchrow_array){ foreach my $col(0..(scalar(@res_array)-1)){ $sheet->write($row,$col,$res_array[$col]); } $row++; } $EXCEL->close();


This code creates an Excel-window where you can use the all the Excel-abilities!

In reply to Re: Running external apps by reneeb
in thread Running external apps by Anonymous Monk

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.