사용자 도구

사이트 도구


develop:perl:excel

Perl을 이용하여 Excel과 연동하기

Excel 데이타 읽기

#!/usr/bin/perl -w
# 
# starlits at adminschool.net
# excel cell reading
#
 
use strict;
use Spreadsheet::ParseExcel;
use Encode;
 
my $encoding = "euc-kr";
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);
        }
    }
}

Excel에서 한글 데이타 읽기

  1. 아래와 같이 서두에 encoding 설정을 하면 된다.
#!/usr/bin/perl -w 
# 
# starlits at adminschool.net
# excel cell reading (korean)
#
 
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode;
 
my $encoding = "euc-kr";
my $oExcel = new Spreadsheet::ParseExcel;
 
my $oFmt = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => $encoding);
my $oBook = $oExcel->Parse($ARGV[0],$oFmt);
 
...
develop/perl/excel.txt · 마지막으로 수정됨: 2007/09/24 02:23 저자 starlits