sms5 추가

This commit is contained in:
chicpro
2014-03-20 14:51:51 +09:00
parent 41a3385e99
commit bcc013bdcf
80 changed files with 16733 additions and 14 deletions

View File

@ -0,0 +1,209 @@
<?php
/*
* Copyleft 2002 Johann Hanne
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
*/
class writeexcel_biffwriter {
var $byte_order;
var $BIFF_version;
var $_byte_order;
var $_data;
var $_datasize;
var $_limit;
var $_debug;
/*
* Constructor
*/
function writeexcel_biffwriter() {
$this->byte_order = '';
$this->BIFF_version = 0x0500;
$this->_byte_order = '';
$this->_data = false;
$this->_datasize = 0;
$this->_limit = 2080;
$this->_set_byte_order();
}
/*
* Determine the byte order and store it as class data to avoid
* recalculating it for each call to new().
*/
function _set_byte_order() {
$this->byteorder=0;
// Check if "pack" gives the required IEEE 64bit float
$teststr = pack("d", 1.2345);
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
if ($number == $teststr) {
$this->byte_order = 0; // Little Endian
} elseif ($number == strrev($teststr)) {
$this->byte_order = 1; // Big Endian
} else {
// Give up
trigger_error("Required floating point format not supported ".
"on this platform. See the portability section ".
"of the documentation.", E_USER_ERROR);
}
$this->_byte_order = $this->byte_order;
}
/*
* General storage function
*/
function _prepend($data) {
if (func_num_args()>1) {
trigger_error("writeexcel_biffwriter::_prepend() ".
"called with more than one argument", E_USER_ERROR);
}
if ($this->_debug) {
print "*** writeexcel_biffwriter::_prepend() called:";
for ($c=0;$c<strlen($data);$c++) {
if ($c%16==0) {
print "\n";
}
printf("%02X ", ord($data[$c]));
}
print "\n";
}
if (strlen($data) > $this->_limit) {
$data = $this->_add_continue($data);
}
$this->_data = $data . $this->_data;
$this->_datasize += strlen($data);
}
/*
* General storage function
*/
function _append($data) {
if (func_num_args()>1) {
trigger_error("writeexcel_biffwriter::_append() ".
"called with more than one argument", E_USER_ERROR);
}
if ($this->_debug) {
print "*** writeexcel_biffwriter::_append() called:";
for ($c=0;$c<strlen($data);$c++) {
if ($c%16==0) {
print "\n";
}
printf("%02X ", ord($data[$c]));
}
print "\n";
}
if (strlen($data) > $this->_limit) {
$data = $this->_add_continue($data);
}
$this->_data = $this->_data . $data;
$this->_datasize += strlen($data);
}
/*
* Writes Excel BOF record to indicate the beginning of a stream or
* sub-stream in the BIFF file.
*
* $type = 0x0005, Workbook
* $type = 0x0010, Worksheet
*/
function _store_bof($type) {
$record = 0x0809; // Record identifier
$length = 0x0008; // Number of bytes to follow
$version = $this->BIFF_version;
// According to the SDK $build and $year should be set to zero.
// However, this throws a warning in Excel 5. So, use these
// magic numbers.
$build = 0x096C;
$year = 0x07C9;
$header = pack("vv", $record, $length);
$data = pack("vvvv", $version, $type, $build, $year);
$this->_prepend($header . $data);
}
/*
* Writes Excel EOF record to indicate the end of a BIFF stream.
*/
function _store_eof() {
$record = 0x000A; // Record identifier
$length = 0x0000; // Number of bytes to follow
$header = pack("vv", $record, $length);
$this->_append($header);
}
/*
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084
* bytes. In Excel 97 the limit is 8228 bytes. Records that are longer
* than these limits must be split up into CONTINUE blocks.
*
* This function take a long BIFF record and inserts CONTINUE records as
* necessary.
*/
function _add_continue($data) {
$limit = $this->_limit;
$record = 0x003C; // Record identifier
// The first 2080/8224 bytes remain intact. However, we have to change
// the length field of the record.
$tmp = substr($data, 0, $limit);
$data = substr($data, $limit);
$tmp = substr($tmp, 0, 2) . pack ("v", $limit-4) . substr($tmp, 4);
// Strip out chunks of 2080/8224 bytes +4 for the header.
while (strlen($data) > $limit) {
$header = pack("vv", $record, $limit);
$tmp .= $header;
$tmp .= substr($data, 0, $limit);
$data = substr($data, $limit);
}
// Mop up the last of the data
$header = pack("vv", $record, strlen($data));
$tmp .= $header;
$tmp .= $data;
return $tmp;
}
}
?>

View File

@ -0,0 +1,695 @@
<?php
/*
* Copyleft 2002 Johann Hanne
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
*/
class writeexcel_format {
var $_xf_index;
var $_font_index;
var $_font;
var $_size;
var $_bold;
var $_italic;
var $_color;
var $_underline;
var $_font_strikeout;
var $_font_outline;
var $_font_shadow;
var $_font_script;
var $_font_family;
var $_font_charset;
var $_num_format;
var $_hidden;
var $_locked;
var $_text_h_align;
var $_text_wrap;
var $_text_v_align;
var $_text_justlast;
var $_rotation;
var $_fg_color;
var $_bg_color;
var $_pattern;
var $_bottom;
var $_top;
var $_left;
var $_right;
var $_bottom_color;
var $_top_color;
var $_left_color;
var $_right_color;
/*
* Constructor
*/
function writeexcel_format() {
$_=func_get_args();
$this->_xf_index = (sizeof($_)>0) ? array_shift($_) : 0;
$this->_font_index = 0;
$this->_font = 'Arial';
$this->_size = 10;
$this->_bold = 0x0190;
$this->_italic = 0;
$this->_color = 0x7FFF;
$this->_underline = 0;
$this->_font_strikeout = 0;
$this->_font_outline = 0;
$this->_font_shadow = 0;
$this->_font_script = 0;
$this->_font_family = 0;
$this->_font_charset = 0;
$this->_num_format = 0;
$this->_hidden = 0;
$this->_locked = 1;
$this->_text_h_align = 0;
$this->_text_wrap = 0;
$this->_text_v_align = 2;
$this->_text_justlast = 0;
$this->_rotation = 0;
$this->_fg_color = 0x40;
$this->_bg_color = 0x41;
$this->_pattern = 0;
$this->_bottom = 0;
$this->_top = 0;
$this->_left = 0;
$this->_right = 0;
$this->_bottom_color = 0x40;
$this->_top_color = 0x40;
$this->_left_color = 0x40;
$this->_right_color = 0x40;
// Set properties passed to writeexcel_workbook::addformat()
if (sizeof($_)>0) {
call_user_func_array(array(&$this, 'set_properties'), $_);
}
}
/*
* Copy the attributes of another writeexcel_format object.
*/
function copy($other) {
$xf = $this->_xf_index; // Backup XF index
foreach ($other as $key->$value) {
$this->{$key} = $value;
}
$this->_xf_index = $xf; // Restore XF index
}
/*
* Generate an Excel BIFF XF record.
*/
function get_xf() {
$_=func_get_args();
// $record Record identifier
// $length Number of bytes to follow
// $ifnt Index to FONT record
// $ifmt Index to FORMAT record
// $style Style and other options
// $align Alignment
// $icv fg and bg pattern colors
// $fill Fill and border line style
// $border1 Border line style and color
// $border2 Border color
// Set the type of the XF record and some of the attributes.
if ($_[0] == "style") {
$style = 0xFFF5;
} else {
$style = $this->_locked;
$style |= $this->_hidden << 1;
}
// Flags to indicate if attributes have been set.
$atr_num = ($this->_num_format != 0) ? 1 : 0;
$atr_fnt = ($this->_font_index != 0) ? 1 : 0;
$atr_alc = $this->_text_wrap ? 1 : 0;
$atr_bdr = ($this->_bottom ||
$this->_top ||
$this->_left ||
$this->_right) ? 1 : 0;
$atr_pat = ($this->_fg_color != 0x41 ||
$this->_bg_color != 0x41 ||
$this->_pattern != 0x00) ? 1 : 0;
$atr_prot = 0;
// Reset the default colors for the non-font properties
if ($this->_fg_color == 0x7FFF) $this->_fg_color = 0x40;
if ($this->_bg_color == 0x7FFF) $this->_bg_color = 0x41;
if ($this->_bottom_color == 0x7FFF) $this->_bottom_color = 0x41;
if ($this->_top_color == 0x7FFF) $this->_top_color = 0x41;
if ($this->_left_color == 0x7FFF) $this->_left_color = 0x41;
if ($this->_right_color == 0x7FFF) $this->_right_color = 0x41;
// Zero the default border colour if the border has not been set.
if ($this->_bottom == 0) {
$this->_bottom_color = 0;
}
if ($this->_top == 0) {
$this->_top_color = 0;
}
if ($this->_right == 0) {
$this->_right_color = 0;
}
if ($this->_left == 0) {
$this->_left_color = 0;
}
// The following 2 logical statements take care of special cases in
// relation to cell colors and patterns:
// 1. For a solid fill (_pattern == 1) Excel reverses the role of
// foreground and background colors
// 2. If the user specifies a foreground or background color
// without a pattern they probably wanted a solid fill, so we
// fill in the defaults.
if ($this->_pattern <= 0x01 &&
$this->_bg_color != 0x41 &&
$this->_fg_color == 0x40 )
{
$this->_fg_color = $this->_bg_color;
$this->_bg_color = 0x40;
$this->_pattern = 1;
}
if ($this->_pattern <= 0x01 &&
$this->_bg_color == 0x41 &&
$this->_fg_color != 0x40 )
{
$this->_bg_color = 0x40;
$this->_pattern = 1;
}
$record = 0x00E0;
$length = 0x0010;
$ifnt = $this->_font_index;
$ifmt = $this->_num_format;
$align = $this->_text_h_align;
$align |= $this->_text_wrap << 3;
$align |= $this->_text_v_align << 4;
$align |= $this->_text_justlast << 7;
$align |= $this->_rotation << 8;
$align |= $atr_num << 10;
$align |= $atr_fnt << 11;
$align |= $atr_alc << 12;
$align |= $atr_bdr << 13;
$align |= $atr_pat << 14;
$align |= $atr_prot << 15;
$icv = $this->_fg_color;
$icv |= $this->_bg_color << 7;
$fill = $this->_pattern;
$fill |= $this->_bottom << 6;
$fill |= $this->_bottom_color << 9;
$border1 = $this->_top;
$border1 |= $this->_left << 3;
$border1 |= $this->_right << 6;
$border1 |= $this->_top_color << 9;
$border2 = $this->_left_color;
$border2 |= $this->_right_color << 7;
$header = pack("vv", $record, $length);
$data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
$icv, $fill,
$border1, $border2);
return($header . $data);
}
/*
* Generate an Excel BIFF FONT record.
*/
function get_font() {
// $record Record identifier
// $length Record length
// $dyHeight Height of font (1/20 of a point)
// $grbit Font attributes
// $icv Index to color palette
// $bls Bold style
// $sss Superscript/subscript
// $uls Underline
// $bFamily Font family
// $bCharSet Character set
// $reserved Reserved
// $cch Length of font name
// $rgch Font name
$dyHeight = $this->_size * 20;
$icv = $this->_color;
$bls = $this->_bold;
$sss = $this->_font_script;
$uls = $this->_underline;
$bFamily = $this->_font_family;
$bCharSet = $this->_font_charset;
$rgch = $this->_font;
$cch = strlen($rgch);
$record = 0x31;
$length = 0x0F + $cch;
$reserved = 0x00;
$grbit = 0x00;
if ($this->_italic) {
$grbit |= 0x02;
}
if ($this->_font_strikeout) {
$grbit |= 0x08;
}
if ($this->_font_outline) {
$grbit |= 0x10;
}
if ($this->_font_shadow) {
$grbit |= 0x20;
}
$header = pack("vv", $record, $length);
$data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
$sss, $uls, $bFamily,
$bCharSet, $reserved, $cch);
return($header . $data . $this->_font);
}
/*
* Returns a unique hash key for a font.
* Used by writeexcel_workbook::_store_all_fonts()
*/
function get_font_key() {
# The following elements are arranged to increase the probability of
# generating a unique key. Elements that hold a large range of numbers
# eg. _color are placed between two binary elements such as _italic
#
$key = $this->_font.$this->_size.
$this->_font_script.$this->_underline.
$this->_font_strikeout.$this->_bold.$this->_font_outline.
$this->_font_family.$this->_font_charset.
$this->_font_shadow.$this->_color.$this->_italic;
$key = preg_replace('/ /', '_', $key); # Convert the key to a single word
return $key;
}
/*
* Returns the used by Worksheet->_XF()
*/
function get_xf_index() {
return $this->_xf_index;
}
/*
* Used in conjunction with the set_xxx_color methods to convert a color
* string into a number. Color range is 0..63 but we will restrict it
* to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
*/
function _get_color($color=false) {
$colors = array(
'aqua' => 0x0F,
'cyan' => 0x0F,
'black' => 0x08,
'blue' => 0x0C,
'brown' => 0x10,
'magenta' => 0x0E,
'fuchsia' => 0x0E,
'gray' => 0x17,
'grey' => 0x17,
'green' => 0x11,
'lime' => 0x0B,
'navy' => 0x12,
'orange' => 0x35,
'purple' => 0x14,
'red' => 0x0A,
'silver' => 0x16,
'white' => 0x09,
'yellow' => 0x0D
);
// Return the default color, 0x7FFF, if undef,
if ($color===false) {
return 0x7FFF;
}
// or the color string converted to an integer,
if (isset($colors[strtolower($color)])) {
return $colors[strtolower($color)];
}
// or the default color if string is unrecognised,
if (preg_match('/\D/', $color)) {
return 0x7FFF;
}
// or an index < 8 mapped into the correct range,
if ($color<8) {
return $color + 8;
}
// or the default color if arg is outside range,
if ($color>63) {
return 0x7FFF;
}
// or an integer in the valid range
return $color;
}
/*
* Set cell alignment.
*/
function set_align($location) {
// Ignore numbers
if (preg_match('/\d/', $location)) {
return;
}
$location = strtolower($location);
switch ($location) {
case 'left':
$this->set_text_h_align(1);
break;
case 'centre':
case 'center':
$this->set_text_h_align(2);
break;
case 'right':
$this->set_text_h_align(3);
break;
case 'fill':
$this->set_text_h_align(4);
break;
case 'justify':
$this->set_text_h_align(5);
break;
case 'merge':
$this->set_text_h_align(6);
break;
case 'equal_space':
$this->set_text_h_align(7);
break;
case 'top':
$this->set_text_v_align(0);
break;
case 'vcentre':
case 'vcenter':
$this->set_text_v_align(1);
break;
break;
case 'bottom':
$this->set_text_v_align(2);
break;
case 'vjustify':
$this->set_text_v_align(3);
break;
case 'vequal_space':
$this->set_text_v_align(4);
break;
}
}
/*
* Set vertical cell alignment. This is required by the set_properties()
* method to differentiate between the vertical and horizontal properties.
*/
function set_valign($location) {
$this->set_align($location);
}
/*
* This is an alias for the unintuitive set_align('merge')
*/
function set_merge() {
$this->set_text_h_align(6);
}
/*
* Bold has a range 0x64..0x3E8.
* 0x190 is normal. 0x2BC is bold.
*/
function set_bold($weight=1) {
if ($weight == 1) {
// Bold text
$weight = 0x2BC;
}
if ($weight == 0) {
// Normal text
$weight = 0x190;
}
if ($weight < 0x064) {
// Lower bound
$weight = 0x190;
}
if ($weight > 0x3E8) {
// Upper bound
$weight = 0x190;
}
$this->_bold = $weight;
}
/*
* Set all cell borders (bottom, top, left, right) to the same style
*/
function set_border($style) {
$this->set_bottom($style);
$this->set_top($style);
$this->set_left($style);
$this->set_right($style);
}
/*
* Set all cell borders (bottom, top, left, right) to the same color
*/
function set_border_color($color) {
$this->set_bottom_color($color);
$this->set_top_color($color);
$this->set_left_color($color);
$this->set_right_color($color);
}
/*
* Convert hashes of properties to method calls.
*/
function set_properties() {
$_=func_get_args();
$properties=array();
foreach($_ as $props) {
if (is_array($props)) {
$properties=array_merge($properties, $props);
} else {
$properties[]=$props;
}
}
foreach ($properties as $key=>$value) {
// Strip leading "-" from Tk style properties eg. -color => 'red'.
$key = preg_replace('/^-/', '', $key);
/* Make sure method names are alphanumeric characters only, in
case tainted data is passed to the eval(). */
if (preg_match('/\W/', $key)) {
trigger_error("Unknown property: $key.",
E_USER_ERROR);
}
/* Evaling all $values as a strings gets around the problem of
some numerical format strings being evaluated as numbers, for
example "00000" for a zip code. */
if (is_int($key)) {
eval("\$this->set_$value();");
} else {
eval("\$this->set_$key('$value');");
}
}
}
function set_font($font) {
$this->_font=$font;
}
function set_size($size) {
$this->_size=$size;
}
function set_italic($italic=1) {
$this->_italic=$italic;
}
function set_color($color) {
$this->_color=$this->_get_color($color);
}
function set_underline($underline=1) {
$this->_underline=$underline;
}
function set_font_strikeout($font_strikeout=1) {
$this->_font_strikeout=$font_strikeout;
}
function set_font_outline($font_outline=1) {
$this->_font_outline=$font_outline;
}
function set_font_shadow($font_shadow=1) {
$this->_font_shadow=$font_shadow;
}
function set_font_script($font_script=1) {
$this->_font_script=$font_script;
}
/* Undocumented */
function set_font_family($font_family=1) {
$this->_font_family=$font_family;
}
/* Undocumented */
function set_font_charset($font_charset=1) {
$this->_font_charset=$font_charset;
}
function set_num_format($num_format=1) {
$this->_num_format=$num_format;
}
function set_hidden($hidden=1) {
$this->_hidden=$hidden;
}
function set_locked($locked=1) {
$this->_locked=$locked;
}
function set_text_h_align($align) {
$this->_text_h_align=$align;
}
function set_text_wrap($wrap=1) {
$this->_text_wrap=$wrap;
}
function set_text_v_align($align) {
$this->_text_v_align=$align;
}
function set_text_justlast($text_justlast=1) {
$this->_text_justlast=$text_justlast;
}
function set_rotation($rotation=1) {
$this->_rotation=$rotation;
}
function set_fg_color($color) {
$this->_fg_color=$this->_get_color($color);
}
function set_bg_color($color) {
$this->_bg_color=$this->_get_color($color);
}
function set_pattern($pattern=1) {
$this->_pattern=$pattern;
}
function set_bottom($bottom=1) {
$this->_bottom=$bottom;
}
function set_top($top=1) {
$this->_top=$top;
}
function set_left($left=1) {
$this->_left=$left;
}
function set_right($right=1) {
$this->_right=$right;
}
function set_bottom_color($color) {
$this->_bottom_color=$this->_get_color($color);
}
function set_top_color($color) {
$this->_top_color=$this->_get_color($color);
}
function set_left_color($color) {
$this->_left_color=$this->_get_color($color);
}
function set_right_color($color) {
$this->_right_color=$this->_get_color($color);
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,353 @@
<?php
/*
* Copyleft 2002 Johann Hanne
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
*/
class writeexcel_olewriter {
var $_OLEfilename;
var $_OLEtmpfilename; /* ABR */
var $_filehandle;
var $_fileclosed;
var $_internal_fh;
var $_biff_only;
var $_size_allowed;
var $_biffsize;
var $_booksize;
var $_big_blocks;
var $_list_blocks;
var $_root_start;
var $_block_count;
/*
* Constructor
*/
function writeexcel_olewriter($filename) {
$this->_OLEfilename = $filename;
$this->_filehandle = false;
$this->_fileclosed = 0;
$this->_internal_fh = 0;
$this->_biff_only = 0;
$this->_size_allowed = 0;
$this->_biffsize = 0;
$this->_booksize = 0;
$this->_big_blocks = 0;
$this->_list_blocks = 0;
$this->_root_start = 0;
$this->_block_count = 4;
$this->_initialize();
}
/*
* Check for a valid filename and store the filehandle.
*/
function _initialize() {
$OLEfile = $this->_OLEfilename;
/* Check for a filename. Workbook.pm will catch this first. */
if ($OLEfile == '') {
trigger_error("Filename required", E_USER_ERROR);
}
/*
* If the filename is a resource it is assumed that it is a valid
* filehandle, if not we create a filehandle.
*/
if (is_resource($OLEfile)) {
$fh = $OLEfile;
} else {
// Create a new file, open for writing
$fh = fopen($OLEfile, "wb");
// The workbook class also checks this but something may have
// happened since then.
if (!$fh) {
trigger_error("Can't open $OLEfile. It may be in use or ".
"protected", E_USER_ERROR);
}
$this->_internal_fh = 1;
}
// Store filehandle
$this->_filehandle = $fh;
}
/*
* Set the size of the data to be written to the OLE stream
*
* $big_blocks = (109 depot block x (128 -1 marker word)
* - (1 x end words)) = 13842
* $maxsize = $big_blocks * 512 bytes = 7087104
*/
function set_size($size) {
$maxsize = 7087104;
if ($size > $maxsize) {
trigger_error("Maximum file size, $maxsize, exceeded. To create ".
"files bigger than this limit please use the ".
"workbookbig class.", E_USER_ERROR);
return ($this->_size_allowed = 0);
}
$this->_biffsize = $size;
// Set the min file size to 4k to avoid having to use small blocks
if ($size > 4096) {
$this->_booksize = $size;
} else {
$this->_booksize = 4096;
}
return ($this->_size_allowed = 1);
}
/*
* Calculate various sizes needed for the OLE stream
*/
function _calculate_sizes() {
$datasize = $this->_booksize;
if ($datasize % 512 == 0) {
$this->_big_blocks = $datasize/512;
} else {
$this->_big_blocks = floor($datasize/512)+1;
}
// There are 127 list blocks and 1 marker blocks for each big block
// depot + 1 end of chain block
$this->_list_blocks = floor(($this->_big_blocks)/127)+1;
$this->_root_start = $this->_big_blocks;
//print $this->_biffsize. "\n";
//print $this->_big_blocks. "\n";
//print $this->_list_blocks. "\n";
}
/*
* Write root entry, big block list and close the filehandle.
* This method must be called so that the file contents are
* actually written.
*/
function close() {
if (!$this->_size_allowed) {
return;
}
if (!$this->_biff_only) {
$this->_write_padding();
$this->_write_property_storage();
$this->_write_big_block_depot();
}
// Close the filehandle if it was created internally.
if ($this->_internal_fh) {
fclose($this->_filehandle);
}
/* ABR */
if ($this->_OLEtmpfilename != '') {
$fh = fopen($this->_OLEtmpfilename, "rb");
if ($fh == false) {
trigger_error("Can't read temporary file.", E_USER_ERROR);
}
fpassthru($fh);
fclose($fh);
unlink($this->_OLEtmpfilename);
};
$this->_fileclosed = 1;
}
/*
* Write BIFF data to OLE file.
*/
function write($data) {
fputs($this->_filehandle, $data);
}
/*
* Write OLE header block.
*/
function write_header() {
if ($this->_biff_only) {
return;
}
$this->_calculate_sizes();
$root_start = $this->_root_start;
$num_lists = $this->_list_blocks;
$id = pack("C8", 0xD0, 0xCF, 0x11, 0xE0,
0xA1, 0xB1, 0x1A, 0xE1);
$unknown1 = pack("VVVV", 0x00, 0x00, 0x00, 0x00);
$unknown2 = pack("vv", 0x3E, 0x03);
$unknown3 = pack("v", -2);
$unknown4 = pack("v", 0x09);
$unknown5 = pack("VVV", 0x06, 0x00, 0x00);
$num_bbd_blocks = pack("V", $num_lists);
$root_startblock = pack("V", $root_start);
$unknown6 = pack("VV", 0x00, 0x1000);
$sbd_startblock = pack("V", -2);
$unknown7 = pack("VVV", 0x00, -2 ,0x00);
$unused = pack("V", -1);
fputs($this->_filehandle, $id);
fputs($this->_filehandle, $unknown1);
fputs($this->_filehandle, $unknown2);
fputs($this->_filehandle, $unknown3);
fputs($this->_filehandle, $unknown4);
fputs($this->_filehandle, $unknown5);
fputs($this->_filehandle, $num_bbd_blocks);
fputs($this->_filehandle, $root_startblock);
fputs($this->_filehandle, $unknown6);
fputs($this->_filehandle, $sbd_startblock);
fputs($this->_filehandle, $unknown7);
for ($c=1;$c<=$num_lists;$c++) {
$root_start++;
fputs($this->_filehandle, pack("V", $root_start));
}
for ($c=$num_lists;$c<=108;$c++) {
fputs($this->_filehandle, $unused);
}
}
/*
* Write big block depot.
*/
function _write_big_block_depot() {
$num_blocks = $this->_big_blocks;
$num_lists = $this->_list_blocks;
$total_blocks = $num_lists * 128;
$used_blocks = $num_blocks + $num_lists + 2;
$marker = pack("V", -3);
$end_of_chain = pack("V", -2);
$unused = pack("V", -1);
for ($i=1;$i<=($num_blocks-1);$i++) {
fputs($this->_filehandle, pack("V", $i));
}
fputs($this->_filehandle, $end_of_chain);
fputs($this->_filehandle, $end_of_chain);
for ($c=1;$c<=$num_lists;$c++) {
fputs($this->_filehandle, $marker);
}
for ($c=$used_blocks;$c<=$total_blocks;$c++) {
fputs($this->_filehandle, $unused);
}
}
/*
* Write property storage. TODO: add summary sheets
*/
function _write_property_storage() {
$rootsize = -2;
$booksize = $this->_booksize;
// name type dir start size
$this->_write_pps('Root Entry', 0x05, 1, -2, 0x00);
$this->_write_pps('Book', 0x02, -1, 0x00, $booksize);
$this->_write_pps('', 0x00, -1, 0x00, 0x0000);
$this->_write_pps('', 0x00, -1, 0x00, 0x0000);
}
/*
* Write property sheet in property storage
*/
function _write_pps($name, $type, $dir, $start, $size) {
$names = array();
$length = 0;
if ($name != '') {
$name = $name . "\0";
// Simulate a Unicode string
$chars=preg_split("''", $name, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as $char) {
array_push($names, ord($char));
}
$length = strlen($name) * 2;
}
$rawname = call_user_func_array('pack', array_merge(array("v*"), $names));
$zero = pack("C", 0);
$pps_sizeofname = pack("v", $length); //0x40
$pps_type = pack("v", $type); //0x42
$pps_prev = pack("V", -1); //0x44
$pps_next = pack("V", -1); //0x48
$pps_dir = pack("V", $dir); //0x4c
$unknown1 = pack("V", 0);
$pps_ts1s = pack("V", 0); //0x64
$pps_ts1d = pack("V", 0); //0x68
$pps_ts2s = pack("V", 0); //0x6c
$pps_ts2d = pack("V", 0); //0x70
$pps_sb = pack("V", $start); //0x74
$pps_size = pack("V", $size); //0x78
fputs($this->_filehandle, $rawname);
fputs($this->_filehandle, str_repeat($zero, (64-$length)));
fputs($this->_filehandle, $pps_sizeofname);
fputs($this->_filehandle, $pps_type);
fputs($this->_filehandle, $pps_prev);
fputs($this->_filehandle, $pps_next);
fputs($this->_filehandle, $pps_dir);
fputs($this->_filehandle, str_repeat($unknown1, 5));
fputs($this->_filehandle, $pps_ts1s);
fputs($this->_filehandle, $pps_ts1d);
fputs($this->_filehandle, $pps_ts2d);
fputs($this->_filehandle, $pps_ts2d);
fputs($this->_filehandle, $pps_sb);
fputs($this->_filehandle, $pps_size);
fputs($this->_filehandle, $unknown1);
}
/*
* Pad the end of the file
*/
function _write_padding() {
$biffsize = $this->_biffsize;
if ($biffsize < 4096) {
$min_size = 4096;
} else {
$min_size = 512;
}
if ($biffsize % $min_size != 0) {
$padding = $min_size - ($biffsize % $min_size);
fputs($this->_filehandle, str_repeat("\0", $padding));
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,55 @@
<?php
/*
* Copyleft 2002 Johann Hanne
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
*/
require_once "class.writeexcel_workbook.inc.php";
require_once "class.ole_pps_root.php";
require_once "class.ole_pps_file.php";
class writeexcel_workbookbig extends writeexcel_workbook {
function writeexcel_workbookbig($filename) {
$this->writeexcel_workbook($filename);
}
function _store_OLE_file() {
$file=new ole_pps_file(asc2ucs("Book"));
$file->append($this->_data);
for ($c=0;$c<sizeof($this->_worksheets);$c++) {
$worksheet=&$this->_worksheets[$c];
while ($data=$worksheet->get_data()) {
$file->append($data);
}
$worksheet->cleanup();
}
$ole=new ole_pps_root(false, false, array($file));
$ole->save($this->_filename);
}
}
?>

File diff suppressed because it is too large Load Diff