update lib/Excel

This commit is contained in:
Amberstone 2024-09-19 20:44:10 +09:00
parent 4cf3aeeb88
commit 42663073c5
Signed by: amber
GPG key ID: 094B0E55F98D8BF1
10 changed files with 1373 additions and 1391 deletions

Binary file not shown.

View file

@ -1,271 +1,270 @@
<?php <?php
define('NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c); define('NUM_BIG_BLOCK_DEPOT_BLOCKS_POS', 0x2c);
define('SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c); define('SMALL_BLOCK_DEPOT_BLOCK_POS', 0x3c);
define('ROOT_START_BLOCK_POS', 0x30); define('ROOT_START_BLOCK_POS', 0x30);
define('BIG_BLOCK_SIZE', 0x200); define('BIG_BLOCK_SIZE', 0x200);
define('SMALL_BLOCK_SIZE', 0x40); define('SMALL_BLOCK_SIZE', 0x40);
define('EXTENSION_BLOCK_POS', 0x44); define('EXTENSION_BLOCK_POS', 0x44);
define('NUM_EXTENSION_BLOCK_POS', 0x48); define('NUM_EXTENSION_BLOCK_POS', 0x48);
define('PROPERTY_STORAGE_BLOCK_SIZE', 0x80); define('PROPERTY_STORAGE_BLOCK_SIZE', 0x80);
define('BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c); define('BIG_BLOCK_DEPOT_BLOCKS_POS', 0x4c);
define('SMALL_BLOCK_THRESHOLD', 0x1000); define('SMALL_BLOCK_THRESHOLD', 0x1000);
// property storage offsets // property storage offsets
define('SIZE_OF_NAME_POS', 0x40); define('SIZE_OF_NAME_POS', 0x40);
define('TYPE_POS', 0x42); define('TYPE_POS', 0x42);
define('START_BLOCK_POS', 0x74); define('START_BLOCK_POS', 0x74);
define('SIZE_POS', 0x78); define('SIZE_POS', 0x78);
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1)); define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
//echo 'ROOT_START_BLOCK_POS = '.ROOT_START_BLOCK_POS."\n"; //echo 'ROOT_START_BLOCK_POS = '.ROOT_START_BLOCK_POS."\n";
//echo bin2hex($data[ROOT_START_BLOCK_POS])."\n"; //echo bin2hex($data[ROOT_START_BLOCK_POS])."\n";
//echo "a="; //echo "a=";
//echo $data[ROOT_START_BLOCK_POS]; //echo $data[ROOT_START_BLOCK_POS];
//function log //function log
function GetInt4d($data, $pos) function GetInt4d($data, $pos)
{ {
$value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24); $value = ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
if ($value>=4294967294) if ($value>=4294967294)
{ {
$value=-2; $value=-2;
} }
return $value; return $value;
} }
class OLERead { class OLERead {
var $data = ''; var $data = '';
function OLERead(){ function OLERead(){
} }
function read($sFileName){ function read($sFileName){
// check if file exist and is readable (Darko Miljanovic) // check if file exist and is readable (Darko Miljanovic)
if(!is_readable($sFileName)) { if(!is_readable($sFileName)) {
$this->error = 1; $this->error = 1;
return false; return false;
} }
$this->data = @file_get_contents($sFileName); $this->data = @file_get_contents($sFileName);
if (!$this->data) { if (!$this->data) {
$this->error = 1; $this->error = 1;
return false; return false;
} }
//echo IDENTIFIER_OLE; //echo IDENTIFIER_OLE;
//echo 'start'; //echo 'start';
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) { if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
$this->error = 1; $this->error = 1;
return false; return false;
} }
$this->numBigBlockDepotBlocks = GetInt4d($this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS); $this->numBigBlockDepotBlocks = GetInt4d($this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
$this->sbdStartBlock = GetInt4d($this->data, SMALL_BLOCK_DEPOT_BLOCK_POS); $this->sbdStartBlock = GetInt4d($this->data, SMALL_BLOCK_DEPOT_BLOCK_POS);
$this->rootStartBlock = GetInt4d($this->data, ROOT_START_BLOCK_POS); $this->rootStartBlock = GetInt4d($this->data, ROOT_START_BLOCK_POS);
$this->extensionBlock = GetInt4d($this->data, EXTENSION_BLOCK_POS); $this->extensionBlock = GetInt4d($this->data, EXTENSION_BLOCK_POS);
$this->numExtensionBlocks = GetInt4d($this->data, NUM_EXTENSION_BLOCK_POS); $this->numExtensionBlocks = GetInt4d($this->data, NUM_EXTENSION_BLOCK_POS);
/* /*
echo $this->numBigBlockDepotBlocks." "; echo $this->numBigBlockDepotBlocks." ";
echo $this->sbdStartBlock." "; echo $this->sbdStartBlock." ";
echo $this->rootStartBlock." "; echo $this->rootStartBlock." ";
echo $this->extensionBlock." "; echo $this->extensionBlock." ";
echo $this->numExtensionBlocks." "; echo $this->numExtensionBlocks." ";
*/ */
//echo "sbdStartBlock = $this->sbdStartBlock\n"; //echo "sbdStartBlock = $this->sbdStartBlock\n";
$bigBlockDepotBlocks = array(); $bigBlockDepotBlocks = array();
$pos = BIG_BLOCK_DEPOT_BLOCKS_POS; $pos = BIG_BLOCK_DEPOT_BLOCKS_POS;
// echo "pos = $pos"; // echo "pos = $pos";
$bbdBlocks = $this->numBigBlockDepotBlocks; $bbdBlocks = $this->numBigBlockDepotBlocks;
if ($this->numExtensionBlocks != 0) { if ($this->numExtensionBlocks != 0) {
$bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4; $bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
} }
for ($i = 0; $i < $bbdBlocks; $i++) { for ($i = 0; $i < $bbdBlocks; $i++) {
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos); $bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
$pos += 4; $pos += 4;
} }
for ($j = 0; $j < $this->numExtensionBlocks; $j++) { for ($j = 0; $j < $this->numExtensionBlocks; $j++) {
$pos = ($this->extensionBlock + 1) * BIG_BLOCK_SIZE; $pos = ($this->extensionBlock + 1) * BIG_BLOCK_SIZE;
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, BIG_BLOCK_SIZE / 4 - 1); $blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, BIG_BLOCK_SIZE / 4 - 1);
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) { for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) {
$bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos); $bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
$pos += 4; $pos += 4;
} }
$bbdBlocks += $blocksToRead; $bbdBlocks += $blocksToRead;
if ($bbdBlocks < $this->numBigBlockDepotBlocks) { if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
$this->extensionBlock = GetInt4d($this->data, $pos); $this->extensionBlock = GetInt4d($this->data, $pos);
} }
} }
// var_dump($bigBlockDepotBlocks); // var_dump($bigBlockDepotBlocks);
// readBigBlockDepot // readBigBlockDepot
$pos = 0; $pos = 0;
$index = 0; $index = 0;
$this->bigBlockChain = array(); $this->bigBlockChain = array();
for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) { for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * BIG_BLOCK_SIZE; $pos = ($bigBlockDepotBlocks[$i] + 1) * BIG_BLOCK_SIZE;
//echo "pos = $pos"; //echo "pos = $pos";
for ($j = 0 ; $j < BIG_BLOCK_SIZE / 4; $j++) { for ($j = 0 ; $j < BIG_BLOCK_SIZE / 4; $j++) {
$this->bigBlockChain[$index] = GetInt4d($this->data, $pos); $this->bigBlockChain[$index] = GetInt4d($this->data, $pos);
$pos += 4 ; $pos += 4 ;
$index++; $index++;
} }
} }
//var_dump($this->bigBlockChain); //var_dump($this->bigBlockChain);
//echo '=====2'; //echo '=====2';
// readSmallBlockDepot(); // readSmallBlockDepot();
$pos = 0; $pos = 0;
$index = 0; $index = 0;
$sbdBlock = $this->sbdStartBlock; $sbdBlock = $this->sbdStartBlock;
$this->smallBlockChain = array(); $this->smallBlockChain = array();
while ($sbdBlock != -2) { while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * BIG_BLOCK_SIZE; $pos = ($sbdBlock + 1) * BIG_BLOCK_SIZE;
for ($j = 0; $j < BIG_BLOCK_SIZE / 4; $j++) { for ($j = 0; $j < BIG_BLOCK_SIZE / 4; $j++) {
$this->smallBlockChain[$index] = GetInt4d($this->data, $pos); $this->smallBlockChain[$index] = GetInt4d($this->data, $pos);
$pos += 4; $pos += 4;
$index++; $index++;
} }
$sbdBlock = $this->bigBlockChain[$sbdBlock]; $sbdBlock = $this->bigBlockChain[$sbdBlock];
} }
// readData(rootStartBlock) // readData(rootStartBlock)
$block = $this->rootStartBlock; $block = $this->rootStartBlock;
$pos = 0; $pos = 0;
$this->entry = $this->__readData($block); $this->entry = $this->__readData($block);
/* /*
while ($block != -2) { while ($block != -2) {
$pos = ($block + 1) * BIG_BLOCK_SIZE; $pos = ($block + 1) * BIG_BLOCK_SIZE;
$this->entry = $this->entry.substr($this->data, $pos, BIG_BLOCK_SIZE); $this->entry = $this->entry.substr($this->data, $pos, BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block]; $block = $this->bigBlockChain[$block];
} }
*/ */
//echo '==='.$this->entry."==="; //echo '==='.$this->entry."===";
$this->__readPropertySets(); $this->__readPropertySets();
} }
function __readData($bl) { function __readData($bl) {
$block = $bl; $block = $bl;
$pos = 0; $pos = 0;
$data = ''; $data = '';
while ($block != -2) { while ($block != -2) {
$pos = ($block + 1) * BIG_BLOCK_SIZE; $pos = ($block + 1) * BIG_BLOCK_SIZE;
$data = $data.substr($this->data, $pos, BIG_BLOCK_SIZE); $data = $data.substr($this->data, $pos, BIG_BLOCK_SIZE);
//echo "pos = $pos data=$data\n"; //echo "pos = $pos data=$data\n";
$block = $this->bigBlockChain[$block]; $block = $this->bigBlockChain[$block];
} }
return $data; return $data;
} }
function __readPropertySets(){ function __readPropertySets(){
$offset = 0; $offset = 0;
//var_dump($this->entry); //var_dump($this->entry);
while ($offset < strlen($this->entry)) { while ($offset < strlen($this->entry)) {
$d = substr($this->entry, $offset, PROPERTY_STORAGE_BLOCK_SIZE); $d = substr($this->entry, $offset, PROPERTY_STORAGE_BLOCK_SIZE);
$nameSize = ord($d[SIZE_OF_NAME_POS]) | (ord($d[SIZE_OF_NAME_POS+1]) << 8); $nameSize = ord($d[SIZE_OF_NAME_POS]) | (ord($d[SIZE_OF_NAME_POS+1]) << 8);
$type = ord($d[TYPE_POS]); $type = ord($d[TYPE_POS]);
//$maxBlock = strlen($d) / BIG_BLOCK_SIZE - 1; //$maxBlock = strlen($d) / BIG_BLOCK_SIZE - 1;
$startBlock = GetInt4d($d, START_BLOCK_POS); $startBlock = GetInt4d($d, START_BLOCK_POS);
$size = GetInt4d($d, SIZE_POS); $size = GetInt4d($d, SIZE_POS);
$name = ''; $name = '';
for ($i = 0; $i < $nameSize ; $i++) { for ($i = 0; $i < $nameSize ; $i++) {
$name .= $d[$i]; $name .= $d[$i];
} }
$name = str_replace("\x00", "", $name); $name = str_replace("\x00", "", $name);
$this->props[] = array ( $this->props[] = array (
'name' => $name, 'name' => $name,
'type' => $type, 'type' => $type,
'startBlock' => $startBlock, 'startBlock' => $startBlock,
'size' => $size); 'size' => $size);
if (($name == "Workbook") || ($name == "Book")) { if (($name == "Workbook") || ($name == "Book")) {
$this->wrkbook = count($this->props) - 1; $this->wrkbook = count($this->props) - 1;
} }
if ($name == "Root Entry") { if ($name == "Root Entry") {
$this->rootentry = count($this->props) - 1; $this->rootentry = count($this->props) - 1;
} }
//echo "name ==$name=\n"; //echo "name ==$name=\n";
$offset += PROPERTY_STORAGE_BLOCK_SIZE; $offset += PROPERTY_STORAGE_BLOCK_SIZE;
} }
} }
function getWorkBook(){ function getWorkBook(){
if ($this->props[$this->wrkbook]['size'] < SMALL_BLOCK_THRESHOLD){ if ($this->props[$this->wrkbook]['size'] < SMALL_BLOCK_THRESHOLD){
// getSmallBlockStream(PropertyStorage ps) // getSmallBlockStream(PropertyStorage ps)
$rootdata = $this->__readData($this->props[$this->rootentry]['startBlock']); $rootdata = $this->__readData($this->props[$this->rootentry]['startBlock']);
$streamData = ''; $streamData = '';
$block = $this->props[$this->wrkbook]['startBlock']; $block = $this->props[$this->wrkbook]['startBlock'];
//$count = 0; //$count = 0;
$pos = 0; $pos = 0;
while ($block != -2) { while ($block != -2) {
$pos = $block * SMALL_BLOCK_SIZE; $pos = $block * SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE); $streamData .= substr($rootdata, $pos, SMALL_BLOCK_SIZE);
$block = $this->smallBlockChain[$block]; $block = $this->smallBlockChain[$block];
} }
return $streamData; return $streamData;
}else{ }else{
$numBlocks = $this->props[$this->wrkbook]['size'] / BIG_BLOCK_SIZE; $numBlocks = $this->props[$this->wrkbook]['size'] / BIG_BLOCK_SIZE;
if ($this->props[$this->wrkbook]['size'] % BIG_BLOCK_SIZE != 0) { if ($this->props[$this->wrkbook]['size'] % BIG_BLOCK_SIZE != 0) {
$numBlocks++; $numBlocks++;
} }
if ($numBlocks == 0) return ''; if ($numBlocks == 0) return '';
//echo "numBlocks = $numBlocks\n"; //echo "numBlocks = $numBlocks\n";
//byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE]; //byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE];
//print_r($this->wrkbook); //print_r($this->wrkbook);
$streamData = ''; $streamData = '';
$block = $this->props[$this->wrkbook]['startBlock']; $block = $this->props[$this->wrkbook]['startBlock'];
//$count = 0; //$count = 0;
$pos = 0; $pos = 0;
//echo "block = $block"; //echo "block = $block";
while ($block != -2) { while ($block != -2) {
$pos = ($block + 1) * BIG_BLOCK_SIZE; $pos = ($block + 1) * BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, BIG_BLOCK_SIZE); $streamData .= substr($this->data, $pos, BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block]; $block = $this->bigBlockChain[$block];
} }
//echo 'stream'.$streamData; //echo 'stream'.$streamData;
return $streamData; return $streamData;
} }
} }
} }
?>

View file

@ -204,6 +204,4 @@ class writeexcel_biffwriter {
return $tmp; return $tmp;
} }
} }
?>

View file

@ -690,6 +690,4 @@ class writeexcel_format {
$this->_right_color=$this->_get_color($color); $this->_right_color=$this->_get_color($color);
} }
} }
?>

View file

@ -153,7 +153,7 @@ function parse_formula() {
$this->_formula = $formula; $this->_formula = $formula;
$this->_current_char = 0; $this->_current_char = 0;
$this->_lookahead = $this->_formula{1}; $this->_lookahead = $this->_formula[1];
$this->_advance($formula); $this->_advance($formula);
$parsetree = $this->_condition(); $parsetree = $this->_condition();
@ -663,10 +663,10 @@ function _convertRange2d($range)
// Split the range into 2 cell refs // Split the range into 2 cell refs
if (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)\:\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$range)) { if (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)\:\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$range)) {
list($cell1, $cell2) = split(':', $range); list($cell1, $cell2) = explode(':', $range);
} }
elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)\.\.\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$range)) { elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)\.\.\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$range)) {
list($cell1, $cell2) = split('\.\.', $range); list($cell1, $cell2) = preg_split('/\.\./', $range);
} }
else { else {
// TODO: use real error codes // TODO: use real error codes
@ -714,7 +714,7 @@ function _convertRange3d($token)
$class = 2; // as far as I know, this is magick. $class = 2; // as far as I know, this is magick.
// Split the ref at the ! symbol // Split the ref at the ! symbol
list($ext_ref, $range) = split('!', $token); list($ext_ref, $range) = explode('!', $token);
// Convert the external reference part // Convert the external reference part
$ext_ref = $this->_packExtRef($ext_ref); $ext_ref = $this->_packExtRef($ext_ref);
@ -723,7 +723,7 @@ function _convertRange3d($token)
} }
// Split the range into 2 cell refs // Split the range into 2 cell refs
list($cell1, $cell2) = split(':', $range); list($cell1, $cell2) = explode(':', $range);
// Convert the cell references // Convert the cell references
if (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/', $cell1)) if (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/', $cell1))
@ -812,7 +812,7 @@ function _convertRef3d($cell)
$class = 2; // as far as I know, this is magick. $class = 2; // as far as I know, this is magick.
// Split the ref at the ! symbol // Split the ref at the ! symbol
list($ext_ref, $cell) = split('!', $cell); list($ext_ref, $cell) = explode('!', $cell);
// Convert the external reference part // Convert the external reference part
$ext_ref = $this->_packExtRef($ext_ref); $ext_ref = $this->_packExtRef($ext_ref);
@ -853,7 +853,7 @@ function _packExtRef($ext_ref) {
// Check if there is a sheet range eg., Sheet1:Sheet2. // Check if there is a sheet range eg., Sheet1:Sheet2.
if (preg_match("/:/", $ext_ref)) if (preg_match("/:/", $ext_ref))
{ {
list($sheet_name1, $sheet_name2) = split(':', $ext_ref); list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
$sheet1 = $this->_getSheetIndex($sheet_name1); $sheet1 = $this->_getSheetIndex($sheet_name1);
if ($sheet1 == -1) { if ($sheet1 == -1) {
@ -1005,7 +1005,7 @@ function _cellToRowcol($cell)
$col = 0; $col = 0;
for ($i=0; $i < strlen($col_ref); $i++) for ($i=0; $i < strlen($col_ref); $i++)
{ {
$col += (ord($col_ref{$i}) - ord('A') + 1) * pow(26, $expn); $col += (ord($col_ref[$i]) - ord('A') + 1) * pow(26, $expn);
$expn--; $expn--;
} }
@ -1027,19 +1027,19 @@ function _advance()
// eat up white spaces // eat up white spaces
if ($i < strlen($this->_formula)) if ($i < strlen($this->_formula))
{ {
while ($this->_formula{$i} == " ") { while ($this->_formula[$i] == " ") {
$i++; $i++;
} }
if ($i < strlen($this->_formula) - 1) { if ($i < strlen($this->_formula) - 1) {
$this->_lookahead = $this->_formula{$i+1}; $this->_lookahead = $this->_formula[$i+1];
} }
$token = ""; $token = "";
} }
while ($i < strlen($this->_formula)) while ($i < strlen($this->_formula))
{ {
$token .= $this->_formula{$i}; $token .= $this->_formula[$i];
if ($i < strlen($this->_formula) - 1) { if ($i < strlen($this->_formula) - 1) {
$this->_lookahead = $this->_formula{$i+1}; $this->_lookahead = $this->_formula[$i+1];
} }
else { else {
$this->_lookahead = ''; $this->_lookahead = '';
@ -1054,7 +1054,7 @@ function _advance()
return 1; return 1;
} }
if ($i < strlen($this->_formula) - 2) { if ($i < strlen($this->_formula) - 2) {
$this->_lookahead = $this->_formula{$i+2}; $this->_lookahead = $this->_formula[$i+2];
} }
else { else {
// if we run out of characters _lookahead becomes empty // if we run out of characters _lookahead becomes empty
@ -1195,7 +1195,7 @@ function parse($formula)
{ {
$this->_current_char = 0; $this->_current_char = 0;
$this->_formula = $formula; $this->_formula = $formula;
$this->_lookahead = $formula{1}; $this->_lookahead = $formula[1];
$this->_advance(); $this->_advance();
$this->_parse_tree = $this->_condition(); $this->_parse_tree = $this->_condition();
if ($this->isError($this->_parse_tree)) { if ($this->isError($this->_parse_tree)) {
@ -1604,7 +1604,4 @@ function toReversePolish($tree = array())
return $polish; return $polish;
} }
} }
?>

View file

@ -348,6 +348,4 @@ class writeexcel_olewriter {
} }
} }
} }
?>

View file

@ -1144,6 +1144,4 @@ function _store_codepage() {
$this->_append($header.$data); $this->_append($header.$data);
} }
} }
?>

View file

@ -50,6 +50,4 @@ class writeexcel_workbookbig extends writeexcel_workbook {
$ole->save($this->_filename); $ole->save($this->_filename);
} }
} }
?>

View file

@ -2963,6 +2963,4 @@ function insert_bitmap() {
$this->_append($header . $data); $this->_append($header . $data);
} }
} }
?>

File diff suppressed because it is too large Load diff