If you have your data in a csv file the next step is just to put in this sub routine to create an excel file.

If your data is not in a csv but in another type of file format - you can change the 'comma' split part to something else if your data is seperated by just whitespace or another seperater.

The code is just to give you a pointer in the right direction.
You should read the Spreadsheet::WriteExcel module information as well.

The code is below

use Spreadsheet::WriteExcel; # Create an excel file binary &create_excel_file ($csv_file_name, $xls_file_name); ## This sub routine creates an xls binary from the csv file data sub create_excel_file { # create Excel binary format outfile from CSV my ($csv_file, $xls_file) = @_; my $workbook = ""; my $worksheet = ""; my $row = 0; my $column = 0; # Sending the csv file information to xls format open (CSV, $csv_file) or die "Error opening $csv_file: $!"; $workbook = Spreadsheet::WriteExcel -> new($xls_file); # Add a worksheet to the workbook file $worksheet = $workbook -> addworksheet(); # Or add a named worksheet to create @worksheets #$worksheet = $workbook->addworksheet($sheetname); #activate($sheetname) # While there is data in the csv file while (<CSV>) { chomp; # Split the fields on only the , and space seperators my @FIELDS = split(', ', $_); $column = 0; foreach my $token (@FIELDS) { # Write out the row and column and token to each row $worksheet -> write($row, $column, $token); $column++; } $row++; } # my $format1 = $workbook -> addformat(); # $format1 -> set_bold(); # $format1 -> set_align('center'); # $format1 -> set_border(); # $worksheet -> set_row(0, undef, $format1); $workbook -> close() or die "Error closing $workbook: $!"; # WARNING .... This code will delete the CSV # Delete the csv file to save space unlink ($csv_file); }

In reply to Re: Display Report Using Excel by chime
in thread Display Report Using Excel by welly

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.