Excel ファイルのインポートにPHPexcelReaderを使用しています。maxcol 値が 92 の場合はすべて正常に動作しますが、maxcol 値が 206 の場合、Excel ファイルの行数は 150 行であっても 0 と表示されます。
$maxcols=206
echo $data->sheets[0]['numCols']."numcol<br>";//showing 206,its correct
echo $data->sheets[0]['numRows'];//showing 0,incorrect there are 150 rows
print_r($data->sheets[0]['cells']);//showing correctly all the data
echo $maxcols."<br>";
if($data->sheets[0]['numCols'] >= $maxcols)
{
$total_rows=$data->sheets[0]['numRows']-1;
if($total_rows > 0)
{
//my codes
}
}
Reader.php コード:
<?php
define('NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c);
define('SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c);
define('ROOT_START_BLOCK_POS', 0x30);
define('BIG_BLOCK_SIZE', 0x200);
define('SMALL_BLOCK_SIZE', 0x40);
define('EXTENSION_BLOCK_POS', 0x44);
define('NUM_EXTENSION_BLOCK_POS', 0x48);
define('PROPERTY_STORAGE_BLOCK_SIZE', 0x80);
define('BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c);
define('SMALL_BLOCK_THRESHOLD', 0x1000);
// property storage offsets
define('SIZE_OF_NAME_POS', 0x40);
define('TYPE_POS', 0x42);
define('START_BLOCK_POS', 0x74);
define('SIZE_POS', 0x78);
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
define('SPREADSHEET_EXCEL_READER_BIFF8', 0x600);
define('SPREADSHEET_EXCEL_READER_BIFF7', 0x500);
define('SPREADSHEET_EXCEL_READER_WORKBOOKGLOBALS', 0x5);
define('SPREADSHEET_EXCEL_READER_WORKSHEET', 0x10);
define('SPREADSHEET_EXCEL_READER_TYPE_BOF', 0x809);
define('SPREADSHEET_EXCEL_READER_TYPE_EOF', 0x0a);
define('SPREADSHEET_EXCEL_READER_TYPE_BOUNDSHEET', 0x85);
define('SPREADSHEET_EXCEL_READER_TYPE_DIMENSION', 0x200);
define('SPREADSHEET_EXCEL_READER_TYPE_ROW', 0x208);
define('SPREADSHEET_EXCEL_READER_TYPE_DBCELL', 0xd7);
define('SPREADSHEET_EXCEL_READER_TYPE_FILEPASS', 0x2f);
define('SPREADSHEET_EXCEL_READER_TYPE_NOTE', 0x1c);
define('SPREADSHEET_EXCEL_READER_TYPE_TXO', 0x1b6);
define('SPREADSHEET_EXCEL_READER_TYPE_RK', 0x7e);
define('SPREADSHEET_EXCEL_READER_TYPE_RK2', 0x27e);
define('SPREADSHEET_EXCEL_READER_TYPE_MULRK', 0xbd);
define('SPREADSHEET_EXCEL_READER_TYPE_MULBLANK', 0xbe);
define('SPREADSHEET_EXCEL_READER_TYPE_INDEX', 0x20b);
define('SPREADSHEET_EXCEL_READER_TYPE_SST', 0xfc);
define('SPREADSHEET_EXCEL_READER_TYPE_EXTSST', 0xff);
define('SPREADSHEET_EXCEL_READER_TYPE_CONTINUE', 0x3c);
define('SPREADSHEET_EXCEL_READER_TYPE_LABEL', 0x204);
define('SPREADSHEET_EXCEL_READER_TYPE_LABELSST', 0xfd);
define('SPREADSHEET_EXCEL_READER_TYPE_NUMBER', 0x203);
define('SPREADSHEET_EXCEL_READER_TYPE_NAME', 0x18);
define('SPREADSHEET_EXCEL_READER_TYPE_ARRAY', 0x221);
define('SPREADSHEET_EXCEL_READER_TYPE_STRING', 0x207);
define('SPREADSHEET_EXCEL_READER_TYPE_FORMULA', 0x406);
define('SPREADSHEET_EXCEL_READER_TYPE_FORMULA2', 0x6);
define('SPREADSHEET_EXCEL_READER_TYPE_FORMAT', 0x41e);
define('SPREADSHEET_EXCEL_READER_TYPE_XF', 0xe0);
define('SPREADSHEET_EXCEL_READER_TYPE_BOOLERR', 0x205);
define('SPREADSHEET_EXCEL_READER_TYPE_FONT', 0x0031);
define('SPREADSHEET_EXCEL_READER_TYPE_PALETTE', 0x0092);
define('SPREADSHEET_EXCEL_READER_TYPE_UNKNOWN', 0xffff);
define('SPREADSHEET_EXCEL_READER_TYPE_NINETEENFOUR', 0x22);
define('SPREADSHEET_EXCEL_READER_TYPE_MERGEDCELLS', 0xE5);
define('SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS' , 25569);
define('SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904', 24107);
define('SPREADSHEET_EXCEL_READER_MSINADAY', 86400);
define('SPREADSHEET_EXCEL_READER_TYPE_HYPER', 0x01b8);
define('SPREADSHEET_EXCEL_READER_TYPE_COLINFO', 0x7d);
define('SPREADSHEET_EXCEL_READER_TYPE_DEFCOLWIDTH', 0x55);
define('SPREADSHEET_EXCEL_READER_TYPE_STANDARDWIDTH', 0x99);
define('SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT', "%s");
/*
* Main Class
*/
class Spreadsheet_Excel_Reader {
// MK: Added to make data retrieval easier
var $colnames = array();
var $colindexes = array();
var $standardColWidth = 0;
var $defaultColWidth = 0;
function myHex($d) {
if ($d < 16) return "0" . dechex($d);
return dechex($d);
}
function dumpHexData($data, $pos, $length) {
$info = "";
for ($i = 0; $i <= $length; $i++) {
$info .= ($i==0?"":" ") . $this->myHex(ord($data[$pos + $i])) . (ord($data[$pos + $i])>31? "[" . $data[$pos + $i] . "]":'');
}
return $info;
}
function getCol($col) {
if (is_string($col)) {
$col = strtolower($col);
if (array_key_exists($col,$this->colnames)) {
$col = $this->colnames[$col];
}
}
return $col;
}
// PUBLIC API FUNCTIONS
// --------------------
function val($row,$col,$sheet=0) {
$col = $this->getCol($col);
if (array_key_exists($row,$this->sheets[$sheet]['cells']) && array_key_exists($col,$this->sheets[$sheet]['cells'][$row])) {
return $this->sheets[$sheet]['cells'][$row][$col];
}
return "";
}
function value($row,$col,$sheet=0) {
return $this->val($row,$col,$sheet);
}
function info($row,$col,$type='',$sheet=0) {
$col = $this->getCol($col);
if (array_key_exists('cellsInfo',$this->sheets[$sheet])
&& array_key_exists($row,$this->sheets[$sheet]['cellsInfo'])
&& array_key_exists($col,$this->sheets[$sheet]['cellsInfo'][$row])
&& array_key_exists($type,$this->sheets[$sheet]['cellsInfo'][$row][$col])) {
return $this->sheets[$sheet]['cellsInfo'][$row][$col][$type];
}
return "";
}
function type($row,$col,$sheet=0) {
return $this->info($row,$col,'type',$sheet);
}
function raw($row,$col,$sheet=0) {
return $this->info($row,$col,'raw',$sheet);
}
function rowspan($row,$col,$sheet=0) {
$val = $this->info($row,$col,'rowspan',$sheet);
if ($val=="") { return 1; }
return $val;
}
function colspan($row,$col,$sheet=0) {
$val = $this->info($row,$col,'colspan',$sheet);
if ($val=="") { return 1; }
return $val;
}
function hyperlink($row,$col,$sheet=0) {
$link = $this->sheets[$sheet]['cellsInfo'][$row][$col]['hyperlink'];
if ($link) {
return $link['link'];
}
return '';
}
function rowcount($sheet=0) {
return $this->sheets[$sheet]['numRows'];
}
function colcount($sheet=0) {
return $this->sheets[$sheet]['numCols'];
}
function colwidth($col,$sheet=0) {
// Col width is actually the width of the number 0. So we have to estimate and come close
return $this->colInfo[$sheet][$col]['width']/9142*200;
}
function colhidden($col,$sheet=0) {
return !!$this->colInfo[$sheet][$col]['hidden'];
}
function rowheight($row,$sheet=0) {
return $this->rowInfo[$sheet][$row]['height'];
}
function rowhidden($row,$sheet=0) {
return !!$this->rowInfo[$sheet][$row]['hidden'];
}
// CELL (XF) PROPERTIES
// ====================
function xfRecord($row,$col,$sheet=0) {
$xfIndex = $this->info($row,$col,'xfIndex',$sheet);
if ($xfIndex!="") {
return $this->xfRecords[$xfIndex];
}
return null;
}
function xfProperty($row,$col,$sheet,$prop) {
$xfRecord = $this->xfRecord($row,$col,$sheet);
if ($xfRecord!=null) {
return $xfRecord[$prop];
}
return "";
}
// DUMP AN HTML TABLE OF THE ENTIRE XLS DATA
// =========================================
function dump($row_numbers=false,$col_letters=false,$sheet=0,$table_class='excel') {
$out = "<table class=\"$table_class\" cellspacing=0>";
if ($col_letters) {
$out .= "<thead>\n\t<tr>";
if ($row_numbers) {
$out .= "\n\t\t<th> </th>";
}
for($i=1;$i<=$this->colcount($sheet);$i++) {
$style = "width:" . ($this->colwidth($i,$sheet)*1) . "px;";
if ($this->colhidden($i,$sheet)) {
$style .= "display:none;";
}
$out .= "\n\t\t<th style=\"$style\">" . strtoupper($this->colindexes[$i]) . "</th>";
}
$out .= "</tr></thead>\n";
}
$out .= "<tbody>\n";
for($row=1;$row<=$this->rowcount($sheet);$row++) {
$rowheight = $this->rowheight($row,$sheet);
$style = "height:" . ($rowheight*(4/3)) . "px;";
if ($this->rowhidden($row,$sheet)) {
$style .= "display:none;";
}
$out .= "\n\t<tr style=\"$style\">";
if ($row_numbers) {
$out .= "\n\t\t<th>$row</th>";
}
for($col=1;$col<=$this->colcount($sheet);$col++) {
// Account for Rowspans/Colspans
$rowspan = $this->rowspan($row,$col,$sheet);
$colspan = $this->colspan($row,$col,$sheet);
for($i=0;$i<$rowspan;$i++) {
for($j=0;$j<$colspan;$j++) {
if ($i>0 || $j>0) {
$this->sheets[$sheet]['cellsInfo'][$row+$i][$col+$j]['dontprint']=1;
}
}
}
if(!$this->sheets[$sheet]['cellsInfo'][$row][$col]['dontprint']) {
$style = $this->style($row,$col,$sheet);
if ($this->colhidden($col,$sheet)) {
$style .= "display:none;";
}
$out .= "\n\t\t<td style=\"$style\"" . ($colspan > 1?" colspan=$colspan":"") . ($rowspan > 1?" rowspan=$rowspan":"") . ">";
$val = $this->val($row,$col,$sheet);
if ($val=='') { $val=" "; }
else {
$val = htmlentities($val);
$link = $this->hyperlink($row,$col,$sheet);
if ($link!='') {
$val = "<a href=\"$link\">$val</a>";
}
}
$out .= "<nobr>".nl2br($val)."</nobr>";
$out .= "</td>";
}
}
$out .= "</tr>\n";
}
$out .= "</tbody></table>";
return $out;
}
// --------------
// END PUBLIC API
var $boundsheets = array();
var $formatRecords = array();
var $fontRecords = array();
var $xfRecords = array();
var $colInfo = array();
var $rowInfo = array();
var $sst = array();
var $sheets = array();
var $data;
var $_ole;
var $_defaultEncoding = "UTF-8";
var $_defaultFormat = SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT;
var $_columnsFormat = array();
var $_rowoffset = 1;
var $_coloffset = 1;
/**
* List of default date formats used by Excel
*/
var $dateFormats = array (
0xe => "m/d/Y",
0xf => "M-d-Y",
0x10 => "d-M",
0x11 => "M-Y",
0x12 => "h:i a",
0x13 => "h:i:s a",
0x14 => "H:i",
0x15 => "H:i:s",
0x16 => "d/m/Y H:i",
0x2d => "i:s",
0x2e => "H:i:s",
0x2f => "i:s.S"
);
/**
* Default number formats used by Excel
*/
* Read the spreadsheet file using OLE, then parse
*/
function read($sFileName) {
$res = $this->_ole->read($sFileName);
// oops, something goes wrong (Darko Miljanovic)
if($res === false) {
// check error code
if($this->_ole->error == 1) {
// bad file
die('The filename ' . $sFileName . ' is not readable');
}
// check other error codes here (eg bad fileformat, etc...)
}
$this->data = $this->_ole->getWorkBook();
$this->_parse();
}
/**
* Parse a workbook
*
* @access private
* @return bool
*/
function _parse() {
$pos = 0;
$data = $this->data;
$code = v($data,$pos);
$length = v($data,$pos+2);
$version = v($data,$pos+4);
$substreamType = v($data,$pos+6);
$this->version = $version;
if (($version != SPREADSHEET_EXCEL_READER_BIFF8) &&
($version != SPREADSHEET_EXCEL_READER_BIFF7)) {
return false;
}
if ($substreamType != SPREADSHEET_EXCEL_READER_WORKBOOKGLOBALS){
return false;
}
$pos += $length + 4;
$code = v($data,$pos);
$length = v($data,$pos+2);
while ($code != SPREADSHEET_EXCEL_READER_TYPE_EOF) {
switch ($code) {
case SPREADSHEET_EXCEL_READER_TYPE_SST:
$spos = $pos + 4;
$limitpos = $spos + $length;
$uniqueStrings = $this->_GetInt4d($data, $spos+4);
$spos += 8;
for ($i = 0; $i < $uniqueStrings; $i++) {
// Read in the number of characters
if ($spos == $limitpos) {
$opcode = v($data,$spos);
$conlength = v($data,$spos+2);
if ($opcode != 0x3c) {
return -1;
}
$spos += 4;
$limitpos = $spos + $conlength;
}
$numChars = ord($data[$spos]) | (ord($data[$spos+1]) << 8);
$spos += 2;
$optionFlags = ord($data[$spos]);
$spos++;
$asciiEncoding = (($optionFlags & 0x01) == 0) ;
$extendedString = ( ($optionFlags & 0x04) != 0);
// See if string contains formatting information
$richString = ( ($optionFlags & 0x08) != 0);
if ($richString) {
// Read in the crun
$formattingRuns = v($data,$spos);
$spos += 2;
}
if ($extendedString) {
// Read in cchExtRst
$extendedRunLength = $this->_GetInt4d($data, $spos);
$spos += 4;
}
$len = ($asciiEncoding)? $numChars : $numChars*2;
if ($spos + $len < $limitpos) {
$retstr = substr($data, $spos, $len);
$spos += $len;
}
else{
// found countinue
$retstr = substr($data, $spos, $limitpos - $spos);
$bytesRead = $limitpos - $spos;
$charsLeft = $numChars - (($asciiEncoding) ? $bytesRead : ($bytesRead / 2));
$spos = $limitpos;
while ($charsLeft > 0){
$opcode = v($data,$spos);
$conlength = v($data,$spos+2);
if ($opcode != 0x3c) {
return -1;
}
$spos += 4;
$limitpos = $spos + $conlength;
$option = ord($data[$spos]);
$spos += 1;
if ($asciiEncoding && ($option == 0)) {
$len = min($charsLeft, $limitpos - $spos); // min($charsLeft, $conlength);
$retstr .= substr($data, $spos, $len);
$charsLeft -= $len;
$asciiEncoding = true;
}
elseif (!$asciiEncoding && ($option != 0)) {
$len = min($charsLeft * 2, $limitpos - $spos); // min($charsLeft, $conlength);
$retstr .= substr($data, $spos, $len);
$charsLeft -= $len/2;
$asciiEncoding = false;
}
elseif (!$asciiEncoding && ($option == 0)) {
// Bummer - the string starts off as Unicode, but after the
// continuation it is in straightforward ASCII encoding
$len = min($charsLeft, $limitpos - $spos); // min($charsLeft, $conlength);
for ($j = 0; $j < $len; $j++) {
$retstr .= $data[$spos + $j].chr(0);
}
$charsLeft -= $len;
$asciiEncoding = false;
}
else{
$newstr = '';
for ($j = 0; $j < strlen($retstr); $j++) {
$newstr = $retstr[$j].chr(0);
}
$retstr = $newstr;
$len = min($charsLeft * 2, $limitpos - $spos); // min($charsLeft, $conlength);
$retstr .= substr($data, $spos, $len);
$charsLeft -= $len/2;
$asciiEncoding = false;
}
$spos += $len;
}
}
$retstr = ($asciiEncoding) ? $retstr : $this->_encodeUTF16($retstr);
if ($richString){
$spos += 4 * $formattingRuns;
}
// For extended strings, skip over the extended string data
if ($extendedString) {
$spos += $extendedRunLength;
}
$this->sst[]=$retstr;
}
break;
case SPREADSHEET_EXCEL_READER_TYPE_FILEPASS:
return false;
break;
case SPREADSHEET_EXCEL_READER_TYPE_NAME:
break;
case SPREADSHEET_EXCEL_READER_TYPE_FORMAT:
$indexCode = v($data,$pos+4);
if ($version == SPREADSHEET_EXCEL_READER_BIFF8) {
$numchars = v($data,$pos+6);
if (ord($data[$pos+8]) == 0){
$formatString = substr($data, $pos+9, $numchars);
} else {
$formatString = substr($data, $pos+9, $numchars*2);
}
} else {
$numchars = ord($data[$pos+6]);
$formatString = substr($data, $pos+7, $numchars*2);
}
$this->formatRecords[$indexCode] = $formatString;
break;
}
}
?>
何が欠けているか、または問題を解決するにはどうすればよいですか?
前もって感謝します。