Perl reads Excel and translates into HTML table

Source: Internet
Author: User

Today, I'm going to use Perl to read Excel and convert it into an HTML table.

Search online, read the package of Excel Spreadsheet::P arseexcel Better, powerful cpan, let me a command on the download installed it: cpan Spreadsheet::P arseexcel

#!/usr/bin/perl-w UseStrict; UseSpreadsheet::Parseexcel; UseSpreadsheet::P arseexcel::Fmtunicode;my $parser= Spreadsheet::P arseexcel->new ();my $file=$ARGV[0];my $formmater= Spreadsheet::P arseexcel::fmtunicode->new (Unicode_map ="CP936"); my $workbook=$parser->parse ($file,$formmater);if( !defined $workbook ) {     die $parser->error (),". \ n";}Open my $html,">","table.html"Or die;Print $html "<table border=1 style=\ "white-space:nowrap\" >"; 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 ) {        Print $html "<tr>";  for my $col($col _min..$col _max ) {           Print $html "<td>"; my $cell=$worksheet->get_cell ($row,$col ); Next unless $cell; Print $html $cell-value (); Print $html "</td>"; }        Print $html "</tr>"; }}Print $html "</table>";Close $html;

Perl reads Excel and translates into HTML table

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.