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);
}