2015年6月25日木曜日

PHP Excel Reader 日本語が入るとエラー?

PHP Excel Readerで読み込むとデータ件数が0になってしまう現象が発生。
var_dumpすると["sheets"]の配列要素数が0。
どうも日本語が入っているとダメな気がする。
reader.phpのSpreadsheet_Excel_Readerクラスのparese()メソッドを調べ、
return -1で戻る条件を元にネット上を探してたら以下の修正コードに辿り着きました。

reader.phpの470行目付近です。
// Add this line とコメントしている箇所を追加してください。

$uniqueStrings = $this->_GetInt4d($this->data, $spos+4);
                    $spos += 8;
                    for ($i = 0; $i < $uniqueStrings; $i++) {
                       // Special case of buggy excel 2003: Continue Opcode between string & richData
                        if ($spos > $limitpos) { // Add this line
                            $tmp_offset=$spos-$limitpos; // Add this line
                            $spos=$limitpos; // Add this line
                        } else { // Add this line
                            $tmp_offset=0; // Add this line
                        } // Add this line
                        // Read in the number of characters
                        if ($spos == $limitpos) {
                            $opcode = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8 p="">                            $conlength = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8 p="">                            if ($opcode != 0x3c) {
                                return -1;
                            }
                            $spos += 4;
                            $limitpos = $spos + $conlength;
                            $spos += $tmp_offset; // Add this line
                        }