めも

2008/5/20 [19:23:18] (火) 天気

以前にも書いたけど、メモっておこう。


エクセルのシートを直接perlで読む。


#!/usr/local/bin/perl

use strict;

use Spreadsheet::ParseExcel;

use Spreadsheet::ParseExcel::FmtJapan;

my $oFmtJ = Spreadsheet::ParseExcel::FmtJapan->new(Code =>’utf8’);

my $oBook = Spreadsheet::ParseExcel::Workbook->Parse(’test.xls’, $oFmtJ);


my $ws; my $wc;

for(my $i = 0; $i < $oBook->{SheetCount}; $i++){

$ws = $oBook->{Worksheet}[$i];

print ’Sheet: ’ , $ws->{Name} , "¥n";

for(my $r = $ws->{MinRow}; defined $ws->{MaxRow} && $r <= $ws->{MaxRow}; $r++ ){

for(my $c = $ws->{MinCol}; defined $ws->{MinCol} && $c <= $ws->{MaxCol}; $c++ ){

$wc = $ws->{Cells}[$r][$c];

print "( $r,$c ) => ", $wc->Value ,"¥n" if $wc && $wc->Value;

}

}

}


読むならこれだけでOK。いちいちエクセルなんぞを開かなくていいんだよなぁ。まじめに助かるゼ

<<2026/1>>
    123
45678910
11121314151617
18192021222324
25262728293031
検索:

【最近の20件】