LoginSignup
6
8

More than 5 years have passed since last update.

Excel::Writer::XLSX

Posted at
 20150301 現在

Perl の Excel の writer について。
有名なものとして、メンテナンスモードの Spreadsheet::WriteExcel がある。過去には定番中の定番だったが、メンテナンスモードと言う通り、大昔の Excel しか相手にしてないので使いものにならない。
で、最近の書式を相手にするものには、同じ作者の Spreadsheet::WriteExcelXML がある。しかし、pod で「非推奨だよ、Excel::Writer::XLSX 使ってね。」と宣言までされている。(そこまで書くなら公開停止すりゃいいのに、、、)

ので素直に Excel::Writer::XLSX を使いましょう。

# windows の人は、 Win32::OLE を覚えてしまうのが、結果的には覚える事が少なくなるのかも知れない。

インストール

$ cpanm Excel::Writer::XLSX

サンプルコード

無し

メモ

  1. 色付け、斜め線などは違ったり違わなかったり。
  2. ハイパーリンクの書き込みは65530まで。
  3. Spreadsheet::WriteExcelExcel::Writer::XLSX では微妙に書式が違う。

1.は、モニタの仕様もあるけど、線が見えなくなるのは Numbers と Excel の互換の問題(?)
2.は、このリミテーションに引っ掛かる様なデータを弄ったので。他にもリミテーションが色々とあるので留意する事。
3.に関しては以下とか、

例)write_url

pod より。

write_url($row, $col, $url, $label, $format)
Spreadsheet::WriteExcel

write_url( $row, $col, $url, $format, $label )
Excel::Writer::XLSX

plenv使用環境下です。
$ grep -A 20 'sub write_url ' ${PLENV_ROOT}/versions/5.18.4/lib/perl5/site_perl/5.18.4/Excel/Writer/XLSX/Worksheet.pm 
sub write_url {

    my $self = shift;

    # Check for a cell reference in A1 notation and substitute row and column
    if ( $_[0] =~ /^\D/ ) {
        @_ = $self->_substitute_cellref( @_ );
    }

    if ( @_ < 3 ) { return -1 }    # Check the number of args


    # Reverse the order of $string and $format if necessary. We work on a copy
    # in order to protect the callers args. We don't use "local @_" in case of
    # perl50005 threads.
    my @args = @_;
    ( $args[3], $args[4] ) = ( $args[4], $args[3] ) if ref $args[3];


    my $row       = $args[0];    # Zero indexed row
    my $col       = $args[1];    # Zero indexed column

後方互換のコードは書かれてるけど、pod に書かれた書式に変更しておくのが、大人な対応だろう。

6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8