The Spreadsheet::WriteExcel and spreadsheet are available on Linux or UNIX (generated) Excel,cpan::P arseexcel these two modules.
Here's a look at Spreadsheet::WriteExcel and spreadsheet: How to use the:P arseexcel.
First, install the appropriate module on the server.
To install the PPM command for an Excel module
Ppm> Install Ole::storage_lite
ppm> Install spreadsheet::P Arseexcel
Ppm> Install Spreadsheet::WriteExcel
Let's take a look at two examples.
Example 1: Reading Excel files
#!/usr/bin/perl-w
Use strict;
Use spreadsheet::P arseexcel;
My $parser = spreadsheet::P arseexcel->new ();
My $workbook = $parser->parse (' Book1.xls ');
For my $worksheet ($workbook->worksheets ()) {
My ($row _min, $row _max) = $worksheet->row_range ();
My ($col _min, $col _max) = $worksheet->col_range ();
For my $row ($row _min. $row _max) {
For my $col ($col _min. $col _max) {
My $cell = $worksheet->get_cell ($row, $col);
Next unless $cell;
Print "Row, Col = ($row, $col) \ n";
print "Value =", $cell->value (), "\ n";
print "unformatted =", $cell->unformatted (), "\ n";
print "\ n";
}
}
}
Example 2: Generating Excel files
#!/usr/bin/perl-w
Use Spreadsheet::WriteExcel;
# Create a new Excel file
My $workbook = spreadsheet::writeexcel->new (' Test.xls ');
# Add a worksheet
$worksheet = $workbook->add_worksheet ();
# Create a new style
$format = $workbook->add_format (); # Add a format
$ format-> set_bold (); #Set the font to bold
$ format-> set_color ('Red'); #Set the foreground color of the cell to red
$ format-> set_align ('center'); #Set cell center
#Use line and column numbers, Writes a formatted and end-formatted string to a cell
$col = $row = 0;
$worksheet->write ($row, $col, ' Hi excel! ', $format);
$worksheet->write (1, $col, ' Hi excel! ');
# Use the cell name (example: A1) to write a number to the cell.
$worksheet->write (' A3 ', 1.2345);
$worksheet->write (' A4 ', ' =sin (PI ()/4) ');
Exit;