トップ «前の日記(2004-09-25) 最新 次の日記(2004-09-27)» 編集

Pyon's Diary

[はてなブックマーク登録数] [Google に登録] [RSS フィード] Gourmet Hardware Programming Society Software
成る可くJIS X 0213:2004對應MSフォント(5.0)、IPAフォント(003.02)で御覽下さい

2004-09-26 舊 平成拾陸年葉月拾參日 (雨) [長年日記]

[節] 徹夜明け。

一旦歸宅。

寢る。

午後出社豫定。

Tags: None | del.icio.usに追加 | はてなブックマークに追加 | livedoor クリップに追加 | Yahoo! ブックマークに追加 | Google ブックマークに追加 | Permalink

[節] 休日出勤。

晝過ぎに起きて出社。けふのFULL SWINGの演奏會はち○っ○に一人で聽きに行つて貰ふ事に。今週も酷い週に成り然うだなあ。

Tags: None | del.icio.usに追加 | はてなブックマークに追加 | livedoor クリップに追加 | Yahoo! ブックマークに追加 | Google ブックマークに追加 | Permalink

[節] PerlでExcelファイルを読む。(Spreadsheet::ParseExcel)

PerlでExcelファイルを讀む爲のモジュール。Linux上のPerlで直接Excelファイルを讀む事が出來るのがミソ。Excelファイルを一々CSVに變換し無くても直接讀込めるので便利。此方作者に據る解説之頁。

一枚のシートに日本語・簡體字・繁體字・ハングルの混じつたファイルを讀む爲にはFmtUnicodeを用ひ無いと駄目の樣子。

セル(Spreadsheet::ParseExcel::Cell)のプロパティで覺えて措くのはValue, Val, Type, Code位か。

  • Value -- 書式が適用された値。
  • Val -- 書式が適用されてゐ無い元の値。
  • Type -- 値の形式。('Text' -- テキスト, 'Numeric' -- 数値, 'Date' -- 日付)
  • Code -- エンコーディング。(undef -- ASCII, 'ucs2' -- UCS2-BE, '_native_' -- Shift_JIS )*1

注意事項。

セルの中身に據つてエンコーディングが異なるので、注意が必要。

以下のコードで變數$cellはSpreadsheet::ParseExcel::Cellのインスタンス。

use utf8;
use strict;
use Encode qw/decode encode/;
use Encode::JP;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode;
(中略)
# セルのエンコーディングをチェックする。
# 値が定義されていなければ ASCII。
my $val;
if (! defined($cell->{Code})) {
    $val = &decode("ascii", $cell->Value);
}
# 値が定義されていれば UCS2 か Shift_JIS
elsif ($cell->{Code} eq 'ucs2') {
    $val = &decode("UCS2-BE", $cell->Value);
}
elsif ($cell->{Code} eq '_native_') {
    $val = &decode("shiftjis", $cell->Value);
}
# どれにも當て嵌まらなければ不明なエンコーディング。
else {
    warn(sprintf("Unknown encoding. (%d, %d)", $row, $col));
}

此れで變數$valにセルの中身が文字化けせずに入る。

Tags: Programming | del.icio.usに追加 | はてなブックマークに追加 | livedoor クリップに追加 | Yahoo! ブックマークに追加 | Google ブックマークに追加 | Permalink

*1  "seem to be" と書かれてゐたので「確實では無い」のだと思はれる。

[節] PHP-ExcelReader. (No.1)

PHPでExcelのファイルを讀む爲のクラス。此方が日本語に據る解説。何故か愛生会へのリンクが有る。

mb_convert_encoding()を使用する (iconvでは無くて)

日本語・簡體字・繁體字・ハングルの入雑じつたExcelファイルを讀込ませて表示させてみたら酷く文字化けした。結構な時間調べてみたらreader.phpでiconvを使用してUTF-16LE (Excelの内部エンコード?)を所定のエンコードに變換してゐる箇所が在つた。會社で使用してゐる計算機ではPHPをiconv付きで構築する事が出來無かつたので、其部分をmb_convert_encoding()を使用する樣に手を入れたら良く成つた。

> *** reader.php.org  Sat Sep 11 18:31:00 2004
> --- reader.php  Mon Sep 27 16:05:21 2004
> ***************
> *** 137,143 ****
> 
>       function read($sFileName) {
>         $errlevel = error_reporting();
> !       error_reporting($errlevel ^ E_NOTICE);
> 
>           $res = $this->_ole->read($sFileName);
> 
> --- 137,144 ----
> 
>       function read($sFileName) {
>         $errlevel = error_reporting();
> !       //      error_reporting($errlevel ^ E_NOTICE);
> !       error_reporting($errlevel ^ E_ERROR);
> 
>           $res = $this->_ole->read($sFileName);
> 
> ***************
> *** 767,773 ****
> --- 768,783 ----
> 
>       function _encodeUTF16($string){
>           if ($this->_defaultEncoding){
> +           //  It is better to use mb_convert_encoding rather than using iconv.
> +           //  If it is why mb_convert_encoding since it is the extended module of PHP.
> +           //  In order to use mb_convert_encoding As the option of configure
> +           //  what is necessary is to attach --enable-mbstring and just to compile.
> +           /*
>               return (Spreadsheet_Excel_Reader_HAVE_ICONV) ? iconv('UTF-16LE', $this->_defaultEncod\
> ing, $string): $string;
> +           */
> +           return mb_convert_encoding ( $string,
> +                                        $this->_defaultEncoding,
> +                                        'UTF-16LE' );
>           }else{
>               return $string;
>           }

自分の作業環境をFreeBSDでは無くてLinuxにし度ひなあ。(No.2へ)

Tags: Software | del.icio.usに追加 | はてなブックマークに追加 | livedoor クリップに追加 | Yahoo! ブックマークに追加 | Google ブックマークに追加 | Permalink

[節] 歸宅。

徹夜する氣だつたけれど、どうも氣力が失せて仕舞つた。

そろゝゝ休養が必要かもな。

Tags: None | del.icio.usに追加 | はてなブックマークに追加 | livedoor クリップに追加 | Yahoo! ブックマークに追加 | Google ブックマークに追加 | Permalink
[]

© pyon