Spreadsheet::ParseExcel v0.09

by Hippo2000(2000/12/25)


目次


名前

Spreadsheet::ParseExcel - Excelファイルから情報を取得する


概要

    use strict;
    use Spreadsheet::ParseExcel;
    my $oExcel = new Spreadsheet::ParseExcel;
    #1.1 Normal Excel97
    my $oBook = $oExcel->Parse('Excel/Test97.xls');
    my($iR, $iC, $oWkS, $oWkC);
    print "FILE  :", $oBook->{File} , "\n";
    print "COUNT :", $oBook->{SheetCount} , "\n";
    print "AUTHOR:", $oBook->{Author} , "\n";
    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);
            }
        }
    }

説明

Spreadsheet::ParseExcel はExcel95, Excel97, Excel2000ファイルから情報を取得することを可能にします。


関数

new
$oExcel = new Spreadsheet::ParseExcel;

コンストラクタ。

 
Parse
$oWorkbook = $oParse->Parse(oFileName [, $oFmt]);

Workbook オブジェクトを返します。エラーが発生したら、undefを返します。

$oFileName
解析するファイルの名前。
$oFmt
セルの値を整形するFormatterクラス

ワークブック(Workbook)

Spreadsheet::ParseExcel::Workbook

Workbookは以下のプロパティを持ちます:

File
ファイルの名前
Author
ファイルの作者(Author)。
Flag1904
このフラグがオンであれば、そのファイルの日付は1904年からカウントされます。
 
Version
そのファイルのバージョン
 
SheetCount
そのワークブックでのWorksheet の数
 
Worksheet[SheetNo]
Worksheet クラスの配列
 

ワークシート(Worksheet)

Spreadsheet::ParseExcel::Worksheet

Worksheetは以下のプロパティを持ちます:

Name
ワークシートの名前
DefRowHeight
行の高さのデフォルト
DefColWidth
列の幅のデフォルト
RowHeight[Row]
行の高さの配列
ColHeight[Col]
列の幅の配列(undefはDefColWidthということ)
Cells[Row][Col]
ワークシートでのCells情報の配列

Cell

Spreadsheet::ParseExcel::Cell

Cellクラスは以下のプロパティを持ちます

Value
メソッド 。 そのセルの整形された値。
Val
そのセルの元の値
Type
そのセルの種類('Text', 'Numeric', 'Date')
Code
そのセルの文字コード(undef, 'ucs2', '_native_')。undefであればASCIIでしょう。'_native_' は'sjis'などのようなものであることを示します。

Formatter class

Spreadsheet::ParseExcel::Fmt*

Formatterクラスはセルのデータを変換します。

Spreadsheet::ParseExcelは2つの整形クラス: FmtDefault と FmtJapanese が入っています。独自の整形クラスを作成することができます。

Formatter クラス(Spreadsheet::ParseExcel::Fmt*) は以下の関数を提供しなければなりません:

ChkType($oSelf, $iNumeric, $iFmtIdx)
指定された値を持つセルのタイプを返します。
$oSelf
Formatter そのもの
$iNumeric
もしオンであれば、その値が数値であると思われます。
$iFmtIdx
そのセルのフォーマット・インデックス番号
TextFmt($oSelf, $sText, $sCode)
元のテキストをその値に適切なものに変換します
$oSelf
Formatterそのもの
$sText
元のテキスト
$sCode
元のテキストの文字コード
ValFmt($oSelf, $oCell, $oBook)
元の値をその値に適切なものに変換します
$oSelf
Formatterそのもの
$oCell
Cellオブジェクト
$oBook
Workbookオブジェクト
 

作者

川合孝典 (Hippo2000) kwitknr@cpan.org

    http://homepage3.nifty.com/hippo2000/ (Sorry Only in Japanese)

参考資料

XLHTML, OLE::Storage, Spreadsheet::WriteExcel

このモジュールはOLE::StorageのなかのherbertとxlHtmlをベースにしてます。


著作権

The Spreadsheet::ParseExcel module is Copyright (c) 2000 Kawai Takanori. Japan. All rights reserved.

You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.


謝辞

まず何より価値あるプログラム、モジュールに感謝します: XHTML, OLE::Storage そして Spreadsheet::WriteExcel.

順不同: Simamoto Takesi, Noguchi Harumi, Ikezawa Kazuhiro, Suwazono Shugo, Hirofumi Morisada, Michael Edwards, Kim Namusk and many many people + Kawai Mikako.


ホーム Perlの小技

ご意見、ご質問はこちらの掲示板で受け付けています。
またメールは河馬屋(Nifty)にお願いします。