In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to read and write Excel packages, xls, and xlsx in perl, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Introduce two packages in perl, which can read Excel files, including 2003 xls files and 2007 xlsx files. Spreadsheet::ParseExcel; Spreadsheet::ParseXLSX
This paper introduces two packages of two perl, which can read Excel files, including 2003 xls files Spreadsheet::ParseExcel, and 2007 xlsx files Spreadsheet::ParseXLSX.
Use Spreadsheet::ParseExcel;# reads the Excel2003 version of the excel file my $parser = Spreadsheet::ParseExcel- > new (); my $workbook = $parser- > parse ('test.xls'); if (! defined $workbook) {die $parser- > error (), ".\ n";} my $worksheet = $workbook- > worksheet (' Sheet1'); my ($row_min, $row_max) = $worksheet- > row_range (); my ($col_min, $col_max) = $worksheet- > col_range () Printf "s s s", 'first_row','second_row','third_row'. "\ n"; for my $row ($row_min.. $row_max) {for my $col ($col_min.. Col_max) {my $cell = $worksheet- > get_cell ($row, $col); next unless $cell; my $va=$cell- > value (); printf "s", $va;} say;} use Spreadsheet::ParseXLSX;# almost my $parser = Spreadsheet::ParseXLSX- > new;my $workbook = $parser- > parse ("file.xlsx"); my $worksheet = $workbook- > worksheet ('Sheet1') My ($row_min, $row_max) = $worksheet- > row_range (); my ($col_min, $col_max) = $worksheet- > col_range (); printf "s s s", 'first_row','second_row','third_row'. "\ n"; for my $row ($row_min. $row_max) {for my $col ($col_min.. $col_max) {my $cell = $worksheet- > get_cell ($row, $col); next unless $cell; my $va=$cell- > value (); printf "s", $va;} say;}
More help: https://metacpan.org/pod/Spreadsheet::ParseExcel
There is also a package that writes excel: Spreadsheet::WriteExcel (2003) and Excel::Writer::XLSX (2007) are used the same way:
Reference Code:
Use Spreadsheet::WriteExcel; # Create a new Excel workbookmy $workbook = Spreadsheet::WriteExcel- > new ('perl.xls'); # Add a worksheet$worksheet = $workbook- > add_worksheet (); # Add and define a format$format = $workbook- > add_format (); # Add a format$format- > set_bold (); $format- > set_color (' red'); $format- > set_align ('center'); # Write a formatted and unformatted string, row and column notation.$col = $row = 0 quality worksheet-> write ($row, $col,' Hi Excelsiors, $format) $worksheet- > write (1, $col,'Hi Excelsior'); # Write a number and a formula using A1 notation$worksheet- > write ('A3 steps, 1.2345); $worksheet- > write ('A4 steps,'= SIN (PI () / 4)')
Reference Code:
Use Excel::Writer::XLSX; # Create a new Excel workbookmy $workbook = Excel::Writer::XLSX- > new ('perl.xlsx'); # Add a worksheet$worksheet = $workbook- > add_worksheet (); # Add and define a format$format = $workbook- > add_format (); $format- > set_bold (); $format- > set_color (' red'); $format- > set_align ('center'); # Write a formatted and unformatted string, row and column notation.$col = $row = 0 $worksheet- > write ($row, $col,'Hi Excelsiors, $format); $worksheet- > write (1, $col,'Hi excels'); # Write a number and a formula using A1 notation$worksheet- > write ('A3 steps, 1.2345); $worksheet- > write ('A4 steps,'= SIN (PI () / 4)'); $workbook- > close () Thank you for reading this article carefully. I hope the article "how to read and write Excel packages, xls, and xlsx in perl" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.