- 论坛徽章:
- 0
|
PERL中如何读取EXCEL中的数据~~
用这个模块 Spreadsheet: arseExcel
在cmd中这样做:
$>;perl -MCPAN -e shell
cpan>;install Spreadsheet: arseExcel
就可以自动安装最新版本了:)
下面是我以前下载的一个应用它的例子
作为你的参考吧!
- #!/usr/bin/perl -w
- use strict;
- use Spreadsheet::ParseExcel;
- my $oExcel = new Spreadsheet::ParseExcel;
- die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV;
- my $oBook = $oExcel->;Parse($ARGV[0]);
- my($iR, $iC, $oWkS, $oWkC);
- print "FILE :", $oBook->;{File} , "\n";
- print "COUNT :", $oBook->;{SheetCount} , "\n";
- print "AUTHOR:", $oBook->;{Author} , "\n"
- if defined $oBook->;{Author};
- for(my $iSheet=0; $iSheet < $oBook->;{SheetCount} ; $iSheet++)
- {
- $oWkS = $oBook->;{Worksheet}[$iSheet];
- print "--------- SHEET:", $oWkS->;{Name}, "\n";
- for(my $iR = $oWkS->;{MinRow} ;
- defined $oWkS->;{MaxRow} && $iR <= $oWkS->;{MaxRow} ;
- $iR++)
- {
- for(my $iC = $oWkS->;{MinCol} ;
- defined $oWkS->;{MaxCol} && $iC <= $oWkS->;{MaxCol} ;
- $iC++)
- {
- $oWkC = $oWkS->;{Cells}[$iR][$iC];
- print "( $iR , $iC ) =>;", $oWkC->;Value, "\n" if($oWkC);
- }
- }
- }
复制代码 |
|