Manipulating an instance code for an Excel document in Perl _perl

Source: Internet
Author: User
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
code as follows:

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
code as follows:

#!/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
 code as follows:

#!/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;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.