use strict; use CGI; use Spreadsheet::WriteExcel; my $q = new CGI; my $inv = $q->param('stinv'); my $mntdir = $q->param('mntdir'); my $second_line_format = $q->param('tap'); my $file_name = $q->param('file_name'); my $download = $q->param('download'); if ( $inv eq "dev" ) { ## Defind Root path for execute file $file_name = "\/home\/httpd\/html\/newdev2\/m\/".$mntdir."/".$file_name."\.txt"; } elsif ( $inv eq "test" ) { $file_name = "\/home\/httpd\/test\/m\/".$mntdir."/".$file_name."\.txt"; } elsif ( $inv eq "stg" ) { $file_name = "\/home\/httpd\/staging\/m\/".$mntdir."/".$file_name."\.txt"; } else { $file_name = "\/home\/httpd\/html\/m\/".$mntdir."/".$file_name."\.txt"; } print "Content-type: application/vnd.ms-excel\n\n"; ## Outputing spreadsheet header my $workbook = Spreadsheet::WriteExcel->new("-"); my $worksheet = $workbook->add_worksheet(); my $plain = $workbook->add_format(); my $bold = $workbook->add_format(bold => 1); my $italic = $workbook->add_format(italic => 1,text_wrap => 1); my $format; $worksheet->set_column(0,0,45); # Set column width for company name $worksheet->set_column(1,20,18); # Set column width for rest of data open(IN,"$file_name") or die "Cannot open :$!\n"; ## Open file my $rnum = 0; my $last_row_empty; while( my $line = ) { ## Input Data from a file chomp $line; my @row = split(/\t/,$line); my $col = 0; foreach my $field ( @row ) { if ( $last_row_empty eq 1 ) { $worksheet->write($rnum, $col++,$field,$bold); } elsif ( $file_name =~ /peer/ && $field =~ /Company Name/ ) { $worksheet->write($rnum, $col++,$field,$italic); } else { $worksheet->write($rnum, $col++,$field,$plain); } } $last_row_empty = 0; $last_row_empty = 1 if ( @row eq 0 ); $rnum++; } close IN; ## Close file exit; #### Using perl 5.6.1 unless otherwise noted. Apache 1.3.27 unless otherwise noted. Redhat 7.1 unless otherwise noted.