Subversion Repositories eFlore/Applications.cel

Rev

Rev 970 | Rev 1605 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 970 Rev 1604
Line 1... Line 1...
1
<?php
1
<?php
2
/*
2
/*
3
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
3
*  Module written/ported by Xavier Noguer <xnoguer@php.net>
4
*
4
*
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
5
*  The majority of this is _NOT_ my code.  I simply ported it from the
6
*  PERL Spreadsheet::WriteExcel module.
6
*  PERL Spreadsheet::WriteExcel module.
7
*
7
*
8
*  The author of the Spreadsheet::WriteExcel module is John McNamara 
8
*  The author of the Spreadsheet::WriteExcel module is John McNamara
Line 13... Line 13...
13
*  class library should be directed to me.
13
*  class library should be directed to me.
14
*
14
*
15
*  License Information:
15
*  License Information:
16
*
16
*
17
*    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
17
*    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
18
*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
18
*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@php.net
19
*
19
*
20
*    This library is free software; you can redistribute it and/or
20
*    This library is free software; you can redistribute it and/or
21
*    modify it under the terms of the GNU Lesser General Public
21
*    modify it under the terms of the GNU Lesser General Public
22
*    License as published by the Free Software Foundation; either
22
*    License as published by the Free Software Foundation; either
23
*    version 2.1 of the License, or (at your option) any later version.
23
*    version 2.1 of the License, or (at your option) any later version.
Line 30... Line 30...
30
*    You should have received a copy of the GNU Lesser General Public
30
*    You should have received a copy of the GNU Lesser General Public
31
*    License along with this library; if not, write to the Free Software
31
*    License along with this library; if not, write to the Free Software
32
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
*/
33
*/
Line 34... Line 34...
34
 
34
 
Line 35... Line 35...
35
//require_once('PEAR.php');
35
require_once 'PEAR.php';
36
 
36
 
37
/**
37
/**
38
* Class for writing Excel BIFF records.
38
* Class for writing Excel BIFF records.
Line 44... Line 44...
44
* BIFF files consist of sequences of variable-length records. There are many 
44
* BIFF files consist of sequences of variable-length records. There are many
45
* different types of BIFF records.  For example, one record type describes a 
45
* different types of BIFF records.  For example, one record type describes a
46
* formula entered into a cell; one describes the size and location of a 
46
* formula entered into a cell; one describes the size and location of a
47
* window into a document; another describes a picture format.
47
* window into a document; another describes a picture format.
48
*
48
*
49
* @author   Xavier Noguer <xnoguer@rezebra.com>
49
* @author   Xavier Noguer <xnoguer@php.net>
50
* @category FileFormats
50
* @category FileFormats
51
* @package  Spreadsheet_Excel_Writer
51
* @package  Spreadsheet_Excel_Writer
52
*/
52
*/
Line 53... Line 53...
53
 
53
 
Line 83... Line 83...
83
    * @see _addContinue()
83
    * @see _addContinue()
84
    */
84
    */
85
    var $_limit;
85
    var $_limit;
Line 86... Line 86...
86
 
86
 
-
 
87
    /**
-
 
88
    * The temporary dir for storing the OLE file
-
 
89
    * @var string
-
 
90
    */
-
 
91
    var $_tmp_dir;
-
 
92
 
-
 
93
    /**
-
 
94
    * The temporary file for storing the OLE file
-
 
95
    * @var string
-
 
96
    */
-
 
97
    var $_tmp_file;
-
 
98
 
87
    /**
99
    /**
88
    * Constructor
100
    * Constructor
89
    *
101
    *
90
    * @access public
102
    * @access public
91
    */
103
    */
92
    function Spreadsheet_Excel_Writer_BIFFwriter()
104
    function Spreadsheet_Excel_Writer_BIFFwriter()
93
    {
105
    {
94
        $this->_byte_order = '';
106
        $this->_byte_order = '';
95
        $this->_data       = '';
107
        $this->_data       = '';
96
        $this->_datasize   = 0;
108
        $this->_datasize   = 0;
-
 
109
        $this->_limit      = 2080;
97
        $this->_limit      = 2080;   
110
        $this->_tmp_dir    = '';
98
        // Set the byte order
111
        // Set the byte order
99
        $this->_setByteOrder();
112
        $this->_setByteOrder();
Line 100... Line 113...
100
    }
113
    }
Line 105... Line 118...
105
*
118
    *
106
* @access private
119
    * @access private
107
*/
120
    */
108
    function _setByteOrder()
121
    function _setByteOrder()
109
    {
122
    {
110
        if ($this->_byte_order == '')
-
 
111
        {
-
 
112
            // Check if "pack" gives the required IEEE 64bit float
123
        // Check if "pack" gives the required IEEE 64bit float
113
            $teststr = pack("d", 1.2345);
124
        $teststr = pack("d", 1.2345);
114
            $number  = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
125
        $number  = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
115
            if ($number == $teststr) {
126
        if ($number == $teststr) {
116
                $byte_order = 0;    // Little Endian
127
            $byte_order = 0;    // Little Endian
117
            }
-
 
118
            elseif ($number == strrev($teststr)){
128
        } elseif ($number == strrev($teststr)){
119
                $byte_order = 1;    // Big Endian
129
            $byte_order = 1;    // Big Endian
120
            }
-
 
121
            else {
130
        } else {
122
                // Give up. I'll fix this in a later version.
131
            // Give up. I'll fix this in a later version.
123
                $this->raiseError("Required floating point format not supported ".
132
            return $this->raiseError("Required floating point format ".
124
                    "on this platform.");
133
                                     "not supported on this platform.");
125
            }
-
 
126
        }
134
        }
127
        $this->_byte_order = $byte_order;
135
        $this->_byte_order = $byte_order;
128
    }
136
    }
Line 129... Line 137...
129
 
137
 
Line 159... Line 167...
159
 
167
 
160
/**
168
    /**
161
* Writes Excel BOF record to indicate the beginning of a stream or
169
    * Writes Excel BOF record to indicate the beginning of a stream or
162
* sub-stream in the BIFF file.
170
    * sub-stream in the BIFF file.
163
*
171
    *
-
 
172
    * @param  integer $type Type of BIFF file to write: 0x0005 Workbook,
164
* @param  integer $type type of BIFF file to write: 0x0005 Workbook, 0x0010 Worksheet.
173
    *                       0x0010 Worksheet.
165
* @access private
174
    * @access private
166
*/
175
    */
167
    function _storeBof($type)
176
    function _storeBof($type)
168
    {
177
    {
169
        $record  = 0x0809;        // Record identifier
-
 
170
        $length  = 0x0008;        // Number of bytes to follow
-
 
Line 171... Line 178...
171
        $version = $this->_BIFF_version;
178
        $record  = 0x0809;        // Record identifier
172
   
179
 
-
 
180
        // According to the SDK $build and $year should be set to zero.
-
 
181
        // However, this throws a warning in Excel 5. So, use magic numbers.
173
        // According to the SDK $build and $year should be set to zero.
182
        if ($this->_BIFF_version == 0x0500) {
174
        // However, this throws a warning in Excel 5. So, use these
183
            $length  = 0x0008;
175
        // magic numbers.
184
            $unknown = '';
-
 
185
            $build   = 0x096C;
-
 
186
            $year    = 0x07C9;
-
 
187
        } elseif ($this->_BIFF_version == 0x0600) {
-
 
188
            $length  = 0x0010;
-
 
189
            $unknown = pack("VV", 0x00000041, 0x00000006); //unknown last 8 bytes for BIFF8
-
 
190
            $build   = 0x0DBB;
-
 
191
            $year    = 0x07CC;
Line 176... Line 192...
176
        $build   = 0x096C;
192
        }
177
        $year    = 0x07C9;
193
        $version = $this->_BIFF_version;
178
   
194
 
179
        $header  = pack("vv",   $record, $length);
195
        $header  = pack("vv",   $record, $length);
Line 180... Line 196...
180
        $data    = pack("vvvv", $version, $type, $build, $year);
196
        $data    = pack("vvvv", $version, $type, $build, $year);
181
        $this->_prepend($header.$data);
197
        $this->_prepend($header . $data . $unknown);
182
    }
198
    }
Line 216... Line 232...
216
        $tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4);
232
        $tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4);
Line 217... Line 233...
217
        
233
 
Line 218... Line 234...
218
        $header = pack("vv", $record, $limit);  // Headers for continue records
234
        $header = pack("vv", $record, $limit);  // Headers for continue records
-
 
235
 
219
 
236
        // Retrieve chunks of 2080/8224 bytes +4 for the header.
220
        // Retrieve chunks of 2080/8224 bytes +4 for the header.
-
 
221
        for($i = $limit; $i < strlen($data) - $limit; $i += $limit)
237
        $data_length = strlen($data);
222
        {
238
        for ($i = $limit; $i <  ($data_length - $limit); $i += $limit) {
223
            $tmp .= $header;
239
            $tmp .= $header;
Line 224... Line 240...
224
            $tmp .= substr($data, $i, $limit);
240
            $tmp .= substr($data, $i, $limit);
225
        }
241
        }
226
 
242
 
227
        // Retrieve the last chunk of data
243
        // Retrieve the last chunk of data
Line 228... Line 244...
228
        $header  = pack("vv", $record, strlen($data) - $i);
244
        $header  = pack("vv", $record, strlen($data) - $i);
-
 
245
        $tmp    .= $header;
-
 
246
        $tmp    .= substr($data, $i, strlen($data) - $i);
-
 
247
 
-
 
248
        return $tmp;
-
 
249
    }
-
 
250
 
-
 
251
    /**
-
 
252
    * Sets the temp dir used for storing the OLE file
-
 
253
    *
-
 
254
    * @access public
-
 
255
    * @param string $dir The dir to be used as temp dir
-
 
256
    * @return true if given dir is valid, false otherwise
-
 
257
    */
-
 
258
    function setTempDir($dir)
-
 
259
    {
-
 
260
        if (is_dir($dir)) {
229
        $tmp    .= $header;
261
            $this->_tmp_dir = $dir;
230
        $tmp    .= substr($data,$i,strlen($data) - $i);
262
            return true;
231
 
263
        }