How to open results in excel when clicked on a link from web page created using perl cgi script -


i have perl cgi script displays results (50 rows) database query on web page.

at end of each row, have column html href link.

when link clicked, have open particular record in excel , allow saved.

i tried using spreadsheet::writeexcel, no luck.

can please give me link or thread regarding this?

code:

while(my $row = $query->fetchrow_hashref){     $html .= "<tr>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{promoter}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{company}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{bunit}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{sub}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{region}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{workstream}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{contractor}</td>";     $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{amp}</td>";     ### link open record in excel sheet ## } 

in main script, create link anchor tag redirects new script define need written in excel.

created new script below sub routine defined.

when link clicked, ask download/save option excel document.

code:1

                            $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{workstream}</td>";                             $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{contractor}</td>";                             $html .= "<td style='border-bottom:1px solid #cccccc' nowrap>$row->{amp}</td>";                             $html .= "<td style='border-bottom:1px solid #cccccc'><a href='notc.cgi?promoter=$row->{promoter}' target='_blank'>link</a></td>";                             $html .= "<td style='border-bottom:1px solid #cccccc'><a href='escc.cgi?promoter=$row->{promoter}' target='_blank'>link</a></td>"; 

code:2

sub doexcel {  print "content-type: excel/ms-excel; name=notc.xls\n"; print "content-disposition: attachment; filename=notc.xls\n\n"; binmode(stdout);      $dbh = kearynet::database->handle();     $query = $dbh->prepare("select * projects.notnames notpromoter = '$notpromoter' ");     $query->execute();      while($row = $query->fetchrow_hashref){             $searchresults{ $row->{notid} } = $row;     }      $fname="notcontacts_".$notpromoter.".xls";      print "content-type: excel/ms-excel; name=$fname\n";     print "content-disposition: attachment; filename=$fname\n\n";     binmode(stdout);      $x=0;     $workbook  = spreadsheet::writeexcel->new(\*stdout);     $worksheet = $workbook->add_worksheet("notificationcontacts");     $worksheet->activate();     $worksheet->write($x, 0,  "not routeid");     $worksheet->write($x, 1,  "not promoter");     $worksheet->write($x, 2,  "not level");     .....             foreach $r (sort keys %searchresults){             $nrow = $searchresults{$r};             if( not $row->{notid} ){                     $worksheet->write($x, 0,  $nrow->{notrouteid} );                     $worksheet->write($x, 1,  $nrow->{notpromoter} );                     $worksheet->write($x, 2,  $nrow->{notlevel} );                     $worksheet->write($x, 3,  $nrow->{notregion} );                     $worksheet->write($x, 4,  $nrow->{ntwrconid_1} );                     $worksheet->write($x, 5,  $nrow->{ntwrconname_1} );             }         }      } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -