Merge commit 'origin/master' into local

This commit is contained in:
Martynas Mickevicius
2010-06-04 16:29:15 +02:00
263 changed files with 59259 additions and 44207 deletions

View File

@@ -82,12 +82,20 @@ $Id$
+ [doc] Incorporate synchronisation docs into main document.
+ [core] Include Content Security Policy HTTP headers.
- bug #3004216 [CSS] Field attributes use inline CSS
- patch #2999595, rfe #2998130 [interface] Cleanup navigation frame.
- [core] Update library PHPExcel to version 1.7.3c
3.3.4.0 (not yet released)
- bug #2996161 [import] properly escape import value
- bug #2998889 [import] Import button does not work in Catalan
- [browse] Fix handling of sort order if only column is specified.
+ [lang] Greek update, thanks to Panagiotis Papazoglou - panos78
+ [lang] Updated lot of translation based on work done in master branch.
- bug #3008411 [databases] Last dropped database remains active in navi
- bug #2986383 [parser] Not all data being shown / counted
- bug [synchronize] Rows were deleted in target table regardless of the
"Would you like to delete..." option
- bug [privileges] List of tables not shown when the db name has a wildcard
3.3.3.0 (2010-05-10)
- patch #2982480 [navi] Do not group if there would be one table in group,

View File

@@ -101,8 +101,8 @@ vim: expandtab ts=4 sw=4 sts=4 tw=78
<h3>Currently phpMyAdmin can:</h3>
<ul><li>browse and drop databases, tables, views, fields and indexes</li>
<li>create, copy, drop, rename and alter databases, tables, fields and
<ul><li>browse and drop databases, tables, views, columns and indexes</li>
<li>create, copy, drop, rename and alter databases, tables, columns and
indexes</li>
<li>maintenance server, databases and tables, with proposals on server
configuration</li>
@@ -328,7 +328,7 @@ rm -rf config # remove not needed directory
<p> For a whole set of new features (bookmarks, comments,
<abbr title="structured query language">SQL</abbr>-history,
tracking mechanism,
<abbr title="Portable Document Format">PDF</abbr>-generation, field contents
<abbr title="Portable Document Format">PDF</abbr>-generation, column contents
transformation, etc.) you need to create a set of special tables. Those
tables can be located in your own database, or in a central database for a
multi-user installation (this database would then be accessed by the
@@ -893,17 +893,17 @@ since this link provides funding for phpMyAdmin.
<span id="cfg_Servers_relation">$cfg['Servers'][$i]['relation']</span> string
</dt>
<dd>Since release 2.2.4 you can describe, in a special 'relation' table,
which field is a key in another table (a foreign key). phpMyAdmin
which column is a key in another table (a foreign key). phpMyAdmin
currently uses this to
<ul><li>make clickable, when you browse the master table, the data values
that point to the foreign table;</li>
<li>display in an optional tool-tip the &quot;display field&quot;
<li>display in an optional tool-tip the &quot;display column&quot;
when browsing the master table, if you move the mouse to a column
containing a foreign key (use also the 'table_info' table);<br />
(see <a href="#faqdisplay"><abbr title="Frequently Asked Questions">
FAQ</abbr> 6.7</a>)</li>
<li>in edit/insert mode, display a drop-down list of possible foreign
keys (key value and &quot;display field&quot; are shown)<br />
keys (key value and &quot;display column&quot; are shown)<br />
(see <a href="#faq6_21"><abbr title="Frequently Asked Questions">
FAQ</abbr> 6.21</a>)</li>
<li>display links on the table properties page, to check referential
@@ -925,12 +925,13 @@ since this link provides funding for phpMyAdmin.
<tt>$cfg['Servers'][$i]['relation']</tt></li>
<li>now as normal user open phpMyAdmin and for each one of your
tables where you want to use this feature, click
&quot;Structure/Relation view/&quot; and choose foreign fields.
&quot;Structure/Relation view/&quot; and choose foreign
columns.
</li>
</ul>
Please note that in the current version, <tt>master_db</tt>
must be the same as <tt>foreign_db</tt>. Those fields have been put in
must be the same as <tt>foreign_db</tt>. Those columns have been put in
future development of the cross-db relations.
</dd>
@@ -939,7 +940,7 @@ since this link provides funding for phpMyAdmin.
</dt>
<dd>
Since release 2.3.0 you can describe, in a special 'table_info'
table, which field is to be displayed as a tool-tip when moving the
table, which column is to be displayed as a tool-tip when moving the
cursor over the corresponding key.<br />
This configuration variable will hold the name of this special
table. To allow the usage of this functionality:
@@ -947,10 +948,10 @@ since this link provides funding for phpMyAdmin.
<li>put the table name in
<tt>$cfg['Servers'][$i]['table_info']</tt></li>
<li>then for each table where you want to use this feature,
click &quot;Structure/Relation view/Choose field to display&quot;
to choose the field.</li>
click &quot;Structure/Relation view/Choose column to display&quot;
to choose the column.</li>
</ul>
Usage tip: <a href="#faqdisplay">Display field</a>.
Usage tip: <a href="#faqdisplay">Display column</a>.
</dd>
<dt id="table_coords">
<span id="cfg_Servers_table_coords">$cfg['Servers'][$i]['table_coords']</span> string<br />
@@ -997,7 +998,7 @@ since this link provides funding for phpMyAdmin.
based on the following table structure. See <a href="#transformations">
Transformations</a> for further information. To use the
MIME-transformation system, your column_info table has to have the three
new fields 'mimetype', 'transformation', 'transformation_options'.
new columns 'mimetype', 'transformation', 'transformation_options'.
<br /><br />
To allow the usage of this functionality:
@@ -1154,7 +1155,7 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre>
<dt><span id="cfg_Servers_verbose_check">$cfg['Servers'][$i]['verbose_check']</span> boolean
</dt>
<dd>Because release 2.5.0 introduced the new MIME-transformation support, the
column_info table got enhanced with three new fields. If the above variable
column_info table got enhanced with three new columns. If the above variable
is set to <tt>TRUE</tt> (default) phpMyAdmin will check if you have the
latest table structure available. If not, it will emit a warning to the
superuser.<br /><br />
@@ -1531,9 +1532,9 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre>
contains more rows, &quot;Previous&quot; and &quot;Next&quot; links will be shown.</dd>
<dt id="cfg_Order">$cfg['Order'] string [<tt>DESC</tt>|<tt>ASC</tt>|<tt>SMART</tt>]</dt>
<dd>Defines whether fields are displayed in ascending (<tt>ASC</tt>) order,
<dd>Defines whether columns are displayed in ascending (<tt>ASC</tt>) order,
in descending (<tt>DESC</tt>) order or in a &quot;smart&quot;
(<tt>SMART</tt>) order - I.E. descending order for fields of type TIME,
(<tt>SMART</tt>) order - I.E. descending order for columns of type TIME,
DATE, DATETIME and TIMESTAMP, ascending order else- by default.</dd>
<dt id="cfg_DisplayBinaryAsHex">$cfg['DisplayBinaryAsHex'] boolean </dt>
@@ -1541,12 +1542,12 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre>
option is ticked by default.</dd>
<dt id="cfg_ProtectBinary">$cfg['ProtectBinary'] boolean or string</dt>
<dd>Defines whether <tt>BLOB</tt> or <tt>BINARY</tt> fields are protected
<dd>Defines whether <tt>BLOB</tt> or <tt>BINARY</tt> columns are protected
from editing when browsing a table's content. Valid values are:
<ul><li><tt>FALSE</tt> to allow editing of all fields;</li>
<li><tt>'blob'</tt> to allow editing of all fields except <tt>BLOBS</tt>;</li>
<ul><li><tt>FALSE</tt> to allow editing of all columns;</li>
<li><tt>'blob'</tt> to allow editing of all columns except <tt>BLOBS</tt>;</li>
<li><tt>'all'</tt> to disallow editing of all <tt>BINARY</tt> or
<tt>BLOB</tt> fields.</li>
<tt>BLOB</tt> columns.</li>
</ul>
</dd>
@@ -1564,10 +1565,10 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre>
<dt id="cfg_CharEditing">$cfg['CharEditing'] string</dt>
<dd>Defines which type of editing controls should be used for CHAR and
VARCHAR fields. Possible values are:
<ul><li>input - this allows to limit size of text to size of field in
MySQL, but has problems with newlines in fields</li>
<li>textarea - no problems with newlines in fields, but also no
VARCHAR columns. Possible values are:
<ul><li>input - this allows to limit size of text to size of columns in
MySQL, but has problems with newlines in columns</li>
<li>textarea - no problems with newlines in columns, but also no
length limitations</li>
</ul>
Default is old behavior so input.</dd>
@@ -1850,7 +1851,7 @@ $cfg['TrustedProxies'] =
<dt><span id="cfg_LongtextDoubleTextarea">$cfg['LongtextDoubleTextarea'] </span>boolean
</dt>
<dd>Defines whether textarea for LONGTEXT fields should have double size.</dd>
<dd>Defines whether textarea for LONGTEXT columns should have double size.</dd>
<dt><span id="cfg_TextareaAutoSelect">$cfg['TextareaAutoSelect'] </span>boolean
</dt>
@@ -1863,7 +1864,7 @@ $cfg['TrustedProxies'] =
editing.</dd>
<dt id="cfg_LimitChars">$cfg['LimitChars'] integer</dt>
<dd>Maximum number of characters showen in any non-numeric field on browse view.
<dd>Maximum number of characters showen in any non-numeric column on browse view.
Can be turned off by a toggle button on the browse page.</dd>
<dt><span id="cfg_ModifyDeleteAtLeft">$cfg['ModifyDeleteAtLeft'] </span>boolean
@@ -1879,7 +1880,7 @@ $cfg['TrustedProxies'] =
<dd>There are 3 display modes: horizontal, horizontalflipped and vertical.
Define which one is displayed by default. The first mode displays each
row on a horizontal line, the second rotates the headers by 90
degrees, so you can use descriptive headers even though fields only
degrees, so you can use descriptive headers even though columns only
contain small values and still print them out. The vertical mode sorts
each row on a vertical lineup.
</dd>
@@ -1903,9 +1904,9 @@ $cfg['TrustedProxies'] =
'vertical' you can have each field lined up vertically beneath each
other. You can save up a lot of place on the horizontal direction and
no longer have to scroll. If you set this to integer, editing of fewer
columns will appear in 'vertical' mode, while editing of more fields
columns will appear in 'vertical' mode, while editing of more columns
still in 'horizontal' mode. This way you can still effectively edit
large number of fields, while having full view on few of them.</dd>
large number of columns, while having full view on few of them.</dd>
<dt id="cfg_ShowBrowseComments">$cfg['ShowBrowseComments'] boolean<br />
<span id="cfg_ShowPropertyComments">$cfg['ShowPropertyComments'] </span>boolean
@@ -1914,7 +1915,7 @@ $cfg['TrustedProxies'] =
display of column comments in Browse or Property display. In browse
mode, the comments are shown inside the header. In property mode,
comments are displayed using a CSS-formatted dashed-line below the
name of the field. The comment is shown as a tool-tip for that field.
name of the column. The comment is shown as a tool-tip for that column.
</dd>
<dt id ="cfg_SQLQuery_Edit">$cfg['SQLQuery']['Edit'] boolean</dt>
@@ -2208,7 +2209,7 @@ setfacl -d -m "g:www-data:rwx" tmp
</dt>
<dd>Default queries that will be displayed in query boxes when user didn't
specify any. Use %d for database name, %t for table name and %f for a
comma separated list of field names. Note that %t and %f are only
comma separated list of column names. Note that %t and %f are only
applicable to <tt>$cfg['DefaultQueryTable']</tt>.</dd>
<dt id="cfg_SQP_fmtType">$cfg['SQP']['fmtType'] string [<tt>html</tt>|<tt>none</tt>]</dt>
@@ -2319,7 +2320,7 @@ setfacl -d -m "g:www-data:rwx" tmp
edit this.</dd>
<dt id="cfg_AttributeTypes">$cfg['AttributeTypes'] array</dt>
<dd>Possible attributes for fields. In most cases you don't need to edit
<dd>Possible attributes for columns. In most cases you don't need to edit
this.</dd>
<dt id="cfg_Functions">$cfg['Functions'] array</dt>
@@ -2343,21 +2344,21 @@ setfacl -d -m "g:www-data:rwx" tmp
in table.</dd>
<dt id="cfg_NumOperators">$cfg['NumOperators'] array</dt>
<dd>Operators available for search operations on numeric and date fields.
<dd>Operators available for search operations on numeric and date columns.
</dd>
<dt id="cfg_TextOperators">$cfg['TextOperators'] array</dt>
<dd>Operators available for search operations on character fields.
<dd>Operators available for search operations on character columns.
Note that we put <code>LIKE</code> by default instead of
<code>LIKE %...%</code>, to avoid unintended performance problems
in case of huge tables.</dd>
<dt id="cfg_EnumOperators">$cfg['EnumOperators'] array</dt>
<dd>Operators available for search operations on enum fields.</dd>
<dd>Operators available for search operations on ENUM columns.</dd>
<dt id="cfg_NullOperators">$cfg['NullOperators'] array</dt>
<dd>Additional operators available for search operations when the
field can be null.</dd>
column can be null.</dd>
</dl>
@@ -2375,14 +2376,14 @@ setfacl -d -m "g:www-data:rwx" tmp
and the proper directives. Please see the <a href="#config">Configuration
section</a> on how to do so.</p>
<p> You can apply different transformations to the contents of each field. The
transformation will take the content of each field and transform it with
<p> You can apply different transformations to the contents of each column. The
transformation will take the content of each column and transform it with
certain rules defined in the selected transformation.</p>
<p> Say you have a field 'filename' which contains a filename. Normally you would
<p> Say you have a column 'filename' which contains a filename. Normally you would
see in phpMyAdmin only this filename. Using transformations you can transform
that filename into a HTML link, so you can click inside of the phpMyAdmin
structure on the field's link and will see the file displayed in a new browser
structure on the column's link and will see the file displayed in a new browser
window. Using transformation options you can also specify strings to
append/prepend to a string or the format you want the output stored in.</p>
@@ -2399,7 +2400,8 @@ setfacl -d -m "g:www-data:rwx" tmp
<p> Go to your <i>tbl_structure.php</i> page (i.e. reached through
clicking on the 'Structure' link for a table). There click on
&quot;Change&quot; (or change icon) and there you will see three new fields at
&quot;Change&quot; (or change icon) and there you will see three new
fields at
the end of the line. They are called 'MIME-type', 'Browser transformation' and
'Transformation options'.</p>
@@ -2455,7 +2457,7 @@ setfacl -d -m "g:www-data:rwx" tmp
<p> One can, however, use empty mime-types and global transformations which should work
for many mimetypes. You can also use transforms on a different mimetype they where built
for, but pay attention to option usage as well as what the transformation does to your
field.</p>
column.</p>
<p> There is a basic file called '<i>global.inc.php</i>'. This function can be included by
any other transform function and provides some basic functions.</p>
@@ -2547,12 +2549,7 @@ setfacl -d -m "g:www-data:rwx" tmp
<p> Please see the libraries/transformations/TEMPLATE file for adding your own transform
function. See the libraries/transformations/TEMPLATE_MIMETYPE for adding a mimetype
without a transform function. Also note the introduction of a function description in
the language files. For each function a $strTransformation_[filename without .inc.php]
has to exist.</p>
<p> You can use the template generator to generate new functions and entries in the
language file.</p>
without a transform function.</p>
<p> To create a new transform function please see
<tt>libraries/transformations/template_generator.sh</tt>.
@@ -2565,15 +2562,15 @@ setfacl -d -m "g:www-data:rwx" tmp
you want to transform.</li>
<li><b>$options</b> - Contains any user-passed options to a transform function
as an array.</li>
<li><b>$meta</b> - Contains an object with field information to your column.
<li><b>$meta</b> - Contains an object with information about your column.
The data is drawn from the output of the
<a href="http://www.php.net/mysql_fetch_field">mysql_fetch_field()</a>
function. This means, all object properties described on the
<a href="http://www.php.net/mysql_fetch_field">manual page</a> are
available in this variable and can be used to transform a field accordingly
available in this variable and can be used to transform a column accordingly
to unsigned/zerofill/not_null/... properties.<br />
The $meta-&gt;mimetype variable contains the original MIME-type of the
field (i.e. 'text/plain', 'image/jpeg' etc.)</li>
column (i.e. 'text/plain', 'image/jpeg' etc.)</li>
</ol>
<p> Additionally you should also provide additional function to provide
@@ -2773,11 +2770,11 @@ setfacl -d -m "g:www-data:rwx" tmp
and try to increase it.</p>
<h4 id="faq1_15">
<a href="#faq1_15">1.15 I have problems with <i>mysql.user</i> field names.</a>
<a href="#faq1_15">1.15 I have problems with <i>mysql.user</i> column names.</a>
</h4>
<p> In previous MySQL versions, the <tt>User</tt> and <tt>Password</tt> fields
were named <tt>user</tt> and <tt>password</tt>. Please modify your field
<p> In previous MySQL versions, the <tt>User</tt> and <tt>Password</tt>columns
were named <tt>user</tt> and <tt>password</tt>. Please modify your column
names to align with current standards.</p>
<h4 id="faq1_16">
@@ -2905,7 +2902,7 @@ setfacl -d -m "g:www-data:rwx" tmp
<h4 id="faq1_23">
<a href="#faq1_23">1.23 I'm running MySQL on a Win32 machine. Each time I create
a new table the table and field names are changed to lowercase!</a></h4>
a new table the table and column names are changed to lowercase!</a></h4>
<p> This happens because the MySQL directive <tt>lower_case_table_names</tt>
defaults to 1 (<tt>ON</tt>) in the Win32 version of MySQL. You can change
@@ -2975,8 +2972,8 @@ setfacl -d -m "g:www-data:rwx" tmp
available starting with MySQL&nbsp;3.23.56 / 4.0.11-gamma.</p>
<h4 id="faq1_29">
<a href="#faq1_29">1.29 When I create a table or modify a field, I get an error
and the fields are duplicated.</a></h4>
<a href="#faq1_29">1.29 When I create a table or modify a column, I get an error
and the columns are duplicated.</a></h4>
<p> It is possible to configure Apache in such a way that PHP has problems
interpreting .php files.</p>
@@ -3106,7 +3103,7 @@ RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
<p>
Suhosin configuration might lead to malfunction in some cases and it can
not be fully avoided as phpMyAdmin is kind of application which needs to
transfer big amounts of fields in single HTTP request, what is something
transfer big amounts of columns in single HTTP request, what is something
what Suhosin tries to prevent. Generally all
<code>suhosin.request.*</code>, <code>suhosin.post.*</code> and
<code>suhosin.get.*</code> directives can have negative effect on
@@ -3435,13 +3432,13 @@ have either the <a href="http://pecl.php.net/package/APC">APC</a> extension
<a href="#faq3_6">3.6 What is currently not supported in phpMyAdmin about InnoDB?</a></h4>
<p> In Relation view, being able to choose a table in another database,
or having more than one index field in the foreign key.<br /><br/>
or having more than one index column in the foreign key.<br /><br/>
In Query-by-example (Query), automatic generation of the query
LEFT JOIN from the foreign table.<br /><br/>
</p>
<h4 id="faq3_7">
<a href="#faq3_7">3.7 I have table with many (100+) fields and when I try to browse table
<a href="#faq3_7">3.7 I have table with many (100+) columns and when I try to browse table
I get series of errors like &quot;Warning: unable to parse url&quot;. How
can this be fixed?</a></h4>
<p>
@@ -3452,7 +3449,7 @@ have either the <a href="http://pecl.php.net/package/APC">APC</a> extension
</p>
<h4 id="faq3_8">
<a href="#faq3_8">3.8 I cannot use (clickable) HTML-forms in fields where I put
<a href="#faq3_8">3.8 I cannot use (clickable) HTML-forms in columns where I put
a MIME-Transformation onto!</a></h4>
<p> Due to a surrounding form-container (for multi-row delete checkboxes), no
@@ -3701,14 +3698,14 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
<h4 id="faq5_1">
<a href="#faq5_1">5.1 I get an out of memory error, and my controls are non-functional,
when trying to create a table with more than 14 fields.
when trying to create a table with more than 14 columns.
</a></h4>
<p>
We could reproduce this problem only under Win98/98SE. Testing under
WinNT4 or Win2K, we could easily create more than 60 fields.
WinNT4 or Win2K, we could easily create more than 60 columns.
<br />
A workaround is to create a smaller number of fields, then come back to
your table properties and add the other fields.
A workaround is to create a smaller number of columns, then come back to
your table properties and add the other columns.
</p>
<h4 id="faq5_2">
@@ -3756,7 +3753,8 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
<h4 id="faq5_6">
<a href="#faq5_6">5.6 In Internet Explorer 5.0, 5.5 or 6.0, I get an error (like "Page not found")
when trying to modify a row in a table with many fields, or with a text field
when trying to modify a row in a table with many columns, or with a text
column
</a></h4>
<p>
Your table neither have a primary key nor an unique one, so we must use a
@@ -3876,7 +3874,7 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
</a></h4>
<p>
Examine the <abbr title="structured query language">SQL</abbr> error with care. Often the problem is caused by
specifying a wrong field-type.<br />
specifying a wrong column-type.<br />
Common errors include:
</p>
<ul>
@@ -3889,11 +3887,12 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
</p>
<h4 id="faq6_2">
<a href="#faq6_2">6.2 When I create a table, I set an index for two fields and
phpMyAdmin generates only one index with those two fields.
<a href="#faq6_2">6.2 When I create a table, I set an index for two
columns and
phpMyAdmin generates only one index with those two columns.
</a></h4>
<p>
This is the way to create a multi-fields
This is the way to create a multi-columns
index. If you want two indexes, create the first one when creating the
table, save, then display the table properties and click the Index link to
create the other index.
@@ -3902,11 +3901,11 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
<h4 id="faq6_3">
<a href="#faq6_3">6.3 How can I insert a null value into my table?</a></h4>
<p>
Since version 2.2.3, you have a checkbox for each field that can be null.
Since version 2.2.3, you have a checkbox for each column that can be null.
Before 2.2.3, you had to enter &quot;null&quot;, without the quotes, as the
field's value. Since version 2.5.5, you have to use the checkbox to get
column's value. Since version 2.5.5, you have to use the checkbox to get
a real NULL value, so if you enter &quot;NULL&quot; this means you want
a literal NULL in the field, and not a NULL value (this works in PHP4).
a literal NULL in the column, and not a NULL value (this works in PHP4).
</p>
<h4 id="faq6_4">
@@ -3988,7 +3987,7 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
<li>in Links, for &quot;town_code&quot; choose &quot;REL_towns-&gt;code&quot;</li>
<li>in Links, for &quot;country_code&quot; choose &quot;REL_countries-&gt;country_code&quot;</li>
<li>on table &quot;REL_towns&quot; click Structure, then Relation view</li>
<li>in &quot;Choose field to display&quot;, choose &quot;description&quot;</li>
<li>in &quot;Choose column to display&quot;, choose &quot;description&quot;</li>
<li>repeat the two previous steps for table &quot;REL_countries&quot;</li>
</ul>
@@ -3998,7 +3997,7 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
<li>Choose &quot;Query&quot;</li>
<li>Use tables: persons, towns, countries</li>
<li>Click &quot;Update query&quot;</li>
<li>In the fields row, choose persons.person_name and click the
<li>In the columns row, choose persons.person_name and click the
&quot;Show&quot; tickbox </li>
<li>Do the same for towns.description and countries.descriptions in the
other 2 columns</li>
@@ -4008,13 +4007,13 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
</ul>
<h4 id="faqdisplay">
<a href="#faqdisplay">6.7 How can I use the &quot;display field&quot; feature?</a></h4>
<a href="#faqdisplay">6.7 How can I use the &quot;display column&quot; feature?</a></h4>
<p>
Starting from the previous example, create the pma_table_info as explained
in the configuration section, then browse your persons table,
and move the mouse over a town code or country code.
<br /><br />
See also <a href="#faq6_21"><abbr title="Frequently Asked Questions">FAQ</abbr> 6.21</a> for an additional feature that &quot;display field&quot;
See also <a href="#faq6_21"><abbr title="Frequently Asked Questions">FAQ</abbr> 6.21</a> for an additional feature that &quot;display column&quot;
enables: drop-down list of possible values.
</p>
@@ -4098,8 +4097,8 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
different structure.</li>
<li>&quot;Add AUTO_INCREMENT value&quot; ensures that AUTO_INCREMENT value
(if any) will be included in backup.</li>
<li>&quot;Enclose table and field names with backquotes&quot; ensures that
field and table names formed with special characters are protected.</li>
<li>&quot;Enclose table and column names with backquotes&quot; ensures that
column and table names formed with special characters are protected.</li>
<li>&quot;Add into comments&quot; includes column comments, relations, and MIME
types set in the pmadb in the dump as
<abbr title="structured query language">SQL</abbr> comments (<i>/* xxx */</i>).
@@ -4156,15 +4155,15 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
We utilize it as free SOAP service.</p>
<h4 id="faq6_15">
<a href="#faq6_15">6.15 I want to add a BLOB field and put an index on
<a href="#faq6_15">6.15 I want to add a BLOB column and put an index on
it, but MySQL says &quot;BLOB column '...' used in key specification without
a key length&quot;.</a></h4>
<p> The right way to do this, is to create the field without any indexes,
<p> The right way to do this, is to create the column without any indexes,
then display the table structure and use the &quot;Create an index&quot;
dialog. On this page, you will be able to choose your BLOB field, and
dialog. On this page, you will be able to choose your BLOB column, and
set a size to the index, which is the condition to create an index on
a BLOB field.</p>
a BLOB column.</p>
<h4 id="faq6_16">
<a href="#faq6_16">6.16 How can I simply move in page with plenty
@@ -4183,7 +4182,7 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
WTF is this feature then useful for?</a></h4>
<p> Slow down :). Defining mimetypes is of no use, if you can't put transformations
on them. Otherwise you could just put a comment on the field. Because entering
on them. Otherwise you could just put a comment on the column. Because entering
your own mimetype will cause serious syntax checking issues and validation,
this introduces a high-risk false-user-input situation. Instead you have to
initialize mimetypes using functions or empty mimetype definitions.<br />
@@ -4273,17 +4272,17 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
<h4 id="faq6_21">
<a href="#faq6_21">6.21 In edit/insert mode, how can I see a list of
possible values for a field, based on some foreign table?</a></h4>
possible values for a column, based on some foreign table?</a></h4>
<p> You have to setup appropriate links between the tables, and also
setup the &quot;display field&quot; in the foreign table. See
setup the &quot;display column&quot; in the foreign table. See
<a href="#faq6_6"><abbr title="Frequently Asked Questions">FAQ</abbr>
6.6</a> for an example. Then, if there are 100 values or less in the
foreign table, a drop-down list of values will be available.
You will see two lists of values, the first list containing the key
and the display field, the second list containing the display field
and the display column, the second list containing the display column
and the key. The reason for this is to be able to type the first
letter of either the key or the display field.<br /><br />
letter of either the key or the display column.<br /><br />
For 100 values or more, a distinct window will appear, to browse foreign
key values and choose one. To change the default limit of 100, see
@@ -4867,7 +4866,7 @@ Jakub Wilk, Thomas Michael Winningham, Vilius Zigmantas, &quot;Manuzhai&quot;.
also contributed the French translation.
</li>
<li>Alexandr Bravo &lt;abravo_at_hq.admiral.ru&gt; who contributed
tbl_select.php3, a feature to display only some fields from a table.
tbl_select.php3, a feature to display only some columns from a table.
</li>
<li>Chris Jackson &lt;chrisj_at_ctel.net&gt; added support for MySQL
functions in tbl_change.php3. He also added the

View File

@@ -125,9 +125,9 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) {
/**
* Gets fields properties
* Gets columns properties
*/
$result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
$result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
$fields_cnt = PMA_DBI_num_rows($result);
if (PMA_MYSQL_INT_VERSION < 50025) {
@@ -171,7 +171,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) {
?>
<table width="100%" class="print">
<tr><th width="50"><?php echo __('Field'); ?></th>
<tr><th width="50"><?php echo __('Column'); ?></th>
<th width="80"><?php echo __('Type'); ?></th>
<?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
<th width="40"><?php echo __('Null'); ?></th>

View File

@@ -121,7 +121,7 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) {
if ($this_what != 'nocopy') {
// keep the triggers from the original db+table
// (third param is empty because delimiters are only intended
// (third param is empty because delimiters are only intended
// for importing via the mysql client or our Import feature)
$triggers = PMA_DBI_get_triggers($db, $each_table, '');
@@ -141,7 +141,7 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) {
}
unset($trigger);
}
unset($triggers);
unset($triggers);
// this does not apply to a rename operation
if (isset($GLOBALS['add_constraints']) && !empty($GLOBALS['sql_constraints_query'])) {
@@ -380,6 +380,8 @@ if (!$is_information_schema) {
<input type="text" name="comment" class="textfield" size="30"
value="<?php
echo htmlspecialchars(PMA_getDBComment($db)); ?>" />
</fieldset>
<fieldset class="tblFooters">
<input type="submit" value="<?php echo __('Go'); ?>" />
</fieldset>
</form>
@@ -422,6 +424,8 @@ if (!$is_information_schema) {
echo 'INSERT INTO ... SELECT';
//}
echo ')'; ?>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" value="<?php echo __('Go'); ?>" onclick="return confirmLink(this, 'CREATE DATABASE ... <?php echo __('and then'); ?> DROP DATABASE <?php echo PMA_jsFormat($db); ?>')" />
</fieldset>
</form>
@@ -599,6 +603,8 @@ if (!$is_information_schema) {
. ' </legend>' . "\n"
. PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
'db_collation', 'select_db_collation', $db_collation, false, 3)
. '</fieldset>'
. '<fieldset class="tblFooters">'
. ' <input type="submit" name="submitcollation"'
. ' value="' . __('Go') . '" />' . "\n"
. '</fieldset>' . "\n"
@@ -631,79 +637,15 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$test_rs = PMA_query_as_controluser($test_query, null, PMA_DBI_QUERY_STORE);
if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?>
<!-- PDF schema -->
<form method="post" action="pdf_schema.php">
<fieldset>
<legend>
<?php
echo PMA_generate_common_hidden_inputs($db);
if ($cfg['PropertiesIconic']) {
echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
.' alt="" width="16" height="16" />';
}
echo __('Display PDF schema');
?>:
</legend>
<label for="pdf_page_number_opt"><?php echo __('Page number:'); ?></label>
<select name="pdf_page_number" id="pdf_page_number_opt">
<?php
while ($pages = @PMA_DBI_fetch_assoc($test_rs)) {
echo ' <option value="' . $pages['page_nr'] . '">'
. $pages['page_nr'] . ': ' . htmlspecialchars($pages['page_descr']) . '</option>' . "\n";
} // end while
PMA_DBI_free_result($test_rs);
unset($test_rs);
?>
</select><br />
<input type="checkbox" name="show_grid" id="show_grid_opt" />
<label for="show_grid_opt"><?php echo __('Show grid'); ?></label><br />
<input type="checkbox" name="show_color" id="show_color_opt"
checked="checked" />
<label for="show_color_opt"><?php echo __('Show color'); ?></label><br />
<input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" />
<label for="show_table_dim_opt"><?php echo __('Show dimension of tables'); ?>
</label><br />
<input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" />
<label for="all_tab_same_wide"><?php echo __('Display all tables with the same width'); ?>
</label><br />
<input type="checkbox" name="with_doc" id="with_doc" checked="checked" />
<label for="with_doc"><?php echo __('Data Dictionary'); ?></label><br />
<input type="checkbox" name="show_keys" id="show_keys" />
<label for="show_keys"><?php echo __('Only show keys'); ?></label><br />
<label for="orientation_opt"><?php echo __('Data Dictionary Format'); ?></label>
<select name="orientation" id="orientation_opt">
<option value="L"><?php echo __('Landscape');?></option>
<option value="P"><?php echo __('Portrait');?></option>
</select><br />
<label for="paper_opt"><?php echo __('Paper size'); ?></label>
<select name="paper" id="paper_opt">
<?php
foreach ($cfg['PDFPageSizes'] AS $key => $val) {
echo '<option value="' . $val . '"';
if ($val == $cfg['PDFDefaultPageSize']) {
echo ' selected="selected"';
}
echo ' >' . $val . '</option>' . "\n";
}
?>
</select>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" value="<?php echo __('Go'); ?>" />
</fieldset>
</form>
<?php
if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
include('./libraries/display_pdf_schema.lib.php');
} // end if
echo '<br /><a href="pdf_pages.php?' . $url_query . '">';
echo '<fieldset><a href="pdf_pages.php?' . $url_query . '">';
if ($cfg['PropertiesIconic']) {
echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
.' alt="" width="16" height="16" />';
}
echo __('Edit PDF Pages') . '</a>';
echo __('Edit PDF Pages') . '</a></fieldset>';
} // end if
/**

View File

@@ -102,7 +102,7 @@ else {
<thead>
<tr>
<th><?php echo __('Table'); ?></th>
<th><?php echo __('Records'); ?></th>
<th><?php echo __('Rows'); ?></th>
<th><?php echo __('Type'); ?></th>
<?php
if ($cfg['ShowStats']) {
@@ -219,7 +219,7 @@ else {
?>
<tr>
<th align="center">
<?php echo sprintf(__('%s table(s)'), PMA_formatNumber($num_tables, 0)); ?>
<?php echo sprintf(_ngettext('%s table', '%s tables', $num_tables), PMA_formatNumber($num_tables, 0)); ?>
</th>
<th align="right" nowrap="nowrap">
<?php echo PMA_formatNumber($sum_entries, 0); ?>

View File

@@ -171,7 +171,7 @@ function showColumnSelectCell($columns, $column_number, $selected = '')
<fieldset>
<table class="data" style="width: 100%;">
<tr class="odd noclick">
<th><?php echo __('Field'); ?>:</th>
<th><?php echo __('Column'); ?>:</th>
<?php
$z = 0;
for ($x = 0; $x < $col; $x++) {
@@ -581,7 +581,7 @@ echo PMA_generate_common_hidden_inputs($url_params);
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<td nowrap="nowrap">
<?php echo __('Add/Delete Criteria Row'); ?>:
<?php echo __('Add/Delete criteria rows'); ?>:
<select size="1" name="add_row">
<option value="-3">-3</option>
<option value="-2">-2</option>
@@ -593,7 +593,7 @@ echo PMA_generate_common_hidden_inputs($url_params);
</select>
</td>
<td width="10">&nbsp;</td>
<td nowrap="nowrap"><?php echo __('Add/Delete Field Columns'); ?>:
<td nowrap="nowrap"><?php echo __('Add/Delete columns'); ?>:
<select size="1" name="add_col">
<option value="-3">-3</option>
<option value="-2">-2</option>

View File

@@ -352,7 +352,7 @@ $alter_select =
<?php echo $alter_select; ?></td>
</tr>
<tr><td align="right">
<?php echo __('Inside field:'); ?></td>
<?php echo __('Inside column:'); ?></td>
<td><input type="text" name="field_str" size="60"
value="<?php echo ! empty($field_str) ? $field_str : ''; ?>" /></td>
</tr>

View File

@@ -477,7 +477,7 @@ if ($is_show_stats) {
if ($num_tables == 0)
$tableReductionCount = 0;
echo sprintf(__('%s table(s)'), PMA_formatNumber($num_tables - $tableReductionCount, 0));
echo sprintf(_ngettext('%s table', '%s tables', $num_tables - $tableReductionCount), PMA_formatNumber($num_tables - $tableReductionCount, 0));
?>
</th>
<?php

View File

@@ -60,7 +60,7 @@ $js_messages['strGeneralRelationFeat:strDisabled'] = __('General relation featur
$js_messages['strSelectReferencedKey'] = __('Select referenced key');
$js_messages['strSelectForeignKey'] = __('Select Foreign Key');
$js_messages['strPleaseSelectPrimaryOrUniqueKey'] = __('Please select the primary key or a unique key');
$js_messages['strChangeDisplay'] = __('Choose field to display');
$js_messages['strChangeDisplay'] = __('Choose column to display');
echo "var PMA_messages = new Array();\n";
foreach ($js_messages as $name => $js_message) {

View File

@@ -443,7 +443,7 @@ class PMA_Index
$r .= '<th>' . __('Type') . '</th>';
$r .= '<th>' . __('Unique') . '</th>';
$r .= '<th>' . __('Packed') . '</th>';
$r .= '<th>' . __('Field') . '</th>';
$r .= '<th>' . __('Column') . '</th>';
$r .= '<th>' . __('Cardinality') . '</th>';
$r .= '<th>' . __('Collation') . '</th>';
$r .= '<th>' . __('Null') . '</th>';

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,45 +20,31 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_DocumentProperties */
require_once PHPEXCEL_ROOT . 'PHPExcel/DocumentProperties.php';
/** PHPExcel_DocumentSecurity */
require_once PHPEXCEL_ROOT . 'PHPExcel/DocumentSecurity.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Shared_ZipStreamWrapper */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/ZipStreamWrapper.php';
/** PHPExcel_NamedRange */
require_once PHPEXCEL_ROOT . 'PHPExcel/NamedRange.php';
/** PHPExcel_WorksheetIterator */
require_once PHPEXCEL_ROOT . 'PHPExcel/WorksheetIterator.php';
/**
* PHPExcel
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel
{
@@ -146,6 +132,16 @@ class PHPExcel
$this->addCellStyleXf(new PHPExcel_Style);
}
public function disconnectWorksheets() {
foreach($this->_workSheetCollection as $k => &$worksheet) {
$worksheet->disconnectCells();
$this->_workSheetCollection[$k] = null;
}
unset($worksheet);
$this->_workSheetCollection = array();
}
/**
* Get properties
*
@@ -212,6 +208,8 @@ class PHPExcel
* Add sheet
*
* @param PHPExcel_Worksheet $pSheet
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @return PHPExcel_Worksheet
* @throws Exception
*/
public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null)
@@ -229,7 +227,14 @@ class PHPExcel
0,
array($pSheet)
);
// Adjust active sheet index if necessary
if ($this->_activeSheetIndex >= $iSheetIndex) {
++$this->_activeSheetIndex;
}
}
return $pSheet;
}
/**
@@ -370,6 +375,23 @@ class PHPExcel
return $this->getActiveSheet();
}
/**
* Set active sheet index by name
*
* @param string $pValue Sheet title
* @return PHPExcel_Worksheet
* @throws Exception
*/
public function setActiveSheetIndexByName($pValue = '')
{
if (($worksheet = $this->getSheetByName($pValue)) instanceof PHPExcel_Worksheet) {
$this->setActiveSheetIndex($worksheet->getParent()->getIndex($worksheet));
return $worksheet;
}
throw new Exception('Workbook does not contain sheet:' . $pValue);
}
/**
* Get sheet names
*
@@ -390,10 +412,11 @@ class PHPExcel
* Add external sheet
*
* @param PHPExcel_Worksheet $pSheet External sheet to add
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @throws Exception
* @return PHPExcel_Worksheet
*/
public function addExternalSheet(PHPExcel_Worksheet $pSheet) {
public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null) {
if (!is_null($this->getSheetByName($pSheet->getTitle()))) {
throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
}
@@ -410,11 +433,12 @@ class PHPExcel
$pSheet->rebindParent($this);
// update the cellXfs
foreach ($pSheet->getCellCollection(false) as $cell) {
foreach ($pSheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$cell->setXfIndex( $cell->getXfIndex() + $countCellXfs );
}
return $this->addSheet($pSheet);
return $this->addSheet($pSheet, $iSheetIndex);
}
/**
@@ -433,7 +457,13 @@ class PHPExcel
* @return PHPExcel
*/
public function addNamedRange(PHPExcel_NamedRange $namedRange) {
$this->_namedRanges[$namedRange->getWorksheet()->getTitle().'!'.$namedRange->getName()] = $namedRange;
if ($namedRange->getScope() == null) {
// global scope
$this->_namedRanges[$namedRange->getName()] = $namedRange;
} else {
// local scope
$this->_namedRanges[$namedRange->getScope()->getTitle().'!'.$namedRange->getName()] = $namedRange;
}
return true;
}
@@ -441,57 +471,42 @@ class PHPExcel
* Get named range
*
* @param string $namedRange
* @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
* @return PHPExcel_NamedRange|null
*/
public function getNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
$returnValue = null;
if ($namedRange != '' && !is_null($namedRange)) {
if (!is_null($pSheet)) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
return $this->_namedRanges[$key];
}
// first look for global defined name
if (isset($this->_namedRanges[$namedRange])) {
$returnValue = $this->_namedRanges[$namedRange];
}
$returnCount = 0;
foreach($this->_namedRanges as $_namedRange) {
if ($_namedRange->getName() == $namedRange) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) {
return $_namedRange;
} else {
$returnCount++;
$returnValue = $_namedRange;
}
}
}
if ($returnCount == 1) {
return $returnValue;
// then look for local defined name (has priority over global defined name if both names exist)
if (!is_null($pSheet) && isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
$returnValue = $this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange];
}
}
return null;
return $returnValue;
}
/**
* Remove named range
*
* @param string $namedRange
* @param PHPExcel_Worksheet|null $pSheet. Scope. Use null for global scope.
* @return PHPExcel
*/
public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
if ($namedRange != '' && !is_null($namedRange)) {
if (!is_null($pSheet)) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
if (is_null($pSheet)) {
if (isset($this->_namedRanges[$namedRange])) {
unset($this->_namedRanges[$namedRange]);
}
foreach($this->_namedRanges as $_namedRange) {
if ($_namedRange->getName() == $namedRange) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
}
}
} else {
if (isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
unset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]);
}
}
return $this;
@@ -612,7 +627,8 @@ class PHPExcel
// then update cellXf indexes for cells
foreach ($this->_workSheetCollection as $worksheet) {
foreach ($worksheet->getCellCollection(false) as $cell) {
foreach ($worksheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$xfIndex = $cell->getXfIndex();
if ($xfIndex > $pIndex ) {
// decrease xf index by 1
@@ -700,7 +716,8 @@ class PHPExcel
}
/**
* Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells in the workbook
* Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells
* and columns in the workbook
*/
public function garbageCollect()
{
@@ -711,12 +728,28 @@ class PHPExcel
}
foreach ($this->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
// from cells
foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
++$countReferencesCellXf[$cell->getXfIndex()];
}
// from row dimensions
foreach ($sheet->getRowDimensions() as $rowDimension) {
if ($rowDimension->getXfIndex() !== null) {
++$countReferencesCellXf[$rowDimension->getXfIndex()];
}
}
// from column dimensions
foreach ($sheet->getColumnDimensions() as $columnDimension) {
++$countReferencesCellXf[$columnDimension->getXfIndex()];
}
}
// remove those cellXfs that have zero references and create mapping so we can update xfIndex for all cells
// remove cellXfs without references and create mapping so we can update xfIndex
// for all cells and columns
$countNeededCellXfs = 0;
foreach ($this->_cellXfCollection as $index => $cellXf) {
if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first cellXf
@@ -728,16 +761,36 @@ class PHPExcel
}
$this->_cellXfCollection = array_values($this->_cellXfCollection);
// if we removed the first style by accident, recreate it
// update the index for all cellXfs
foreach ($this->_cellXfCollection as $i => $cellXf) {
$cellXf->setIndex($i);
}
// make sure there is always at least one cellXf (there should be)
if (count($this->_cellXfCollection) == 0) {
$this->_cellXfCollection[] = new PHPExcel_Style();
}
// update the xfIndex for all cells
// update the xfIndex for all cells, row dimensions, column dimensions
foreach ($this->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
// for all cells
foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$cell->setXfIndex( $map[$cell->getXfIndex()] );
}
// for all row dimensions
foreach ($sheet->getRowDimensions() as $rowDimension) {
if ($rowDimension->getXfIndex() !== null) {
$rowDimension->setXfIndex( $map[$rowDimension->getXfIndex()] );
}
}
// for all column dimensions
foreach ($sheet->getColumnDimensions() as $columnDimension) {
$columnDimension->setXfIndex( $map[$columnDimension->getXfIndex()] );
}
}
// also do garbage collection for all the sheets

View File

@@ -2,38 +2,50 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
class PHPExcel_Autoloader
{
public static function Register() {
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} // function Register()
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** Require FPDF library */
$k_path_url = dirname(__FILE__) . '/PDF';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PDF/tcpdf.php';
public static function Load($pObjectName){
if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') === False)) {
return false;
}
$pObjectFilePath = PHPEXCEL_ROOT.
str_replace('_',DIRECTORY_SEPARATOR,$pObjectName).
'.php';
if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {
return false;
}
require($pObjectFilePath);
} // function Load()
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_APC
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_cachePrefix = null;
private $_cacheTime = 600;
private function _storeData() {
$this->_currentObject->detach();
if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) {
$this->__destruct();
throw new Exception('Failed to store cell in APC');
}
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in apc
$success = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in APC');
}
return true;
}
return false;
} // function isDataSet()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) {
$obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
if ($obj === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in APC');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
// Delete the entry from APC
apc_delete($this->_cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
} // function deleteCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
// Flush the APC cache
$this->__destruct();
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_cachePrefix = substr(md5(uniqid($baseUnique,true)),0,8).'.';
$this->_cacheTime = $cacheTime;
parent::__construct($parent);
}
} // function __construct()
public function __destruct() {
$cacheList = $this->getCellList();
foreach($cacheList as $cellID) {
apc_delete($this->_cachePrefix.$cellID.'.cache');
}
} // function __destruct()
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_CacheBase
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_CacheBase {
/**
* Parent worksheet
*
* @var PHPExcel_Worksheet
*/
protected $_parent;
/**
* The currently active Cell
*
* @var PHPExcel_Cell
*/
protected $_currentObject = null;
/**
* Coordinate address of the currently active Cell
*
* @var string
*/
protected $_currentObjectID = null;
/**
* An array of cells or cell pointers for the worksheet cells held in this cache,
* and indexed by their coordinate address within the worksheet
*
* @var array of mixed
*/
protected $_cellCache = array();
public function __construct(PHPExcel_Worksheet $parent) {
// Set our parent worksheet.
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
// they are woken from a serialized state
$this->_parent = $parent;
} // function __construct()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return true;
}
// Check if the requested entry exists in the cache
return isset($this->_cellCache[$pCoord]);
} // function isDataSet()
/**
* Add or Update a cell in cache
*
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function updateCacheData(PHPExcel_Cell $cell) {
$pCoord = $cell->getCoordinate();
return $this->addCacheData($pCoord,$cell);
} // function updateCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
$this->_currentObject->detach();
$this->_currentObjectID = $this->_currentObject = null;
}
if (isset($this->_cellCache[$pCoord])) {
$this->_cellCache[$pCoord]->detach();
unset($this->_cellCache[$pCoord]);
}
} // function deleteCacheData()
/**
* Get a list of all cell addresses currently held in cache
*
* @return array of string
*/
public function getCellList() {
return array_keys($this->_cellCache);
} // function getCellList()
/**
* Sort the list of all cell addresses currently held in cache by row and column
*
* @return void
*/
public function getSortedCellList() {
$sortKeys = array();
foreach ($this->_cellCache as $coord => $value) {
preg_match('/^(\w+)(\d+)$/U',$coord,$matches);
list(,$colNum,$rowNum) = $matches;
$sortKeys[$coord] = str_pad($rowNum . str_pad($colNum,3,'@',STR_PAD_LEFT),12,'0',STR_PAD_LEFT);
}
asort($sortKeys);
return array_keys($sortKeys);
} // function sortCellList()
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_DiscISAM
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_fileName = null;
private $_fileHandle = null;
private function _storeData() {
$this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END);
$offset = ftell($this->_fileHandle);
fwrite($this->_fileHandle, serialize($this->_currentObject));
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset
);
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
// Close down the temporary cache file
$this->__destruct();
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent) {
parent::__construct($parent);
if (is_null($this->_fileHandle)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_fileName = sys_get_temp_dir().'/PHPExcel.'.uniqid($baseUnique,true).'.cache';
$this->_fileHandle = fopen($this->_fileName,'a+');
}
} // function __construct()
public function __destruct() {
if (!is_null($this->_fileHandle)) {
fclose($this->_fileHandle);
unlink($this->_fileName);
}
$this->_fileHandle = null;
} // function __destruct()
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_ICache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_CachedObjectStorage_ICache
{
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell);
/**
* Add or Update a cell in cache
*
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function updateCacheData(PHPExcel_Cell $cell);
/**
* Fetch a cell from cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to retrieve
* @return PHPExcel_Cell Cell that was found, or null if not found
* @throws Exception
*/
public function getCacheData($pCoord);
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord);
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord);
/**
* Get a list of all cell addresses currently held in cache
*
* @return array of string
*/
public function getCellList();
/**
* Get the list of all cell addresses currently held in cache sorted by column and row
*
* @return void
*/
public function getSortedCellList();
}

View File

@@ -0,0 +1,214 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_Memcache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_cachePrefix = null;
private $_cacheTime = 600;
private $_memcache = null;
private function _storeData() {
$this->_currentObject->detach();
$obj = serialize($this->_currentObject);
if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
$this->__destruct();
throw new Exception('Failed to store cell in Memcache');
}
}
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in apc
$success = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Memcache');
}
return true;
}
return false;
} // function isDataSet()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) {
$obj = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
if ($obj === false) {
// Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Memcache');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
// Delete the entry from Memcache
$this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
} // function deleteCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
// Flush the Memcache cache
$this->__destruct();
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_cachePrefix = substr(md5(uniqid($baseUnique,true)),0,8).'.';
// Set a new Memcache object and connect to the Memcache server
$this->_memcache = new Memcache();
if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback')) {
throw new Exception('Could not connect to Memcache server at '.$memcacheServer.':'.$memcachePort);
}
$this->_cacheTime = $cacheTime;
parent::__construct($parent);
}
} // function __construct()
public function failureCallback($host, $port) {
throw new Exception('memcache '.$host.':'.$port' failed');
}
public function __destruct() {
$cacheList = $this->getCellList();
foreach($cacheList as $cellID) {
$this->_memcache->delete($this->_cachePrefix.$cellID.'.cache');
}
} // function __destruct()
}
?>

View File

@@ -0,0 +1,85 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_Memory
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
$this->_cellCache[$pCoord] = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Return requested entry
return $this->_cellCache[$pCoord];
} // function getCacheData()
public function unsetWorksheetCells() {
// Because cells are all stored as intact objects in memory, we need to detach each one from the parent
foreach($this->_cellCache as $k => &$cell) {
$cell->detach();
$this->_cellCache[$k] = null;
}
unset($cell);
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_MemoryGZip
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private function _storeData() {
$this->_currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord]));
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_MemorySerialized
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private function _storeData() {
$this->_currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($this->_cellCache[$pCoord]);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_PHPTemp
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_fileHandle = null;
private function _storeData() {
$this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END);
$offset = ftell($this->_fileHandle);
fwrite($this->_fileHandle, serialize($this->_currentObject));
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset
);
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
// Close down the php://temp file
$this->__destruct();
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $memoryCacheSize = '1MB') {
$memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
parent::__construct($parent);
if (is_null($this->_fileHandle)) {
$this->_fileHandle = fopen('php://temp/maxmemory:'.$memoryCacheSize,'a+');
}
} // function __construct()
public function __destruct() {
if (!is_null($this->_fileHandle)) {
fclose($this->_fileHandle);
}
$this->_fileHandle = null;
} // function __destruct()
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_Wincache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_cachePrefix = null;
private $_cacheTime = 600;
private function _storeData() {
$this->_currentObject->detach();
$obj = serialize($this->_currentObject);
if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime);
} else {
wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime);
}
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in cache
$success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in Wincache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Wincache');
}
return true;
}
return false;
} // function isDataSet()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
$obj = null;
if (parent::isDataSet($pCoord)) {
$success = false;
$obj = wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache', $success);
if ($success === false) {
// Entry no longer exists in Wincache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Wincache');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
// Delete the entry from Wincache
wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
} // function deleteCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
// Flush the Wincache cache
$this->__destruct();
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_cachePrefix = substr(md5(uniqid($baseUnique,true)),0,8).'.';
$this->_cacheTime = $cacheTime;
parent::__construct($parent);
}
} // function __construct()
public function __destruct() {
$cacheList = $this->getCellList();
foreach($cacheList as $cellID) {
wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
}
} // function __destruct()
}
?>

View File

@@ -0,0 +1,131 @@
<?php
class PHPExcel_CachedObjectStorageFactory {
const cache_in_memory = 'Memory';
const cache_in_memory_gzip = 'MemoryGZip';
const cache_in_memory_serialized = 'MemorySerialized';
const cache_to_discISAM = 'DiscISAM';
const cache_to_apc = 'APC';
const cache_to_memcache = 'Memcache';
const cache_to_phpTemp = 'PHPTemp';
const cache_to_wincache = 'Wincache';
private static $_cacheStorageMethod = null;
private static $_cacheStorageClass = null;
private static $_storageMethods = array(
self::cache_in_memory,
self::cache_in_memory_gzip,
self::cache_in_memory_serialized,
self::cache_to_phpTemp,
self::cache_to_discISAM,
self::cache_to_apc,
self::cache_to_memcache,
self::cache_to_wincache,
);
private static $_storageMethodDefaultParameters = array(
self::cache_in_memory => array(
),
self::cache_in_memory_gzip => array(
),
self::cache_in_memory_serialized => array(
),
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
),
self::cache_to_discISAM => array(
),
self::cache_to_apc => array( 'cacheTime' => 600
),
self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
'memcachePort' => 11211,
'cacheTime' => 600
),
self::cache_to_wincache => array( 'cacheTime' => 600
)
);
private static $_storageMethodParameters = array();
public static function getCacheStorageMethod() {
if (!is_null(self::$_cacheStorageMethod)) {
return self::$_cacheStorageMethod;
}
return null;
} // function getCacheStorageMethod()
public static function getCacheStorageClass() {
if (!is_null(self::$_cacheStorageClass)) {
return self::$_cacheStorageClass;
}
return null;
} // function getCacheStorageClass()
public static function getCacheStorageMethods() {
return self::$_storageMethods;
} // function getCacheStorageMethods()
public static function initialize($method = self::cache_in_memory, $arguments = array()) {
if (!in_array($method,self::$_storageMethods)) {
return false;
}
switch($method) {
case self::cache_to_apc :
if (!function_exists('apc_store')) {
return false;
}
if (apc_sma_info() === false) {
return false;
}
break;
case self::cache_to_memcache :
if (!function_exists('memcache_add')) {
return false;
}
break;
case self::cache_to_wincache :
if (!function_exists('wincache_ucache_add')) {
return false;
}
break;
}
self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
foreach($arguments as $k => $v) {
if (isset(self::$_storageMethodParameters[$method][$k])) {
self::$_storageMethodParameters[$method][$k] = $v;
}
}
if (is_null(self::$_cacheStorageMethod)) {
self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
self::$_cacheStorageMethod = $method;
}
return true;
} // function initialize()
public static function getInstance(PHPExcel_Worksheet $parent) {
if (is_null(self::$_cacheStorageMethod)) {
self::initialize();
}
$instance = new self::$_cacheStorageClass($parent,self::$_storageMethodParameters[self::$_cacheStorageMethod]);
if (!is_null($instance)) {
return $instance;
}
return false;
} // function getInstance()
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Exception extends Exception {
/**

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,37 +20,26 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Calculation_Exception */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/Exception.php';
/**
* PHPExcel_Calculation_ExceptionHandler
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_ExceptionHandler {
class PHPExcel_Calculation_ExceptionHandler {
/**
* Register errorhandler
*/
public function __construct() {
set_error_handler(array('PHPExcel_Calculation_Exception', 'errorHandlerCallback'), E_ALL);
set_error_handler(array('PHPExcel_Calculation_Exception', 'errorHandlerCallback'), E_ALL);
}
/**
* Unregister errorhandler
*/

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -49,23 +49,12 @@ PARTLY BASED ON:
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Calculation_FormulaToken */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/FormulaToken.php';
/**
* PHPExcel_Calculation_FormulaParser
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_FormulaParser {
/* Character constants */

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -55,7 +55,7 @@ PARTLY BASED ON:
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_FormulaToken {
/* Token types */

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Function {
/* Function categories */

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,51 +20,18 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Cell_DataValidation */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataValidation.php';
/** PHPExcel_Cell_Hyperlink */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/Hyperlink.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Calculation */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation.php';
/** PHPExcel_Cell_IValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/IValueBinder.php';
/** PHPExcel_Cell_DefaultValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DefaultValueBinder.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/**
* PHPExcel_Cell
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell
{
@@ -124,6 +91,24 @@ class PHPExcel_Cell
*/
private $_xfIndex;
/**
* Send notification to the cache controller
* @return void
**/
public function notifyCacheController() {
$this->_parent->getCellCacheController()->updateCacheData($this);
}
public function detach() {
$this->_parent = null;
}
public function attach($parent) {
$this->_parent = $parent;
}
/**
* Create a new Cell
*
@@ -136,11 +121,6 @@ class PHPExcel_Cell
*/
public function __construct($pColumn = 'A', $pRow = 1, $pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null)
{
// Set value binder?
if (is_null(self::$_valueBinder)) {
self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
}
// Initialise cell coordinate
$this->_column = strtoupper($pColumn);
$this->_row = $pRow;
@@ -171,7 +151,7 @@ class PHPExcel_Cell
*/
public function getColumn()
{
return strtoupper($this->_column);
return $this->_column;
}
/**
@@ -226,26 +206,48 @@ class PHPExcel_Cell
* @param mixed $pValue Value
* @param string $pDataType Explicit data type
* @return PHPExcel_Cell
* @throws Exception
*/
public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{
// check strings that they are ok
// TODO: fix also for RichText
if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING && !($pValue instanceof PHPExcel_RichText)) {
// string must never be longer than 32,767 characters, truncate if necessary
$pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767);
// set the value according to data type
switch ($pDataType) {
case PHPExcel_Cell_DataType::TYPE_STRING:
case PHPExcel_Cell_DataType::TYPE_NULL:
case PHPExcel_Cell_DataType::TYPE_INLINE:
$this->_value = PHPExcel_Cell_DataType::checkString($pValue);
break;
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
$pValue = str_replace(array("\r\n", "\r"), "\n", $pValue);
case PHPExcel_Cell_DataType::TYPE_NUMERIC:
$this->_value = (float)$pValue;
break;
case PHPExcel_Cell_DataType::TYPE_FORMULA:
$this->_value = (string)$pValue;
break;
case PHPExcel_Cell_DataType::TYPE_BOOL:
$this->_value = (bool)$pValue;
break;
case PHPExcel_Cell_DataType::TYPE_ERROR:
$this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue);
break;
default:
throw new Exception('Invalid datatype: ' . $pDataType);
break;
}
$this->_value = $pValue;
$this->_dataType = $pDataType;
return $this;
// set the datatype
$this->_dataType = $pDataType;
$this->notifyCacheController();
return $this;
}
/**
* Get caluclated cell value
* Get calculated cell value
*
* @return mixed
*/
@@ -256,9 +258,11 @@ class PHPExcel_Cell
try {
// echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />';
$result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog);
// echo $this->getCoordinate().' calculation result is '.$result.'<br />';
} catch ( Exception $ex ) {
// echo 'Calculation Exception: '.$ex->getMessage().'<br />';
$result = '#N/A';
throw(new Exception($ex->getMessage()));
}
if ((is_string($result)) && ($result == '#Not Yet Implemented')) {
@@ -293,6 +297,8 @@ class PHPExcel_Cell
if (!is_null($pValue)) {
$this->_calculatedValue = $pValue;
}
$this->notifyCacheController();
return $this;
}
@@ -325,6 +331,8 @@ class PHPExcel_Cell
public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{
$this->_dataType = $pDataType;
$this->notifyCacheController();
return $this;
}
@@ -371,6 +379,8 @@ class PHPExcel_Cell
}
$this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation);
$this->notifyCacheController();
return $this;
}
@@ -418,6 +428,8 @@ class PHPExcel_Cell
}
$this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink);
$this->notifyCacheController();
return $this;
}
@@ -438,6 +450,8 @@ class PHPExcel_Cell
*/
public function rebindParent(PHPExcel_Worksheet $parent) {
$this->_parent = $parent;
$this->notifyCacheController();
return $this;
}
@@ -492,22 +506,17 @@ class PHPExcel_Cell
{
if (strpos($pCoordinateString,':') !== false) {
throw new Exception('Cell coordinate string can not be a range of cells.');
} else if ($pCoordinateString == '') {
throw new Exception('Cell coordinate can not be zero-length string.');
} else {
// Column
$column = '';
// Row
$row = '';
// Convert a cell reference
if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
list(, $column, $row) = $matches;
}
// Return array
} else if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
list(, $column, $row) = $matches;
return array($column, $row);
} else {
throw new Exception('Invalid cell coordinate.');
}
}
@@ -606,6 +615,30 @@ class PHPExcel_Cell
return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
}
/**
* Calculate range boundaries
*
* @param string $pRange Cell range (e.g. A1:A1)
* @return array Range boundaries (staring Column, starting Row, Final Column, Final Row)
*/
public static function getRangeBoundaries($pRange = 'A1:A1')
{
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
$rangeA = '';
$rangeB = '';
if (strpos($pRange, ':') === false) {
$rangeA = $pRange;
$rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
}
/**
* Column index from string
*
@@ -615,6 +648,14 @@ class PHPExcel_Cell
*/
public static function columnIndexFromString($pString = 'A')
{
static $lookup = array(
'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26
);
if (isset($lookup[$pString]))
return $lookup[$pString];
// Convert to uppercase
$pString = strtoupper($pString);
@@ -745,6 +786,10 @@ class PHPExcel_Cell
* @return PHPExcel_Cell_IValueBinder
*/
public static function getValueBinder() {
if (is_null(self::$_valueBinder)) {
self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
}
return self::$_valueBinder;
}
@@ -795,6 +840,8 @@ class PHPExcel_Cell
public function setXfIndex($pValue = 0)
{
$this->_xfIndex = $pValue;
$this->notifyCacheController();
return $this;
}

View File

@@ -2,63 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_IValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/IValueBinder.php';
/** PHPExcel_Cell_DefaultValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DefaultValueBinder.php';
/** PHPExcel_Style_NumberFormat */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/NumberFormat.php';
/** PHPExcel_Shared_Date */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Date.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/**
* PHPExcel_Cell_AdvancedValueBinder
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
@@ -78,67 +51,76 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
// Find out data type
$dataType = parent::dataTypeForValue($value);
// Style logic - strings
if ($dataType === PHPExcel_Cell_DataType::TYPE_STRING && !$value instanceof PHPExcel_RichText) {
// Check for percentage
if (preg_match('/^\-?[0-9]*\.?[0-9]*\s?\%$/', $value)) {
// Convert value to number
$cell->setValueExplicit( (float)str_replace('%', '', $value) / 100, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE );
return true;
}
// Check for time e.g. '9:45', '09:45'
// Check for time without seconds e.g. '9:45', '09:45'
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
list($h, $m) = explode(':', $value);
$days = $h / 24 + $m / 1440;
// Convert value to number
$cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3 );
return true;
}
// Check for date
if (strtotime($value) !== false) {
// make sure we have UTC for the sake of strtotime
$saveTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
// Check for time with seconds '9:45:59', '09:45:59'
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)) {
list($h, $m, $s) = explode(':', $value);
$days = $h / 24 + $m / 1440 + $s / 86400;
// Convert value to number
$cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 );
return true;
}
// Check for datetime, e.g. '2008-12-31', '2008-12-31 15:59', '2008-12-31 15:59:10'
if (($v = PHPExcel_Shared_Date::stringToExcel($value)) !== false) {
// Convert value to Excel date
$cell->setValueExplicit( PHPExcel_Shared_Date::PHPToExcel(strtotime($value)), PHPExcel_Cell_DataType::TYPE_NUMERIC);
$cell->setValueExplicit($v, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style. Either there is a time part or not. Look for ':'
if (strpos($value, ':') !== false) {
$formatCode = 'yyyy-mm-dd h:mm';
} else {
$formatCode = 'yyyy-mm-dd';
}
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode($formatCode);
return true;
}
// Check for newline character "\n"
if (strpos($value, "\n") !== false) {
$value = PHPExcel_Shared_String::SanitizeUTF8($value);
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2 );
// restore original value for timezone
date_default_timezone_set($saveTimeZone);
$cell->getParent()->getStyle( $cell->getCoordinate() )->getAlignment()->setWrapText(true);
return true;
}
}
// Style logic - Numbers
if ($dataType === PHPExcel_Cell_DataType::TYPE_NUMERIC) {
// Leading zeroes?
if (preg_match('/^\-?[0]+[0-9]*\.?[0-9]*$/', $value)) {
// Convert value to string
$cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_STRING);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
return true;
}
}
// Not bound yet? Use parent...
return parent::bindValue($cell, $value);
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell_DefaultValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DefaultValueBinder.php';
/**
* PHPExcel_Cell_DataType
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_DataType
{
@@ -71,7 +59,7 @@ class PHPExcel_Cell_DataType
public static function getErrorCodes() {
return self::$_errorCodes;
}
/**
* DataType for value
*
@@ -82,4 +70,44 @@ class PHPExcel_Cell_DataType
public static function dataTypeForValue($pValue = null) {
return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue);
}
/**
* Check a string that it satisfies Excel requirements
*
* @param mixed Value to sanitize to an Excel string
* @return mixed Sanitized value
*/
public static function checkString($pValue = null)
{
if ($pValue instanceof PHPExcel_RichText) {
// TODO: Sanitize Rich-Text string (max. character count is 32,767)
return $pValue;
}
// string must never be longer than 32,767 characters, truncate if necessary
$pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767);
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
$pValue = str_replace(array("\r\n", "\r"), "\n", $pValue);
return $pValue;
}
/**
* Check a value that it is a valid error code
*
* @param mixed Value to sanitize to an Excel error code
* @return string Sanitized value
*/
public static function checkErrorCode($pValue = null)
{
$pValue = (string)$pValue;
if ( !array_key_exists($pValue, self::$_errorCodes) ) {
$pValue = '#NULL!';
}
return $pValue;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_DataValidation
{
@@ -151,20 +151,12 @@ class PHPExcel_Cell_DataValidation
*/
private $_prompt;
/**
* Parent cell
*
* @var PHPExcel_Cell
*/
private $_parent;
/**
* Create a new PHPExcel_Cell_DataValidation
*
* @param PHPExcel_Cell $pCell Parent cell
* @throws Exception
*/
public function __construct(PHPExcel_Cell $pCell = null)
public function __construct()
{
// Initialise member variables
$this->_formula1 = '';
@@ -180,9 +172,6 @@ class PHPExcel_Cell_DataValidation
$this->_error = '';
$this->_promptTitle = '';
$this->_prompt = '';
// Set cell
$this->_parent = $pCell;
}
/**
@@ -445,26 +434,6 @@ class PHPExcel_Cell_DataValidation
return $this;
}
/**
* Get parent
*
* @return PHPExcel_Cell
*/
public function getParent() {
return $this->_parent;
}
/**
* Set Parent
*
* @param PHPExcel_Cell $value
* @return PHPExcel_Cell_DataValidation
*/
public function setParent($value = null) {
$this->_parent = $value;
return $this;
}
/**
* Get hash code
*
@@ -485,7 +454,6 @@ class PHPExcel_Cell_DataValidation
. $this->_error
. $this->_promptTitle
. $this->_prompt
. $this->_parent->getCoordinate()
. __CLASS__
);
}
@@ -494,12 +462,9 @@ class PHPExcel_Cell_DataValidation
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/
public function __clone() {
// unbind parent
$this->setParent(null);
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (is_object($value) && $key != '_parent') {
if (is_object($value)) {
$this->$key = clone $value;
} else {
$this->$key = $value;

View File

@@ -2,57 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_IValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/IValueBinder.php';
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/**
* PHPExcel_Cell_DefaultValueBinder
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
@@ -72,11 +51,11 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
// Set value explicit
$cell->setValueExplicit( $value, PHPExcel_Cell_DataType::dataTypeForValue($value) );
// Done!
return true;
}
/**
* DataType for value
*
@@ -87,22 +66,31 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
// Match the value against a few data types
if (is_null($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NULL;
} elseif ($pValue === '') {
return PHPExcel_Cell_DataType::TYPE_STRING;
} elseif ($pValue instanceof PHPExcel_RichText) {
return PHPExcel_Cell_DataType::TYPE_STRING;
} elseif ($pValue{0} === '=') {
} elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
return PHPExcel_Cell_DataType::TYPE_FORMULA;
} elseif (is_bool($pValue)) {
return PHPExcel_Cell_DataType::TYPE_BOOL;
} elseif (is_float($pValue) || is_int($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NUMERIC;
} elseif (preg_match('/^\-?[0-9]*\\.?[0-9]*$/', $pValue)) {
} elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/', $pValue)) {
return PHPExcel_Cell_DataType::TYPE_NUMERIC;
} elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
return PHPExcel_Cell_DataType::TYPE_ERROR;
} else {
return PHPExcel_Cell_DataType::TYPE_STRING;
}
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,17 +31,10 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_Hyperlink
{
/**
* Cell representing the hyperlink
*
* @var PHPExcel_Cell
*/
private $_cell;
/**
* URL to link the cell to
*
@@ -59,19 +52,15 @@ class PHPExcel_Cell_Hyperlink
/**
* Create a new PHPExcel_Cell_Hyperlink
*
* @param PHPExcel_Cell $pCell Parent cell
* @param string $pUrl Url to link the cell to
* @param string $pTooltip Tooltip to display on the hyperlink
* @throws Exception
*/
public function __construct(PHPExcel_Cell $pCell = null, $pUrl = '', $pTooltip = '')
public function __construct($pUrl = '', $pTooltip = '')
{
// Initialise member variables
$this->_url = $pUrl;
$this->_tooltip = $pTooltip;
// Set cell
$this->_parent = $pCell;
}
/**
@@ -123,26 +112,6 @@ class PHPExcel_Cell_Hyperlink
return strpos($this->_url, 'sheet://') !== false;
}
/**
* Get parent
*
* @return PHPExcel_Cell
*/
public function getParent() {
return $this->_parent;
}
/**
* Set Parent
*
* @param PHPExcel_Cell $value
* @return PHPExcel_Cell_Hyperlink
*/
public function setParent($value = null) {
$this->_parent = $value;
return $this;
}
/**
* Get hash code
*
@@ -152,7 +121,6 @@ class PHPExcel_Cell_Hyperlink
return md5(
$this->_url
. $this->_tooltip
. $this->_parent->getCoordinate()
. __CLASS__
);
}

View File

@@ -2,48 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/**
* PHPExcel_Cell_IValueBinder
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_Cell_IValueBinder
{

View File

@@ -2,54 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_RichText */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText.php';
/** PHPExcel_Style_Color */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/**
* PHPExcel_Comment
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Comment implements PHPExcel_IComparable
{
@@ -59,59 +41,59 @@ class PHPExcel_Comment implements PHPExcel_IComparable
* @var string
*/
private $_author;
/**
* Rich text comment
*
* @var PHPExcel_RichText
*/
private $_text;
/**
* Comment width (CSS style, i.e. XXpx or YYpt)
*
* @var string
*/
private $_width = '96pt';
/**
* Left margin (CSS style, i.e. XXpx or YYpt)
*
* @var string
*/
private $_marginLeft = '59.25pt';
/**
* Top margin (CSS style, i.e. XXpx or YYpt)
*
* @var string
*/
private $_marginTop = '1.5pt';
/**
* Visible
*
* @var boolean
*/
private $_visible = false;
/**
* Comment height (CSS style, i.e. XXpx or YYpt)
*
* @var string
*/
private $_height = '55.5pt';
/**
* Comment fill color
*
* @var PHPExcel_Style_Color
*/
private $_fillColor;
/**
* Create a new PHPExcel_Comment
*
*
* @throws Exception
*/
public function __construct()
@@ -121,7 +103,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_text = new PHPExcel_RichText();
$this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1');
}
/**
* Get Author
*
@@ -130,7 +112,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getAuthor() {
return $this->_author;
}
/**
* Set Author
*
@@ -141,7 +123,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_author = $pValue;
return $this;
}
/**
* Get Rich text comment
*
@@ -150,7 +132,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getText() {
return $this->_text;
}
/**
* Set Rich text comment
*
@@ -161,7 +143,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_text = $pValue;
return $this;
}
/**
* Get comment width (CSS style, i.e. XXpx or YYpt)
*
@@ -170,7 +152,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getWidth() {
return $this->_width;
}
/**
* Set comment width (CSS style, i.e. XXpx or YYpt)
*
@@ -181,7 +163,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_width = $value;
return $this;
}
/**
* Get comment height (CSS style, i.e. XXpx or YYpt)
*
@@ -190,7 +172,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getHeight() {
return $this->_height;
}
/**
* Set comment height (CSS style, i.e. XXpx or YYpt)
*
@@ -201,7 +183,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_height = $value;
return $this;
}
/**
* Get left margin (CSS style, i.e. XXpx or YYpt)
*
@@ -210,7 +192,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getMarginLeft() {
return $this->_marginLeft;
}
/**
* Set left margin (CSS style, i.e. XXpx or YYpt)
*
@@ -221,7 +203,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_marginLeft = $value;
return $this;
}
/**
* Get top margin (CSS style, i.e. XXpx or YYpt)
*
@@ -230,7 +212,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getMarginTop() {
return $this->_marginTop;
}
/**
* Set top margin (CSS style, i.e. XXpx or YYpt)
*
@@ -241,7 +223,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
$this->_marginTop = $value;
return $this;
}
/**
* Is the comment visible by default?
*
@@ -250,7 +232,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getVisible() {
return $this->_visible;
}
/**
* Set comment default visibility
*
@@ -258,10 +240,10 @@ class PHPExcel_Comment implements PHPExcel_IComparable
* @return PHPExcel_Comment
*/
public function setVisible($value = false) {
$this->_visible = $value;
$this->_visible = $value;
return $this;
}
/**
* Get fill color
*
@@ -270,12 +252,12 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function getFillColor() {
return $this->_fillColor;
}
/**
* Get hash code
*
* @return string Hash code
*/
*/
public function getHashCode() {
return md5(
$this->_author
@@ -289,38 +271,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
. __CLASS__
);
}
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_DocumentProperties
{

View File

@@ -2,48 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Shared_PasswordHasher */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PasswordHasher.php';
/**
* PHPExcel_DocumentSecurity
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_DocumentSecurity
{
@@ -53,35 +41,35 @@ class PHPExcel_DocumentSecurity
* @var boolean
*/
private $_lockRevision;
/**
* LockStructure
*
* @var boolean
*/
private $_lockStructure;
/**
* LockWindows
*
* @var boolean
*/
private $_lockWindows;
/**
* RevisionsPassword
*
* @var string
*/
private $_revisionsPassword;
/**
* WorkbookPassword
*
* @var string
*/
private $_workbookPassword;
/**
* Create a new PHPExcel_DocumentSecurity
*/
@@ -94,7 +82,7 @@ class PHPExcel_DocumentSecurity
$this->_revisionsPassword = '';
$this->_workbookPassword = '';
}
/**
* Is some sort of dcument security enabled?
*
@@ -105,7 +93,7 @@ class PHPExcel_DocumentSecurity
$this->_lockStructure ||
$this->_lockWindows;
}
/**
* Get LockRevision
*
@@ -114,7 +102,7 @@ class PHPExcel_DocumentSecurity
function getLockRevision() {
return $this->_lockRevision;
}
/**
* Set LockRevision
*
@@ -125,7 +113,7 @@ class PHPExcel_DocumentSecurity
$this->_lockRevision = $pValue;
return $this;
}
/**
* Get LockStructure
*
@@ -134,7 +122,7 @@ class PHPExcel_DocumentSecurity
function getLockStructure() {
return $this->_lockStructure;
}
/**
* Set LockStructure
*
@@ -145,7 +133,7 @@ class PHPExcel_DocumentSecurity
$this->_lockStructure = $pValue;
return $this;
}
/**
* Get LockWindows
*
@@ -154,7 +142,7 @@ class PHPExcel_DocumentSecurity
function getLockWindows() {
return $this->_lockWindows;
}
/**
* Set LockWindows
*
@@ -165,7 +153,7 @@ class PHPExcel_DocumentSecurity
$this->_lockWindows = $pValue;
return $this;
}
/**
* Get RevisionsPassword (hashed)
*
@@ -174,7 +162,7 @@ class PHPExcel_DocumentSecurity
function getRevisionsPassword() {
return $this->_revisionsPassword;
}
/**
* Set RevisionsPassword
*
@@ -189,7 +177,7 @@ class PHPExcel_DocumentSecurity
$this->_revisionsPassword = $pValue;
return $this;
}
/**
* Get WorkbookPassword (hashed)
*

View File

@@ -2,48 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/**
* PHPExcel_HashTable
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_HashTable
{
@@ -53,14 +41,14 @@ class PHPExcel_HashTable
* @var array
*/
public $_items = array();
/**
* HashTable key map
*
* @var array
*/
public $_keyMap = array();
/**
* Create a new PHPExcel_HashTable
*
@@ -74,7 +62,7 @@ class PHPExcel_HashTable
$this->addFromSource($pSource);
}
}
/**
* Add HashTable items from source
*
@@ -88,7 +76,7 @@ class PHPExcel_HashTable
} else if (!is_array($pSource)) {
throw new Exception('Invalid array parameter passed.');
}
foreach ($pSource as $item) {
$this->add($item);
}
@@ -101,28 +89,12 @@ class PHPExcel_HashTable
* @throws Exception
*/
public function add(PHPExcel_IComparable $pSource = null) {
// Determine hashcode
$hashCode = null;
$hashIndex = $pSource->getHashIndex();
if ( is_null ( $hashIndex ) ) {
$hashCode = $pSource->getHashCode();
} else if ( isset ( $this->_keyMap[$hashIndex] ) ) {
$hashCode = $this->_keyMap[$hashIndex];
} else {
$hashCode = $pSource->getHashCode();
}
// Add value
if (!isset($this->_items[ $hashCode ])) {
$this->_items[ $hashCode ] = $pSource;
$index = count($this->_items) - 1;
$this->_keyMap[ $index ] = $hashCode;
$pSource->setHashIndex( $index );
} else {
$pSource->setHashIndex( $this->_items[ $hashCode ]->getHashIndex() );
}
if (!isset($this->_items[ $pSource->getHashCode() ])) {
$this->_items[ $pSource->getHashCode() ] = $pSource;
$this->_keyMap[ count($this->_items) - 1 ] = $pSource->getHashCode();
}
}
/**
* Remove HashTable item
*
@@ -132,21 +104,21 @@ class PHPExcel_HashTable
public function remove(PHPExcel_IComparable $pSource = null) {
if (isset($this->_items[ $pSource->getHashCode() ])) {
unset($this->_items[ $pSource->getHashCode() ]);
$deleteKey = -1;
foreach ($this->_keyMap as $key => $value) {
foreach ($this->_keyMap as $key => $value) {
if ($deleteKey >= 0) {
$this->_keyMap[$key - 1] = $value;
}
if ($value == $pSource->getHashCode()) {
$deleteKey = $key;
}
}
unset($this->_keyMap[ count($this->_keyMap) - 1 ]);
}
unset($this->_keyMap[ count($this->_keyMap) - 1 ]);
}
}
/**
* Clear HashTable
*
@@ -155,7 +127,7 @@ class PHPExcel_HashTable
$this->_items = array();
$this->_keyMap = array();
}
/**
* Count
*
@@ -164,7 +136,7 @@ class PHPExcel_HashTable
public function count() {
return count($this->_items);
}
/**
* Get index for hash code
*
@@ -174,7 +146,7 @@ class PHPExcel_HashTable
public function getIndexForHashCode($pHashCode = '') {
return array_search($pHashCode, $this->_keyMap);
}
/**
* Get by index
*
@@ -186,10 +158,10 @@ class PHPExcel_HashTable
if (isset($this->_keyMap[$pIndex])) {
return $this->getByHashCode( $this->_keyMap[$pIndex] );
}
return null;
}
/**
* Get by hashcode
*
@@ -201,10 +173,10 @@ class PHPExcel_HashTable
if (isset($this->_items[$pHashCode])) {
return $this->_items[$pHashCode];
}
return null;
}
/**
* HashTable to array
*
@@ -213,7 +185,7 @@ class PHPExcel_HashTable
public function toArray() {
return $this->_items;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/

View File

@@ -18,9 +18,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -29,7 +29,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_IComparable
{
@@ -39,24 +39,5 @@ interface PHPExcel_IComparable
* @return string Hash code
*/
public function getHashCode();
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex();
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value);
}

View File

@@ -2,98 +2,106 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/** PHPExcel */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_IWriter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Writer/IWriter.php';
/** PHPExcel_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/**
* PHPExcel_IOFactory
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_IOFactory
{
{
/**
* Search locations
* Search locations
*
* @var array
* @var array
* @access private
* @static
*/
private static $_searchLocations = array(
array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ),
array( 'type' => 'IReader', 'path' => 'PHPExcel/Reader/{0}.php', 'class' => 'PHPExcel_Reader_{0}' )
);
/**
* Autoresolve classes
*
* @var array
* Autoresolve classes
*
* @var array
* @access private
* @static
*/
private static $_autoResolveClasses = array(
'Excel2007',
'Excel5',
'Excel2003XML',
'OOCalc',
'SYLK',
'Serialized',
'CSV'
'CSV',
);
/**
* Private constructor for PHPExcel_IOFactory
* Private constructor for PHPExcel_IOFactory
*/
private function __construct() { }
/**
* Get search locations
* Get search locations
*
* @return array
* @static
* @access public
* @return array
*/
public static function getSearchLocations() {
return self::$_searchLocations;
}
} // function getSearchLocations()
/**
* Set search locations
*
* @param array $value
* @throws Exception
* Set search locations
*
* @static
* @access public
* @param array $value
* @throws Exception
*/
public static function setSearchLocations($value) {
if (is_array($value)) {
@@ -101,101 +109,162 @@ class PHPExcel_IOFactory
} else {
throw new Exception('Invalid parameter passed.');
}
}
} // function setSearchLocations()
/**
* Add search location
*
* @param string $type Example: IWriter
* @param string $location Example: PHPExcel/Writer/{0}.php
* @param string $classname Example: PHPExcel_Writer_{0}
* Add search location
*
* @static
* @access public
* @param string $type Example: IWriter
* @param string $location Example: PHPExcel/Writer/{0}.php
* @param string $classname Example: PHPExcel_Writer_{0}
*/
public static function addSearchLocation($type = '', $location = '', $classname = '') {
self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname );
}
} // function addSearchLocation()
/**
* Create PHPExcel_Writer_IWriter
* Create PHPExcel_Writer_IWriter
*
* @param PHPExcel $phpExcel
* @param string $writerType Example: Excel2007
* @return PHPExcel_Writer_IWriter
* @static
* @access public
* @param PHPExcel $phpExcel
* @param string $writerType Example: Excel2007
* @return PHPExcel_Writer_IWriter
* @throws Exception
*/
public static function createWriter(PHPExcel $phpExcel, $writerType = '') {
// Search type
$searchType = 'IWriter';
// Include class
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $writerType, $searchLocation['class']);
$classFile = str_replace('{0}', $writerType, $searchLocation['path']);
if (!class_exists($className)) {
require_once PHPEXCEL_ROOT . $classFile;
}
$instance = new $className($phpExcel);
if (!is_null($instance)) {
return $instance;
}
}
}
// Nothing found...
throw new Exception("No $searchType found for type $writerType");
}
} // function createWriter()
/**
* Create PHPExcel_Reader_IReader
* Create PHPExcel_Reader_IReader
*
* @param string $readerType Example: Excel2007
* @return PHPExcel_Reader_IReader
* @static
* @access public
* @param string $readerType Example: Excel2007
* @return PHPExcel_Reader_IReader
* @throws Exception
*/
public static function createReader($readerType = '') {
// Search type
$searchType = 'IReader';
// Include class
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $readerType, $searchLocation['class']);
$classFile = str_replace('{0}', $readerType, $searchLocation['path']);
if (!class_exists($className)) {
require_once PHPEXCEL_ROOT . $classFile;
}
$instance = new $className();
if (!is_null($instance)) {
return $instance;
}
}
}
// Nothing found...
throw new Exception("No $searchType found for type $readerType");
}
} // function createReader()
/**
* Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution
* Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution
*
* @param string $pFileName
* @return PHPExcel
*/
* @static
* @access public
* @param string $pFileName
* @return PHPExcel
* @throws Exception
*/
public static function load($pFilename) {
$reader = self::createReaderForFile($pFilename);
return $reader->load($pFilename);
}
} // function load()
/**
* Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution
* Identify file type using automatic PHPExcel_Reader_IReader resolution
*
* @param string $pFileName
* @return PHPExcel_Reader_IReader
* @throws Exception
*/
* @static
* @access public
* @param string $pFileName
* @return string
* @throws Exception
*/
public static function identify($pFilename) {
$reader = self::createReaderForFile($pFilename);
$className = get_class($reader);
$classType = explode('_',$className);
unset($reader);
return array_pop($classType);
} // function identify()
/**
* Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution
*
* @static
* @access public
* @param string $pFileName
* @return PHPExcel_Reader_IReader
* @throws Exception
*/
public static function createReaderForFile($pFilename) {
// First, lucky guess by inspecting file extension
$pathinfo = pathinfo($pFilename);
if (isset($pathinfo['extension'])) {
switch (strtolower($pathinfo['extension'])) {
case 'xlsx':
$reader = self::createReader('Excel2007');
break;
case 'xls':
$reader = self::createReader('Excel5');
break;
case 'ods':
$reader = self::createReader('OOCalc');
break;
case 'slk':
$reader = self::createReader('SYLK');
break;
case 'xml':
$reader = self::createReader('Excel2003XML');
break;
case 'csv':
// Do nothing
// We must not try to use CSV reader since it loads
// all files including Excel files etc.
break;
default:
break;
}
// Let's see if we are lucky
if (isset($reader) && $reader->canRead($pFilename)) {
return $reader;
}
}
// If we reach here then "lucky guess" didn't give any result
// Try loading using self::$_autoResolveClasses
foreach (self::$_autoResolveClasses as $autoResolveClass) {
$reader = self::createReader($autoResolveClass);
@@ -204,6 +273,5 @@ class PHPExcel_IOFactory
}
}
throw new Exception("Could not automatically determine PHPExcel_Reader_IReader for file.");
}
} // function createReaderForFile()
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,36 +20,18 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_ReferenceHelper */
require_once PHPEXCEL_ROOT . 'PHPExcel/ReferenceHelper.php';
/**
* PHPExcel_NamedRange
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_NamedRange
{
@@ -81,6 +63,13 @@ class PHPExcel_NamedRange
*/
private $_localOnly;
/**
* Scope
*
* @var PHPExcel_Worksheet
*/
private $_scope;
/**
* Create a new NamedRange
*
@@ -88,8 +77,9 @@ class PHPExcel_NamedRange
* @param PHPExcel_Worksheet $pWorksheet
* @param string $pRange
* @param bool $pLocalOnly
* @param PHPExcel_Worksheet|null $pScope Scope. Only applies when $pLocalOnly = true. Null for global scope.
*/
public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false)
public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null)
{
// Validate data
if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) {
@@ -101,6 +91,8 @@ class PHPExcel_NamedRange
$this->_worksheet = $pWorksheet;
$this->_range = $pRange;
$this->_localOnly = $pLocalOnly;
$this->_scope = ($pLocalOnly == true) ?
(($pScope == null) ? $pWorksheet : $pScope) : null;
}
/**
@@ -201,6 +193,28 @@ class PHPExcel_NamedRange
*/
public function setLocalOnly($value = false) {
$this->_localOnly = $value;
$this->_scope = $value ? $this->_worksheet : null;
return $this;
}
/**
* Get scope
*
* @return PHPExcel_Worksheet|null
*/
public function getScope() {
return $this->_scope;
}
/**
* Set scope
*
* @param PHPExcel_Worksheet|null $value
* @return PHPExcel_NamedRange
*/
public function setScope(PHPExcel_Worksheet $value = null) {
$this->_scope = $value;
$this->_localOnly = ($value == null) ? false : true;
return $this;
}
@@ -208,7 +222,7 @@ class PHPExcel_NamedRange
* Resolve a named range to a regular cell range
*
* @param string $pNamedRange Named range
* @param PHPExcel_Worksheet $pSheet Worksheet
* @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
* @return PHPExcel_NamedRange
*/
public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -32,101 +32,109 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/** PHPExcel */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Reader_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Reader_DefaultReadFilter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/DefaultReadFilter.php';
/**
* PHPExcel_Reader_CSV
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
{
/**
* Delimiter
* Input encoding
*
* @var string
* @access private
* @var string
*/
private $_inputEncoding;
/**
* Delimiter
*
* @access private
* @var string
*/
private $_delimiter;
/**
* Enclosure
* Enclosure
*
* @var string
* @access private
* @var string
*/
private $_enclosure;
/**
* Line ending
* Line ending
*
* @var string
* @access private
* @var string
*/
private $_lineEnding;
/**
* Sheet index to read
* Sheet index to read
*
* @var int
* @access private
* @var int
*/
private $_sheetIndex;
/**
* PHPExcel_Reader_IReadFilter instance
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
* @access private
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Create a new PHPExcel_Reader_CSV
* Create a new PHPExcel_Reader_CSV
*/
public function __construct() {
$this->_inputEncoding = 'UTF-8';
$this->_delimiter = ',';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
} // function __construct()
/**
* Can the current PHPExcel_Reader_IReader read the file?
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
* @access public
* @param string $pFileName
* @return boolean
* @throws Exception
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Check if it is a CSV file (using file name)
return (substr(strtolower($pFilename), -3) == 'csv');
}
return true;
} // function canRead()
/**
* Loads PHPExcel from file
* Loads PHPExcel from file
*
* @param string $pFilename
* @throws Exception
* @access public
* @param string $pFilename
* @return PHPExcel
* @throws Exception
*/
public function load($pFilename)
{
@@ -135,32 +143,60 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
} // function load()
/**
* Read filter
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
* @access public
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
} // function getReadFilter()
/**
* Set read filter
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
* @access public
* @param PHPExcel_Reader_IReadFilter $pValue
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
}
return $this;
} // function setReadFilter()
/**
* Loads PHPExcel from file into PHPExcel instance
* Set input encoding
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @throws Exception
* @access public
* @param string $pValue Input encoding
*/
public function setInputEncoding($pValue = 'UTF-8')
{
$this->_inputEncoding = $pValue;
return $this;
} // function setInputEncoding()
/**
* Get input encoding
*
* @access public
* @return string
*/
public function getInputEncoding()
{
return $this->_inputEncoding;
} // function getInputEncoding()
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @access public
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
@@ -181,7 +217,17 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
throw new Exception("Could not open file $pFilename for reading.");
}
// Loop trough file
// Skip BOM, if any
switch ($this->_inputEncoding) {
case 'UTF-8':
fgets($fileHandle, 4) == "\xEF\xBB\xBF" ?
fseek($fileHandle, 3) : fseek($fileHandle, 0);
break;
default:
break;
}
// Loop through file
$currentRow = 0;
$rowData = array();
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
@@ -194,10 +240,13 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
$rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]);
$rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]);
// Convert encoding if necessary
if ($this->_inputEncoding !== 'UTF-8') {
$rowData[$i] = PHPExcel_Shared_String::ConvertEncoding($rowData[$i], 'UTF-8', $this->_inputEncoding);
}
// Set cell value
$objPHPExcel->getActiveSheet()->setCellValue(
$columnLetter . $currentRow, $rowData[$i]
);
$objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowData[$i]);
}
}
}
@@ -207,42 +256,46 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
// Return
return $objPHPExcel;
}
} // function loadIntoExisting()
/**
* Get delimiter
* Get delimiter
*
* @return string
* @access public
* @return string
*/
public function getDelimiter() {
return $this->_delimiter;
}
} // function getDelimiter()
/**
* Set delimiter
* Set delimiter
*
* @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_CSV
* @access public
* @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_CSV
*/
public function setDelimiter($pValue = ',') {
$this->_delimiter = $pValue;
return $this;
}
} // function setDelimiter()
/**
* Get enclosure
* Get enclosure
*
* @return string
* @access public
* @return string
*/
public function getEnclosure() {
return $this->_enclosure;
}
} // function getEnclosure()
/**
* Set enclosure
* Set enclosure
*
* @param string $pValue Enclosure, defaults to "
* @return PHPExcel_Reader_CSV
* @access public
* @param string $pValue Enclosure, defaults to "
* @return PHPExcel_Reader_CSV
*/
public function setEnclosure($pValue = '"') {
if ($pValue == '') {
@@ -250,45 +303,49 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
}
$this->_enclosure = $pValue;
return $this;
}
} // function setEnclosure()
/**
* Get line ending
* Get line ending
*
* @return string
* @access public
* @return string
*/
public function getLineEnding() {
return $this->_lineEnding;
}
} // function getLineEnding()
/**
* Set line ending
* Set line ending
*
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
* @return PHPExcel_Reader_CSV
* @access public
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
* @return PHPExcel_Reader_CSV
*/
public function setLineEnding($pValue = PHP_EOL) {
$this->_lineEnding = $pValue;
return $this;
}
} // function setLineEnding()
/**
* Get sheet index
* Get sheet index
*
* @return int
* @access public
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
} // function getSheetIndex()
/**
* Set sheet index
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_CSV
* @access public
* @param int $pValue Sheet index
* @return PHPExcel_Reader_CSV
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
} // function setSheetIndex()
}

View File

@@ -2,27 +2,27 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -32,18 +32,21 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/** PHPExcel_Reader_IReadFilter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReadFilter.php';
/**
* PHPExcel_Reader_DefaultReadFilter
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
{
@@ -54,7 +57,7 @@ class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
* @param $row Row index
* @param $worksheetName Optional worksheet name
* @return boolean
*/
*/
public function readCell($column, $row, $worksheetName = '') {
return true;
}

View File

@@ -0,0 +1,688 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
* PHPExcel_Reader_Excel2003XML
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
{
/**
* Read data only?
*
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restict which sheets should be loaded?
*
* @var array
*/
private $_loadSheetsOnly = null;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
* @var array
*/
private $_styles = array();
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Read data only?
*
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
return $this;
}
/**
* Get which sheets to load
*
* @return mixed
*/
public function getLoadSheetsOnly()
{
return $this->_loadSheetsOnly;
}
/**
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadSheetsOnly($value = null)
{
$this->_loadSheetsOnly = is_array($value) ?
$value : array($value);
return $this;
}
/**
* Set all sheets to load
*
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadAllSheets()
{
$this->_loadSheetsOnly = null;
return $this;
}
/**
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
/**
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
* @return PHPExcel_Reader_Excel2007
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Create a new PHPExcel_Reader_Excel2003XML
*/
public function __construct() {
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Office xmlns:o="urn:schemas-microsoft-com:office:office"
// Excel xmlns:x="urn:schemas-microsoft-com:office:excel"
// XML Spreadsheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
// Spreadsheet component xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
// XML schema xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
// XML data type xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
// MS-persist recordset xmlns:rs="urn:schemas-microsoft-com:rowset"
// Rowset xmlns:z="#RowsetSchema"
//
$signature = array(
'<?xml version="1.0"?>',
'<?mso-application progid="Excel.Sheet"?>'
);
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Read sample data (first 2 KB will do)
$fh = fopen($pFilename, 'r');
$data = fread($fh, 2048);
fclose($fh);
$headers = explode("\n",$data);
$valid = true;
foreach($signature as $key => $match) {
if (isset($headers[$key])) {
$line = trim(rtrim($headers[$key], "\r\n"));
if ($line != $match) {
$valid = false;
break;
}
} else {
$valid = false;
break;
}
}
return $valid;
}
/**
* Loads PHPExcel from file
*
* @param string $pFilename
* @return PHPExcel
* @throws Exception
*/
public function load($pFilename)
{
// Create new PHPExcel
$objPHPExcel = new PHPExcel();
// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
$styleAttributeValue = strtolower($styleAttributeValue);
foreach($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
$styleAttributeValue = $style;
return true;
}
}
return false;
}
/**
* pixel units to excel width units(units of 1/256th of a character width)
* @param pxs
* @return
*/
private static function _pixel2WidthUnits($pxs) {
$UNIT_OFFSET_MAP = array(0, 36, 73, 109, 146, 182, 219);
$widthUnits = 256 * ($pxs / 7);
$widthUnits += $UNIT_OFFSET_MAP[($pxs % 7)];
return $widthUnits;
}
/**
* excel width units(units of 1/256th of a character width) to pixel units
* @param widthUnits
* @return
*/
private static function _widthUnits2Pixel($widthUnits) {
$pixels = ($widthUnits / 256) * 7;
$offsetWidthUnits = $widthUnits % 256;
$pixels += round($offsetWidthUnits / (256 / 7));
return $pixels;
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
$fromFormats = array('\-', '\ ');
$toFormats = array('-', ' ');
$underlineStyles = array (
PHPExcel_Style_Font::UNDERLINE_NONE,
PHPExcel_Style_Font::UNDERLINE_DOUBLE,
PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
PHPExcel_Style_Font::UNDERLINE_SINGLE,
PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
);
$verticalAlignmentStyles = array (
PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
PHPExcel_Style_Alignment::VERTICAL_TOP,
PHPExcel_Style_Alignment::VERTICAL_CENTER,
PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
);
$horizontalAlignmentStyles = array (
PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
);
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$xml = simplexml_load_file($pFilename);
$namespaces = $xml->getNamespaces(true);
// echo '<pre>';
// print_r($namespaces);
// echo '</pre><hr />';
//
// echo '<pre>';
// print_r($xml);
// echo '</pre><hr />';
//
$docProps = $objPHPExcel->getProperties();
foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) {
switch ($propertyName) {
case 'Title' :
$docProps->setTitle($propertyValue);
break;
case 'Subject' :
$docProps->setSubject($propertyValue);
break;
case 'Author' :
$docProps->setCreator($propertyValue);
break;
case 'Created' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
break;
case 'LastAuthor' :
$docProps->setLastModifiedBy($propertyValue);
break;
case 'Company' :
$docProps->setCompany($propertyValue);
break;
case 'Category' :
$docProps->setCategory($propertyValue);
break;
case 'Keywords' :
$docProps->setKeywords($propertyValue);
break;
case 'Description' :
$docProps->setDescription($propertyValue);
break;
}
}
foreach($xml->Styles[0] as $style) {
$style_ss = $style->attributes($namespaces['ss']);
$styleID = (string) $style_ss['ID'];
// echo 'Style ID = '.$styleID.'<br />';
if ($styleID == 'Default') {
$this->_styles['Default'] = array();
} else {
$this->_styles[$styleID] = $this->_styles['Default'];
}
foreach ($style as $styleType => $styleData) {
$styleAttributes = $styleData->attributes($namespaces['ss']);
// echo $styleType.'<br />';
switch ($styleType) {
case 'Alignment' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'Vertical' :
if (self::identifyFixedStyleValue($verticalAlignmentStyles,$styleAttributeValue)) {
$this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
}
break;
case 'Horizontal' :
if (self::identifyFixedStyleValue($horizontalAlignmentStyles,$styleAttributeValue)) {
$this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
}
break;
case 'WrapText' :
$this->_styles[$styleID]['alignment']['wrap'] = true;
break;
}
}
break;
case 'Borders' :
foreach($styleData->Border as $borderStyle) {
$borderAttributes = $borderStyle->attributes($namespaces['ss']);
$thisBorder = array();
foreach($borderAttributes as $borderStyleKey => $borderStyleValue) {
// echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
switch ($borderStyleKey) {
case 'LineStyle' :
$thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
// $thisBorder['style'] = $borderStyleValue;
break;
case 'Weight' :
// $thisBorder['style'] = $borderStyleValue;
break;
case 'Position' :
$borderPosition = strtolower($borderStyleValue);
break;
case 'Color' :
$borderColour = substr($borderStyleValue,1);
$thisBorder['color']['rgb'] = $borderColour;
break;
}
}
if (count($thisBorder) > 0) {
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
$this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
}
}
}
break;
case 'Font' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'FontName' :
$this->_styles[$styleID]['font']['name'] = $styleAttributeValue;
break;
case 'Size' :
$this->_styles[$styleID]['font']['size'] = $styleAttributeValue;
break;
case 'Color' :
$this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1);
break;
case 'Bold' :
$this->_styles[$styleID]['font']['bold'] = true;
break;
case 'Italic' :
$this->_styles[$styleID]['font']['italic'] = true;
break;
case 'Underline' :
if (self::identifyFixedStyleValue($underlineStyles,$styleAttributeValue)) {
$this->_styles[$styleID]['font']['underline'] = $styleAttributeValue;
}
break;
}
}
break;
case 'Interior' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
switch ($styleAttributeKey) {
case 'Color' :
$this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1);
break;
}
}
break;
case 'NumberFormat' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
$styleAttributeValue = str_replace($fromFormats,$toFormats,$styleAttributeValue);
switch ($styleAttributeValue) {
case 'Short Date' :
$styleAttributeValue = 'dd/mm/yyyy';
break;
}
if ($styleAttributeValue > '') {
$this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue;
}
}
break;
case 'Protection' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
}
break;
}
}
// print_r($this->_styles[$styleID]);
// echo '<hr />';
}
// echo '<hr />';
$worksheetID = 0;
foreach($xml->Worksheet as $worksheet) {
$worksheet_ss = $worksheet->attributes($namespaces['ss']);
if ((isset($this->_loadSheetsOnly)) && (isset($worksheet_ss['Name'])) &&
(!in_array($worksheet_ss['Name'], $this->_loadSheetsOnly))) {
continue;
}
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
if (isset($worksheet_ss['Name'])) {
$worksheetName = (string) $worksheet_ss['Name'];
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
}
$columnID = 'A';
foreach($worksheet->Table->Column as $columnData) {
$columnData_ss = $columnData->attributes($namespaces['ss']);
if (isset($columnData_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1);
}
if (isset($columnData_ss['Width'])) {
$columnWidth = $columnData_ss['Width'];
// echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />';
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth / 5.4);
}
++$columnID;
}
$rowID = 1;
foreach($worksheet->Table->Row as $rowData) {
$row_ss = $rowData->attributes($namespaces['ss']);
if (isset($row_ss['Index'])) {
$rowID = (integer) $row_ss['Index'];
}
// echo '<b>Row '.$rowID.'</b><br />';
if (isset($row_ss['StyleID'])) {
$rowStyle = $row_ss['StyleID'];
}
if (isset($row_ss['Height'])) {
$rowHeight = $row_ss['Height'];
// echo '<b>Setting row height to '.$rowHeight.'</b><br />';
$objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight);
}
$columnID = 'A';
foreach($rowData->Cell as $cell) {
$cell_ss = $cell->attributes($namespaces['ss']);
if (isset($cell_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
}
$cellRange = $columnID.$rowID;
if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
$columnTo = $columnID;
if (isset($cell_ss['MergeAcross'])) {
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] -1);
}
$rowTo = $rowID;
if (isset($cell_ss['MergeDown'])) {
$rowTo = $rowTo + $cell_ss['MergeDown'];
}
$cellRange .= ':'.$columnTo.$rowTo;
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
}
$hasCalculatedValue = false;
$cellDataFormula = '';
if (isset($cell_ss['Formula'])) {
$cellDataFormula = $cell_ss['Formula'];
$hasCalculatedValue = true;
}
if (isset($cell->Data)) {
$cellValue = $cellData = $cell->Data;
$type = PHPExcel_Cell_DataType::TYPE_NULL;
$cellData_ss = $cellData->attributes($namespaces['ss']);
if (isset($cellData_ss['Type'])) {
$cellDataType = $cellData_ss['Type'];
switch ($cellDataType) {
/*
const TYPE_STRING = 's';
const TYPE_FORMULA = 'f';
const TYPE_NUMERIC = 'n';
const TYPE_BOOL = 'b';
const TYPE_NULL = 's';
const TYPE_INLINE = 'inlineStr';
const TYPE_ERROR = 'e';
*/
case 'String' :
$type = PHPExcel_Cell_DataType::TYPE_STRING;
break;
case 'Number' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$cellValue = (float) $cellValue;
if (floor($cellValue) == $cellValue) {
$cellValue = (integer) $cellValue;
}
break;
case 'Boolean' :
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
$cellValue = ($cellValue != 0);
break;
case 'DateTime' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
break;
case 'Error' :
$type = PHPExcel_Cell_DataType::TYPE_ERROR;
break;
}
}
if ($hasCalculatedValue) {
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
// Convert R1C1 style references to A1 style references (but only when not quoted)
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if (($key % 2) == 0) {
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
// through the formula from left to right. Reversing means that we work right to left.through
// the formula
$cellReferences = array_reverse($cellReferences);
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
// then modify the formula to use that new reference
foreach($cellReferences as $cellReference) {
$rowReference = $cellReference[2][0];
// Empty R reference is the current row
if ($rowReference == '') $rowReference = $rowID;
// Bracketed R references are relative to the current row
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
$columnReference = $cellReference[4][0];
// Empty C reference is the current column
if ($columnReference == '') $columnReference = $columnNumber;
// Bracketed C references are relative to the current column
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
}
}
}
unset($value);
// Then rebuild the formula string
$cellDataFormula = implode('"',$temp);
}
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
//
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $cellValue),$type);
if ($hasCalculatedValue) {
// echo 'Forumla result is '.$cellValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue);
}
}
if (isset($cell_ss['StyleID'])) {
$style = (string) $cell_ss['StyleID'];
// echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
if ((isset($this->_styles[$style])) && (count($this->_styles[$style]) > 0)) {
// echo 'Cell '.$columnID.$rowID.'<br />';
// print_r($this->_styles[$style]);
// echo '<br />';
if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(NULL);
}
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
}
}
++$columnID;
}
++$rowID;
}
++$worksheetID;
}
// Return
return $objPHPExcel;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_Excel2003XML
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,49 +20,17 @@
*
* @category PHPExcel
* @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Shared_Escher_DggContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer.php';
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php';
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php';
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php';
/** PHPExcel_Shared_Escher_DgContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer.php';
/** PHPExcel_Shared_Escher_DgContainer_SpgrContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer/SpgrContainer.php';
/** PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php';
/**
* PHPExcel_Reader_Excel5_Escher
*
* @category PHPExcel
* @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel5_Escher
{
@@ -122,7 +90,7 @@ class PHPExcel_Reader_Excel5_Escher
{
$this->_object = $object;
}
/**
* Load Escher stream data. May be a partial Escher stream.
*
@@ -136,14 +104,14 @@ class PHPExcel_Reader_Excel5_Escher
$this->_dataSize = strlen($this->_data);
$this->_pos = 0;
// Parse Escher stream
while ($this->_pos < $this->_dataSize) {
// offset: 2; size: 2: Record Type
$fbt = $this->_GetInt2d($this->_data, $this->_pos + 2);
switch ($fbt) {
case self::DGGCONTAINER: $this->_readDggContainer(); break;
case self::DGG: $this->_readDgg(); break;
@@ -166,7 +134,7 @@ class PHPExcel_Reader_Excel5_Escher
default: $this->_readDefault(); break;
}
}
return $this->_object;
}
@@ -177,16 +145,16 @@ class PHPExcel_Reader_Excel5_Escher
{
// offset 0; size: 2; recVer and recInstance
$verInstance = $this->_GetInt2d($this->_data, $this->_pos);
// offset: 2; size: 2: Record Type
$fbt = $this->_GetInt2d($this->_data, $this->_pos + 2);
// bit: 0-3; mask: 0x000F; recVer
$recVer = (0x000F & $verInstance) >> 0;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
}
@@ -216,7 +184,7 @@ class PHPExcel_Reader_Excel5_Escher
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
}
@@ -245,22 +213,22 @@ class PHPExcel_Reader_Excel5_Escher
private function _readBSE()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// add BSE to BstoreContainer
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE();
$this->_object->addBSE($BSE);
$BSE->setBLIPType($recInstance);
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE)
$btWin32 = ord($recordData[0]);
@@ -311,38 +279,38 @@ class PHPExcel_Reader_Excel5_Escher
private function _readBlipJPEG()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
$pos = 0;
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
$rgbUid1 = substr($recordData, 0, 16);
$pos += 16;
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
if (in_array($recInstance, array(0x046B, 0x06E3))) {
$rgbUid2 = substr($recordData, 16, 16);
$pos += 16;
}
// offset: var; size: 1; tag
$tag = ord($recordData{$pos});
$pos += 1;
// offset: var; size: var; the raw image data
$data = substr($recordData, $pos);
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
$blip->setData($data);
$this->_object->setBlip($blip);
}
@@ -352,38 +320,38 @@ class PHPExcel_Reader_Excel5_Escher
private function _readBlipPNG()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
$pos = 0;
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
$rgbUid1 = substr($recordData, 0, 16);
$pos += 16;
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
if ($recInstance == 0x06E1) {
$rgbUid2 = substr($recordData, 16, 16);
$pos += 16;
}
// offset: var; size: 1; tag
$tag = ord($recordData{$pos});
$pos += 1;
// offset: var; size: var; the raw image data
$data = substr($recordData, $pos);
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
$blip->setData($data);
$this->_object->setBlip($blip);
}
@@ -393,13 +361,13 @@ class PHPExcel_Reader_Excel5_Escher
private function _readOPT()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
@@ -412,7 +380,7 @@ class PHPExcel_Reader_Excel5_Escher
private function _readTertiaryOPT()
{
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
@@ -566,10 +534,10 @@ class PHPExcel_Reader_Excel5_Escher
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// offset: 2; size: 2; upper-left corner column index (0-based)
$c1 = $this->_GetInt2d($recordData, 2);

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_Reader_IReadFilter
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_Reader_IReader
{

View File

@@ -0,0 +1,498 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
* PHPExcel_Reader_OOCalc
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
{
/**
* Read data only?
*
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restict which sheets should be loaded?
*
* @var array
*/
private $_loadSheetsOnly = null;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
* @var array
*/
private $_styles = array();
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Read data only?
*
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
return $this;
}
/**
* Get which sheets to load
*
* @return mixed
*/
public function getLoadSheetsOnly()
{
return $this->_loadSheetsOnly;
}
/**
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadSheetsOnly($value = null)
{
$this->_loadSheetsOnly = is_array($value) ?
$value : array($value);
return $this;
}
/**
* Set all sheets to load
*
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadAllSheets()
{
$this->_loadSheetsOnly = null;
return $this;
}
/**
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
/**
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
* @return PHPExcel_Reader_Excel2007
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Create a new PHPExcel_Reader_OOCalc
*/
public function __construct() {
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Check if zip class exists
if (!class_exists('ZipArchive')) {
return false;
}
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Load file
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$mimeType = $zip->getFromName("mimetype");
$zip->close();
return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
}
return false;
}
/**
* Loads PHPExcel from file
*
* @param string $pFilename
* @return PHPExcel
* @throws Exception
*/
public function load($pFilename)
{
// Create new PHPExcel
$objPHPExcel = new PHPExcel();
// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
$styleAttributeValue = strtolower($styleAttributeValue);
foreach($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
$styleAttributeValue = $style;
return true;
}
}
return false;
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
// echo '<h1>Meta Information</h1>';
$xml = simplexml_load_string($zip->getFromName("meta.xml"));
$namespacesMeta = $xml->getNamespaces(true);
// echo '<pre>';
// print_r($namespacesMeta);
// echo '</pre><hr />';
$docProps = $objPHPExcel->getProperties();
$officeProperty = $xml->children($namespacesMeta['office']);
foreach($officeProperty as $officePropertyData) {
$officePropertyDC = array();
if (isset($namespacesMeta['dc'])) {
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
}
foreach($officePropertyDC as $propertyName => $propertyValue) {
// echo $propertyName.' = '.$propertyValue.'<hr />';
switch ($propertyName) {
case 'title' :
$docProps->setTitle($propertyValue);
break;
case 'subject' :
$docProps->setSubject($propertyValue);
break;
case 'creator' :
$docProps->setCreator($propertyValue);
break;
case 'date' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
break;
case 'description' :
$docProps->setDescription($propertyValue);
break;
}
}
$officePropertyMeta = array();
if (isset($namespacesMeta['dc'])) {
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
}
foreach($officePropertyMeta as $propertyName => $propertyValue) {
$propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
// echo $propertyName.' = '.$propertyValue.'<br />';
// foreach ($propertyValueAttributes as $key => $value) {
// echo $key.' = '.$value.'<br />';
// }
// echo '<hr />';
//
switch ($propertyName) {
case 'keyword' :
$docProps->setKeywords($propertyValue);
break;
}
}
}
// echo '<h1>Workbook Content</h1>';
$xml = simplexml_load_string($zip->getFromName("content.xml"));
$namespacesContent = $xml->getNamespaces(true);
// echo '<pre>';
// print_r($namespacesContent);
// echo '</pre><hr />';
$workbook = $xml->children($namespacesContent['office']);
foreach($workbook->body->spreadsheet as $workbookData) {
$workbookData = $workbookData->children($namespacesContent['table']);
$worksheetID = 0;
foreach($workbookData->table as $worksheetDataSet) {
$worksheetData = $worksheetDataSet->children($namespacesContent['table']);
// print_r($worksheetData);
// echo '<br />';
$worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
// print_r($worksheetDataAttributes);
// echo '<br />';
if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
(!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
continue;
}
// echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
if (isset($worksheetDataAttributes['name'])) {
$worksheetName = (string) $worksheetDataAttributes['name'];
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
}
$rowID = 1;
foreach($worksheetData as $key => $rowData) {
// echo '<b>'.$key.'</b><br />';
switch ($key) {
case 'table-row' :
$columnID = 'A';
foreach($rowData as $key => $cellData) {
// echo '<b>'.$columnID.$rowID.'</b><br />';
$cellDataText = $cellData->children($namespacesContent['text']);
$cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
$cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
// echo 'Office Attributes: ';
// print_r($cellDataOfficeAttributes);
// echo '<br />Table Attributes: ';
// print_r($cellDataTableAttributes);
// echo '<br />Cell Data Text';
// print_r($cellDataText);
// echo '<br />';
//
$type = $formatting = $hyperlink = null;
$hasCalculatedValue = false;
$cellDataFormula = '';
if (isset($cellDataTableAttributes['formula'])) {
$cellDataFormula = $cellDataTableAttributes['formula'];
$hasCalculatedValue = true;
}
if (isset($cellDataText->p)) {
// echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
switch ($cellDataOfficeAttributes['value-type']) {
case 'string' :
$type = PHPExcel_Cell_DataType::TYPE_STRING;
$dataValue = $cellDataText->p;
if (isset($dataValue->a)) {
$dataValue = $dataValue->a;
$cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
$hyperlink = $cellXLinkAttributes['href'];
}
break;
case 'boolean' :
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
$dataValue = ($cellDataText->p == 'TRUE') ? True : False;
break;
case 'float' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = (float) $cellDataOfficeAttributes['value'];
if (floor($dataValue) == $dataValue) {
$dataValue = (integer) $dataValue;
}
break;
case 'date' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dateObj = date_create($cellDataOfficeAttributes['date-value']);
list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
$dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
if ($dataValue != floor($dataValue)) {
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
} else {
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
}
break;
case 'time' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
break;
}
// echo 'Data value is '.$dataValue.'<br />';
// if (!is_null($hyperlink)) {
// echo 'Hyperlink is '.$hyperlink.'<br />';
// }
}
if ($hasCalculatedValue) {
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
// echo 'Formula: '.$cellDataFormula.'<br />';
$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if (($key % 2) == 0) {
$value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
$value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
$value = PHPExcel_Calculation::_translateSeparator(';',',',$value);
}
}
unset($value);
// Then rebuild the formula string
$cellDataFormula = implode('"',$temp);
// echo 'Adjusted Formula: '.$cellDataFormula.'<br />';
}
if (!is_null($type)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
if ($hasCalculatedValue) {
// echo 'Forumla result is '.$dataValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($dataValue);
}
if (($cellDataOfficeAttributes['value-type'] == 'date') ||
($cellDataOfficeAttributes['value-type'] == 'time')) {
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rowID)->getNumberFormat()->setFormatCode($formatting);
}
if (!is_null($hyperlink)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->getHyperlink()->setUrl($hyperlink);
}
}
// Merged cells
if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
$columnTo = $columnID;
if (isset($cellDataTableAttributes['number-columns-spanned'])) {
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
}
$rowTo = $rowID;
if (isset($cellDataTableAttributes['number-rows-spanned'])) {
$rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
}
$cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
}
if (isset($cellDataTableAttributes['number-columns-repeated'])) {
// echo 'Repeated '.$cellDataTableAttributes['number-columns-repeated'].' times<br />';
$columnID = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-repeated'] - 2);
}
++$columnID;
}
++$rowID;
break;
}
}
++$worksheetID;
}
}
}
// Return
return $objPHPExcel;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_OOCalc
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

View File

@@ -0,0 +1,509 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
* PHPExcel_Reader_SYLK
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
{
/**
* Input encoding
*
* @var string
*/
private $_inputEncoding;
/**
* Delimiter
*
* @var string
*/
private $_delimiter;
/**
* Enclosure
*
* @var string
*/
private $_enclosure;
/**
* Line ending
*
* @var string
*/
private $_lineEnding;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
* @var array
*/
private $_formats = array();
/**
* Format Count
*
* @var int
*/
private $_format = 0;
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Create a new PHPExcel_Reader_SYLK
*/
public function __construct() {
$this->_inputEncoding = 'ANSI';
$this->_delimiter = ';';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Read sample data (first 2 KB will do)
$fh = fopen($pFilename, 'r');
$data = fread($fh, 2048);
fclose($fh);
// Count delimiters in file
$delimiterCount = substr_count($data, ';');
if ($delimiterCount < 1) {
return false;
}
// Analyze first line looking for ID; signature
$lines = explode("\n", $data);
if (substr($lines[0],0,4) != 'ID;P') {
return false;
}
return true;
}
/**
* Loads PHPExcel from file
*
* @param string $pFilename
* @return PHPExcel
* @throws Exception
*/
public function load($pFilename)
{
// Create new PHPExcel
$objPHPExcel = new PHPExcel();
// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
/**
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
/**
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Set input encoding
*
* @param string $pValue Input encoding
*/
public function setInputEncoding($pValue = 'ANSI')
{
$this->_inputEncoding = $pValue;
return $this;
}
/**
* Get input encoding
*
* @return string
*/
public function getInputEncoding()
{
return $this->_inputEncoding;
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Create new PHPExcel
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
$objPHPExcel->createSheet();
}
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );
$fromFormats = array('\-', '\ ');
$toFormats = array('-', ' ');
// Open file
$fileHandle = fopen($pFilename, 'r');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for reading.");
}
// Loop through file
$rowData = array();
$column = $row = '';
// loop through one row (line) at a time in the file
while (($rowData = fgets($fileHandle)) !== FALSE) {
// convert SYLK encoded $rowData to UTF-8
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData);
// explode each row at semicolons while taking into account that literal semicolon (;)
// is escaped like this (;;)
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData)))));
$dataType = array_shift($rowData);
// Read shared styles
if ($dataType == 'P') {
$formatArray = array();
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'P' : $formatArray['numberformat']['code'] = str_replace($fromFormats,$toFormats,substr($rowDatum,1));
break;
case 'E' :
case 'F' : $formatArray['font']['name'] = substr($rowDatum,1);
break;
case 'L' : $formatArray['font']['size'] = substr($rowDatum,1);
break;
case 'S' : $styleSettings = substr($rowDatum,1);
for ($i=0;$i<strlen($styleSettings);++$i) {
switch ($styleSettings{$i}) {
case 'I' : $formatArray['font']['italic'] = true;
break;
case 'D' : $formatArray['font']['bold'] = true;
break;
case 'T' : $formatArray['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'B' : $formatArray['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'L' : $formatArray['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'R' : $formatArray['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
}
}
break;
}
}
$this->_formats['P'.$this->_format++] = $formatArray;
// Read cell value data
} elseif ($dataType == 'C') {
$hasCalculatedValue = false;
$cellData = $cellDataFormula = '';
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'C' :
case 'X' : $column = substr($rowDatum,1);
break;
case 'R' :
case 'Y' : $row = substr($rowDatum,1);
break;
case 'K' : $cellData = substr($rowDatum,1);
break;
case 'E' : $cellDataFormula = '='.substr($rowDatum,1);
// Convert R1C1 style references to A1 style references (but only when not quoted)
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
// Only count/replace in alternate array entries
if (($key % 2) == 0) {
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
// through the formula from left to right. Reversing means that we work right to left.through
// the formula
$cellReferences = array_reverse($cellReferences);
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
// then modify the formula to use that new reference
foreach($cellReferences as $cellReference) {
$rowReference = $cellReference[2][0];
// Empty R reference is the current row
if ($rowReference == '') $rowReference = $row;
// Bracketed R references are relative to the current row
if ($rowReference{0} == '[') $rowReference = $row + trim($rowReference,'[]');
$columnReference = $cellReference[4][0];
// Empty C reference is the current column
if ($columnReference == '') $columnReference = $column;
// Bracketed C references are relative to the current column
if ($columnReference{0} == '[') $columnReference = $column + trim($columnReference,'[]');
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
}
}
}
unset($value);
// Then rebuild the formula string
$cellDataFormula = implode('"',$temp);
$hasCalculatedValue = true;
break;
}
}
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$cellData = PHPExcel_Calculation::_unwrapResult($cellData);
// Set cell value
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData);
if ($hasCalculatedValue) {
$cellData = PHPExcel_Calculation::_unwrapResult($cellData);
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData);
}
// Read cell formatting
} elseif ($dataType == 'F') {
$formatStyle = $columnWidth = $styleSettings = '';
$styleData = array();
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'C' :
case 'X' : $column = substr($rowDatum,1);
break;
case 'R' :
case 'Y' : $row = substr($rowDatum,1);
break;
case 'P' : $formatStyle = $rowDatum;
break;
case 'W' : list($startCol,$endCol,$columnWidth) = explode(' ',substr($rowDatum,1));
break;
case 'S' : $styleSettings = substr($rowDatum,1);
for ($i=0;$i<strlen($styleSettings);++$i) {
switch ($styleSettings{$i}) {
case 'I' : $styleData['font']['italic'] = true;
break;
case 'D' : $styleData['font']['bold'] = true;
break;
case 'T' : $styleData['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'B' : $styleData['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'L' : $styleData['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'R' : $styleData['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
}
}
break;
}
}
if (($formatStyle > '') && ($column > '') && ($row > '')) {
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
}
if ((count($styleData) > 0) && ($column > '') && ($row > '')) {
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
}
if ($columnWidth > '') {
if ($startCol == $endCol) {
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1);
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
} else {
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1);
$endCol = PHPExcel_Cell::stringFromColumnIndex($endCol-1);
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
do {
$objPHPExcel->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);
} while ($startCol != $endCol);
}
}
} else {
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'C' :
case 'X' : $column = substr($rowDatum,1);
break;
case 'R' :
case 'Y' : $row = substr($rowDatum,1);
break;
}
}
}
}
// Close file
fclose($fileHandle);
// Return
return $objPHPExcel;
}
/**
* Get delimiter
*
* @return string
*/
public function getDelimiter() {
return $this->_delimiter;
}
/**
* Set delimiter
*
* @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_SYLK
*/
public function setDelimiter($pValue = ',') {
$this->_delimiter = $pValue;
return $this;
}
/**
* Get enclosure
*
* @return string
*/
public function getEnclosure() {
return $this->_enclosure;
}
/**
* Set enclosure
*
* @param string $pValue Enclosure, defaults to "
* @return PHPExcel_Reader_SYLK
*/
public function setEnclosure($pValue = '"') {
if ($pValue == '') {
$pValue = '"';
}
$this->_enclosure = $pValue;
return $this;
}
/**
* Get line ending
*
* @return string
*/
public function getLineEnding() {
return $this->_lineEnding;
}
/**
* Set line ending
*
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
* @return PHPExcel_Reader_SYLK
*/
public function setLineEnding($pValue = PHP_EOL) {
$this->_lineEnding = $pValue;
return $this;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_SYLK
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -32,24 +32,21 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/** PHPExcel */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Reader_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/** PHPExcel_Shared_File */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/File.php';
/**
* PHPExcel_Reader_Serialized
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader
{
@@ -58,17 +55,17 @@ class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
return $this->fileSupportsUnserializePHPExcel($pFilename);
}
/**
* Loads PHPExcel Serialized file
*

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,49 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Style */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style.php';
/** PHPExcel_Worksheet_Drawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/Drawing.php';
/** PHPExcel_Calculation_FormulaParser */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/FormulaParser.php';
/** PHPExcel_Calculation_FormulaToken */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/FormulaToken.php';
/**
* PHPExcel_ReferenceHelper (Singleton)
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_ReferenceHelper
{
@@ -86,37 +56,31 @@ class PHPExcel_ReferenceHelper
}
/**
* Create a new PHPExcel_Calculation
* Create a new PHPExcel_ReferenceHelper
*/
protected function __construct() {
}
/**
* Insert a new column, updating all possible related data
*
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert
* @param int $pNumRows Number of rows to insert
* @throws Exception
*/
public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) {
// Get a copy of the cell collection
/*$aTemp = $pSheet->getCellCollection();
$aCellCollection = array();
foreach ($aTemp as $key => $value) {
$aCellCollection[$key] = clone $value;
}*/
/**
* Insert a new column, updating all possible related data
*
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert
* @param int $pNumRows Number of rows to insert
* @throws Exception
*/
public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) {
$aCellCollection = $pSheet->getCellCollection();
// Get coordinates of $pBefore
$beforeColumn = 'A';
$beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
// Get coordinates of $pBefore
$beforeColumn = 'A';
$beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
// Clear cells if we are removing columns or rows
$highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow();
$highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow();
// 1. Clear column strips if we are removing columns
if ($pNumCols < 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols > 0) {
@@ -148,14 +112,16 @@ class PHPExcel_ReferenceHelper
// Loop through cells, bottom-up, and change cell coordinates
while ( ($cell = ($pNumCols < 0 || $pNumRows < 0) ? array_shift($aCellCollection) : array_pop($aCellCollection)) ) {
while (($cellID = ($pNumCols < 0 || $pNumRows < 0) ? array_shift($aCellCollection) : array_pop($aCellCollection))) {
$cell = $pSheet->getCell($cellID);
// New coordinates
$newCoordinates = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1 + $pNumCols ) . ($cell->getRow() + $pNumRows);
// Should the cell be updated? Move value and cellXf index from one cell to another.
if (
(PHPExcel_Cell::columnIndexFromString( $cell->getColumn() ) >= PHPExcel_Cell::columnIndexFromString($beforeColumn)) &&
($cell->getRow() >= $beforeRow)
($cell->getRow() >= $beforeRow)
) {
// Update cell styles
@@ -165,24 +131,22 @@ class PHPExcel_ReferenceHelper
// Insert this cell at its new location
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted
$pSheet->setCellValue(
$newCoordinates
, $this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows)
);
$pSheet->getCell($newCoordinates)
->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows));
} else {
// Formula should not be adjusted
$pSheet->setCellValue($newCoordinates, $cell->getValue());
$pSheet->getCell($newCoordinates)->setValue($cell->getValue());
}
// Clear the original cell
$pSheet->setCellValue($cell->getCoordinate(), '');
$pSheet->getCell($cell->getCoordinate())->setValue('');
}
}
// Duplicate styles for the newly inserted cells
$highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow();
$highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow();
if ($pNumCols > 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 > 0) {
for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) {
@@ -303,14 +267,13 @@ class PHPExcel_ReferenceHelper
// Update worksheet: merge cells
$aMergeCells = array_reverse($pSheet->getMergeCells(), true);
foreach ($aMergeCells as $key => $value) {
$aMergeCells = $pSheet->getMergeCells();
$aNewMergeCells = array(); // the new array of all merge cells
foreach ($aMergeCells as $key => &$value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->mergeCells( $newReference );
$pSheet->unmergeCells( $key );
}
$aNewMergeCells[$newReference] = $newReference;
}
$pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array
// Update worksheet: protected cells
@@ -365,57 +328,74 @@ class PHPExcel_ReferenceHelper
// Garbage collect
$pSheet->garbageCollect();
}
/**
* Update references within formulas
*
* @param string $pFormula Formula to update
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert
* @param int $pNumRows Number of rows to insert
* @return string Updated formula
* @throws Exception
*/
public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
// Formula stack
$executableFormulaArray = array();
}
/**
* Update references within formulas
*
* @param string $pFormula Formula to update
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert
* @param int $pNumRows Number of rows to insert
* @return string Updated formula
* @throws Exception
*/
public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
// Parse formula into a tree of tokens
$tokenisedFormula = PHPExcel_Calculation::getInstance()->parseFormula($pFormula);
$newCellTokens = $cellTokens = array();
$adjustCount = 0;
// Build the translation table of cell tokens
foreach($tokenisedFormula as $token) {
$token = $token['value'];
if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) {
$newCellTokens[] = $this->updateCellReference($token, $pBefore, $pNumCols, $pNumRows);
$cellTokens[] = '/'.$token.'/';
list($column,$row) = PHPExcel_Cell::coordinateFromString($token);
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = PHPExcel_Cell::columnIndexFromString($column) + 100000;
$row += 10000000;
$cellIndex = $column.$row;
if (!isset($cellTokens[$cellIndex])) {
$newReference = $this->updateCellReference($token, $pBefore, $pNumCols, $pNumRows);
if ($newReference !== $token) {
$newCellTokens[$cellIndex] = preg_quote($newReference);
$cellTokens[$cellIndex] = '/(?<![A-Z])'.preg_quote($token).'(?!\d)/i';
++$adjustCount;
}
}
}
}
if ($adjustCount == 0) {
return $pFormula;
}
krsort($cellTokens);
krsort($newCellTokens);
// Update cell references in the formula
$formulaBlocks = explode('"',$pFormula);
$i = 0;
foreach($formulaBlocks as $formulaBlockKey => $formulaBlock) {
foreach($formulaBlocks as $i => &$formulaBlock) {
// Only count/replace in alternate array entries
if (($i++ % 2) == 0) {
$formulaBlocks[$formulaBlockKey] = preg_replace($cellTokens,$newCellTokens,$formulaBlock);
if (($i % 2) == 0) {
$formulaBlock = preg_replace($cellTokens,$newCellTokens,$formulaBlock);
}
}
unset($formulaBlock);
// Then rebuild the formula string
return implode('"',$formulaBlocks);
}
}
/**
* Update cell reference
*
* @param string $pCellRange Cell range
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
* @return string Updated cell range
* @throws Exception
*/
public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
/**
* Update cell reference
*
* @param string $pCellRange Cell range
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
* @return string Updated cell range
* @throws Exception
*/
public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
// Is it in another worksheet? Will not have to update anything.
if (strpos($pCellRange, "!") !== false) {
return $pCellRange;
@@ -423,25 +403,30 @@ class PHPExcel_ReferenceHelper
} elseif (strpos($pCellRange, ':') === false && strpos($pCellRange, ',') === false) {
// Single cell
return $this->_updateSingleCellReference($pCellRange, $pBefore, $pNumCols, $pNumRows);
} else if (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) {
} elseif (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) {
// Range
return $this->_updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows);
} else {
// Return original
return $pCellRange;
}
}
}
/**
* Update named formulas (i.e. containing worksheet references / named ranges)
*
* @param PHPExcel $pPhpExcel Object to update
* @param string $oldName Old name (name to replace)
* @param string $newName New name
*/
public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') {
foreach ($pPhpExcel->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
/**
* Update named formulas (i.e. containing worksheet references / named ranges)
*
* @param PHPExcel $pPhpExcel Object to update
* @param string $oldName Old name (name to replace)
* @param string $newName New name
*/
public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') {
if ($oldName == '') {
return;
}
foreach ($pPhpExcel->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
if (!is_null($cell) && $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
$formula = $cell->getValue();
if (strpos($formula, $oldName) !== false) {
@@ -451,56 +436,56 @@ class PHPExcel_ReferenceHelper
}
}
}
}
}
}
}
/**
* Update cell range
*
* @param string $pCellRange Cell range
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
* @return string Updated cell range
* @throws Exception
*/
private function _updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) {
/**
* Update cell range
*
* @param string $pCellRange Cell range
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
* @return string Updated cell range
* @throws Exception
*/
private function _updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) {
// Update range
$range = PHPExcel_Cell::splitRange($pCellRange);
for ($i = 0; $i < count($range); $i++) {
for ($j = 0; $j < count($range[$i]); $j++) {
for ($i = 0; $i < count($range); ++$i) {
for ($j = 0; $j < count($range[$i]); ++$j) {
$range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows);
}
}
// Recreate range string
return PHPExcel_Cell::buildRange($range);
} else {
throw new Exception("Only cell ranges may be passed to this method.");
}
}
} else {
throw new Exception("Only cell ranges may be passed to this method.");
}
}
/**
* Update single cell reference
*
* @param string $pCellReference Single cell reference
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
* @return string Updated cell reference
* @throws Exception
*/
private function _updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) {
// Get coordinates of $pBefore
$beforeColumn = 'A';
$beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
/**
* Update single cell reference
*
* @param string $pCellReference Single cell reference
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
* @return string Updated cell reference
* @throws Exception
*/
private function _updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) {
// Get coordinates of $pBefore
$beforeColumn = 'A';
$beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
// Get coordinates
$newColumn = 'A';
$newRow = 1;
$newColumn = 'A';
$newRow = 1;
list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString( $pCellReference );
// Make sure the reference can be used
@@ -520,20 +505,20 @@ class PHPExcel_ReferenceHelper
// Create new column reference
if ($updateColumn) {
$newColumn = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($newColumn) - 1 + $pNumCols );
$newColumn = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($newColumn) - 1 + $pNumCols );
}
// Create new row reference
if ($updateRow) {
$newRow = $newRow + $pNumRows;
$newRow = $newRow + $pNumRows;
}
// Return new reference
return $newColumn . $newRow;
} else {
throw new Exception("Only single cell references may be passed to this method.");
}
}
} else {
throw new Exception("Only single cell references may be passed to this method.");
}
}
/**
* __clone implementation. Cloning should not be allowed in a Singleton!

View File

@@ -2,65 +2,36 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_RichText_ITextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/ITextElement.php';
/** PHPExcel_RichText_TextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/TextElement.php';
/** PHPExcel_RichText_Run */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/Run.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/**
* PHPExcel_RichText
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_RichText implements PHPExcel_IComparable
{
@@ -70,14 +41,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
* @var PHPExcel_RichText_ITextElement[]
*/
private $_richTextElements;
/**
* Parent cell
*
* @var PHPExcel_Cell
*/
private $_parent;
/**
* Create a new PHPExcel_RichText instance
*
@@ -88,24 +52,21 @@ class PHPExcel_RichText implements PHPExcel_IComparable
{
// Initialise variables
$this->_richTextElements = array();
// Set parent?
// Rich-Text string attached to cell?
if (!is_null($pCell)) {
// Set parent cell
$this->_parent = $pCell;
// Add cell text and style
if ($this->_parent->getValue() != "") {
$objRun = new PHPExcel_RichText_Run($this->_parent->getValue());
$objRun->setFont(clone $this->_parent->getParent()->getStyle($this->_parent->getCoordinate())->getFont());
if ($pCell->getValue() != "") {
$objRun = new PHPExcel_RichText_Run($pCell->getValue());
$objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont());
$this->addText($objRun);
}
// Set parent value
$this->_parent->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
$pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
}
}
/**
* Add text
*
@@ -118,7 +79,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
$this->_richTextElements[] = $pText;
return $this;
}
/**
* Create text
*
@@ -132,7 +93,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
$this->addText($objText);
return $objText;
}
/**
* Create text run
*
@@ -146,7 +107,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
$this->addText($objText);
return $objText;
}
/**
* Get plain text
*
@@ -156,16 +117,16 @@ class PHPExcel_RichText implements PHPExcel_IComparable
{
// Return value
$returnValue = '';
// Loop trough all PHPExcel_RichText_ITextElement
// Loop through all PHPExcel_RichText_ITextElement
foreach ($this->_richTextElements as $text) {
$returnValue .= $text->getText();
}
// Return
return $returnValue;
}
/**
* Convert to string
*
@@ -174,7 +135,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
public function __toString() {
return $this->getPlainText();
}
/**
* Get Rich Text elements
*
@@ -184,7 +145,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
{
return $this->_richTextElements;
}
/**
* Set Rich Text elements
*
@@ -201,101 +162,30 @@ class PHPExcel_RichText implements PHPExcel_IComparable
}
return $this;
}
/**
* Get parent
*
* @return PHPExcel_Cell
*/
public function getParent() {
return $this->_parent;
}
/**
* Set parent
*
* @param PHPExcel_Cell $value
* @return PHPExcel_RichText
*/
public function setParent(PHPExcel_Cell $value) {
// Set parent
$this->_parent = $value;
// Set parent value
$this->_parent->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
// Verify style information
$sheet = $this->_parent->getParent();
$cellFont = $sheet->getStyle($this->_parent->getCoordinate())->getFont()->getSharedComponent();
foreach ($this->getRichTextElements() as $element) {
if (!($element instanceof PHPExcel_RichText_Run)) continue;
if ($element->getFont()->getHashCode() == $sheet->getDefaultStyle()->getFont()->getHashCode()) {
if ($element->getFont()->getHashCode() != $cellFont->getHashCode()) {
$element->setFont(clone $cellFont);
}
}
}
return $this;
}
/**
* Get hash code
*
* @return string Hash code
*/
*/
public function getHashCode() {
$hashElements = '';
foreach ($this->_richTextElements as $element) {
$hashElements .= $element->getHashCode();
}
return md5(
$hashElements
. __CLASS__
);
}
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/
public function __clone() {
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if ($key == '_parent') continue;
if (is_object($value)) {
$this->$key = clone $value;
} else {

View File

@@ -6,42 +6,30 @@
* 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/**
* PHPExcel_RichText_ITextElement
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_RichText_ITextElement
{
@@ -49,28 +37,28 @@ interface PHPExcel_RichText_ITextElement
* Get text
*
* @return string Text
*/
*/
public function getText();
/**
* Set text
*
* @param $pText string Text
* @return PHPExcel_RichText_ITextElement
*/
*/
public function setText($pText = '');
/**
* Get font
*
* @return PHPExcel_Style_Font
*/
*/
public function getFont();
/**
* Get hash code
*
* @return string Hash code
*/
*/
public function getHashCode();
}

View File

@@ -6,58 +6,40 @@
* 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_RichText_ITextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/ITextElement.php';
/** PHPExcel_RichText_TextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/TextElement.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/**
* PHPExcel_RichText_Run
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{
{
/**
* Font
*
* @var PHPExcel_Style_Font
*/
private $_font;
/**
* Create a new PHPExcel_RichText_Run instance
*
@@ -69,33 +51,33 @@ class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHP
$this->setText($pText);
$this->_font = new PHPExcel_Style_Font();
}
/**
* Get font
*
* @return PHPExcel_Style_Font
*/
*/
public function getFont() {
return $this->_font;
}
/**
* Set font
*
* @param PHPExcel_Style_Font $pFont Font
* @throws Exception
* @return PHPExcel_RichText_ITextElement
*/
*/
public function setFont(PHPExcel_Style_Font $pFont = null) {
$this->_font = $pFont;
return $this;
}
/**
* Get hash code
*
* @return string Hash code
*/
*/
public function getHashCode() {
return md5(
$this->getText()
@@ -103,7 +85,7 @@ class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHP
. __CLASS__
);
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/

View File

@@ -6,45 +6,30 @@
* 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_RichText_ITextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/ITextElement.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/**
* PHPExcel_RichText_TextElement
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{
@@ -54,7 +39,7 @@ class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
* @var string
*/
private $_text;
/**
* Create a new PHPExcel_RichText_TextElement instance
*
@@ -65,48 +50,48 @@ class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
// Initialise variables
$this->_text = $pText;
}
/**
* Get text
*
* @return string Text
*/
*/
public function getText() {
return $this->_text;
}
/**
* Set text
*
* @param $pText string Text
* @return PHPExcel_RichText_ITextElement
*/
*/
public function setText($pText = '') {
$this->_text = $pText;
return $this;
}
/**
* Get font
*
* @return PHPExcel_Style_Font
*/
*/
public function getFont() {
return null;
}
/**
* Get hash code
*
* @return string Hash code
*/
*/
public function getHashCode() {
return md5(
$this->_text
. __CLASS__
);
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/

View File

@@ -0,0 +1,65 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Settings
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
class PHPExcel_Settings
{
public static function getCacheStorageMethod() {
return PHPExcel_CachedObjectStorageFactory::$_cacheStorageMethod;
} // function getCacheStorageMethod()
public static function getCacheStorageClass() {
return PHPExcel_CachedObjectStorageFactory::$_cacheStorageClass;
} // function getCacheStorageClass()
public static function setCacheStorageMethod($method = PHPExcel_CachedObjectStorageFactory::cache_in_memory, $arguments = array()) {
return PHPExcel_CachedObjectStorageFactory::initialize($method,$arguments);
} // function setCacheStorageMethod()
public static function setLocale($locale){
return PHPExcel_Calculation::getInstance()->setLocale($locale);
} // function setLocale()
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.3c, 2010-06-01
*/
/**
* PHPExcel_Shared_CodePage
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_CodePage
{
/**
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
* and mbstring understands
*
* @param int $number Microsoft Code Page Indentifier
* @return string Code Page Name
* @throws Exception
*/
public static function NumberToName($codePage = '1252')
{
switch ($codePage) {
case 367: return 'ASCII'; break; // ASCII
case 437: return 'CP437'; break; //OEM US
case 720: throw new Exception('Code page 720 not supported.');
break; //OEM Arabic
case 737: return 'CP737'; break; //OEM Greek
case 775: return 'CP775'; break; //OEM Baltic
case 850: return 'CP850'; break; //OEM Latin I
case 852: return 'CP852'; break; //OEM Latin II (Central European)
case 855: return 'CP855'; break; //OEM Cyrillic
case 857: return 'CP857'; break; //OEM Turkish
case 858: return 'CP858'; break; //OEM Multilingual Latin I with Euro
case 860: return 'CP860'; break; //OEM Portugese
case 861: return 'CP861'; break; //OEM Icelandic
case 862: return 'CP862'; break; //OEM Hebrew
case 863: return 'CP863'; break; //OEM Canadian (French)
case 864: return 'CP864'; break; //OEM Arabic
case 865: return 'CP865'; break; //OEM Nordic
case 866: return 'CP866'; break; //OEM Cyrillic (Russian)
case 869: return 'CP869'; break; //OEM Greek (Modern)
case 874: return 'CP874'; break; //ANSI Thai
case 932: return 'CP932'; break; //ANSI Japanese Shift-JIS
case 936: return 'CP936'; break; //ANSI Chinese Simplified GBK
case 949: return 'CP949'; break; //ANSI Korean (Wansung)
case 950: return 'CP950'; break; //ANSI Chinese Traditional BIG5
case 1200: return 'UTF-16LE'; break; //UTF-16 (BIFF8)
case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
case 1251: return 'CP1251'; break; //ANSI Cyrillic
case 1252: return 'CP1252'; break; //ANSI Latin I (BIFF4-BIFF7)
case 1253: return 'CP1253'; break; //ANSI Greek
case 1254: return 'CP1254'; break; //ANSI Turkish
case 1255: return 'CP1255'; break; //ANSI Hebrew
case 1256: return 'CP1256'; break; //ANSI Arabic
case 1257: return 'CP1257'; break; //ANSI Baltic
case 1258: return 'CP1258'; break; //ANSI Vietnamese
case 1361: return 'CP1361'; break; //ANSI Korean (Johab)
case 10000: return 'MAC'; break; //Apple Roman
case 32768: return 'MAC'; break; //Apple Roman
case 32769: throw new Exception('Code page 32769 not supported.');
break; //ANSI Latin I (BIFF2-BIFF3)
case 65001: return 'UTF-8'; break; //Unicode (UTF-8)
}
throw new Exception('Unknown codepage: ' . $codePage);
}
}

View File

@@ -3,7 +3,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,33 +21,18 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Style_NumberFormat */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/NumberFormat.php';
/**
* PHPExcel_Shared_Date
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Date
{
@@ -106,12 +91,15 @@ class PHPExcel_Shared_Date
// Perform conversion
if ($dateValue >= 1) {
$utcDays = $dateValue - $myExcelBaseDate;
$returnValue = (integer) round($utcDays * 24 * 60 * 60);
$returnValue = round($utcDays * 24 * 60 * 60);
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
$returnValue = (integer) $returnValue;
}
} else {
$hours = round($dateValue * 24);
$mins = round($dateValue * 24 * 60) - round($hours * 60);
$secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 60);
$returnValue = (integer) mktime($hours, $mins, $secs);
$returnValue = (integer) gmmktime($hours, $mins, $secs);
}
// Return
@@ -132,8 +120,10 @@ class PHPExcel_Shared_Date
$hours = round($time / 3600);
$minutes = round($time / 60) - ($hours * 60);
$seconds = round($time) - ($hours * 3600) - ($minutes * 60);
$dateObj = date_create('1-Jan-1970+'.$days.' days');
$dateObj->setTime($hours,$minutes,$seconds);
return $dateObj;
} // function ExcelToPHPObject()
@@ -274,4 +264,40 @@ class PHPExcel_Shared_Date
// No date...
return false;
} // function isDateTimeFormatCode()
/**
* Convert a date/time string to Excel time
*
* @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
* @return float|false Excel date/time serial value
*/
public static function stringToExcel($dateValue = '') {
// restrict to dates and times like these because date_parse accepts too many strings
// '2009-12-31'
// '2009-12-31 15:59'
// '2009-12-31 15:59:10'
if (!preg_match('/^\d{4}\-\d{1,2}\-\d{1,2}( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/', $dateValue)) {
return false;
}
// now try with date_parse
$PHPDateArray = date_parse($dateValue);
if ($PHPDateArray['error_count'] == 0) {
$year = $PHPDateArray['year'] !== false ? $PHPDateArray['year'] : self::getExcelCalendar();
$month = $PHPDateArray['month'] !== false ? $PHPDateArray['month'] : 1;
$day = $PHPDateArray['day'] !== false ? $PHPDateArray['day'] : 0;
$hour = $PHPDateArray['hour'] !== false ? $PHPDateArray['hour'] : 0;
$minute = $PHPDateArray['minute'] !== false ? $PHPDateArray['minute'] : 0;
$second = $PHPDateArray['second'] !== false ? $PHPDateArray['second'] : 0;
$excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day, $hour, $minute, $second);
return $excelDateValue;
}
return false;
}
}

View File

@@ -2,27 +2,27 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Drawing
{
@@ -44,7 +44,7 @@ class PHPExcel_Shared_Drawing
public static function pixelsToEMU($pValue = 0) {
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
@@ -58,35 +58,69 @@ class PHPExcel_Shared_Drawing
return 0;
}
}
/**
* Convert pixels to cell dimension. Exact algorithm not known.
* Convert pixels to column width. Exact algorithm not known.
* By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
* This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
*
* @param int $pValue Value in pixels
* @param int $pFontSize Default font size of workbook
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in cell dimension
*/
public static function pixelsToCellDimension($pValue = 0, $pFontSize = 11) {
return $pValue * $pFontSize / 11 / 7;
}
/**
* Convert cell width to pixels
*
* @param int $pValue Value in cell dimension
* @param int $pFontSize Default font size of workbook
* @return int Value in pixels
*/
public static function cellDimensionToPixels($pValue = 0, $pFontSize = 11) {
if ($pValue != 0) {
return $pValue * 7 * $pFontSize / 11;
public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue
* PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width']
/ PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
} else {
return 0;
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11
* PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width']
/ PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
return $colWidth;
}
/**
* Convert column width from (intrinsic) Excel units to pixels
*
* @param float $pValue Value in cell dimension
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in pixels
*/
public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue
* PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px']
/ PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * $size
* PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px']
/ PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
}
// Round pixels to closest integer
$colWidth = (int) round($colWidth);
return $colWidth;
}
/**
* Convert pixels to points
*
@@ -96,7 +130,7 @@ class PHPExcel_Shared_Drawing
public static function pixelsToPoints($pValue = 0) {
return $pValue * 0.67777777;
}
/**
* Convert points to pixels
*
@@ -120,7 +154,7 @@ class PHPExcel_Shared_Drawing
public static function degreesToAngle($pValue = 0) {
return (int)round($pValue * 60000);
}
/**
* Convert angle to degrees
*
@@ -134,4 +168,105 @@ class PHPExcel_Shared_Drawing
return 0;
}
}
/**
* Create a new image from file. By alexander at alexauto dot nl
*
* @link http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214
* @param string $filename Path to Windows DIB (BMP) image
* @return resource
*/
public static function imagecreatefrombmp($p_sFile)
{
// Load the image into a string
$file = fopen($p_sFile,"rb");
$read = fread($file,10);
while(!feof($file)&&($read<>""))
$read .= fread($file,1024);
$temp = unpack("H*",$read);
$hex = $temp[1];
$header = substr($hex,0,108);
// Process the header
// Structure: http://www.fastgraph.com/help/bmp_header_format.html
if (substr($header,0,4)=="424d")
{
// Cut it in parts of 2 bytes
$header_parts = str_split($header,2);
// Get the width 4 bytes
$width = hexdec($header_parts[19].$header_parts[18]);
// Get the height 4 bytes
$height = hexdec($header_parts[23].$header_parts[22]);
// Unset the header params
unset($header_parts);
}
// Define starting X and Y
$x = 0;
$y = 1;
// Create newimage
$image = imagecreatetruecolor($width,$height);
// Grab the body from the image
$body = substr($hex,108);
// Calculate if padding at the end-line is needed
// Divided by two to keep overview.
// 1 byte = 2 HEX-chars
$body_size = (strlen($body)/2);
$header_size = ($width*$height);
// Use end-line padding? Only when needed
$usePadding = ($body_size>($header_size*3)+4);
// Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
// Calculate the next DWORD-position in the body
for ($i=0;$i<$body_size;$i+=3)
{
// Calculate line-ending and padding
if ($x>=$width)
{
// If padding needed, ignore image-padding
// Shift i to the ending of the current 32-bit-block
if ($usePadding)
$i += $width%4;
// Reset horizontal position
$x = 0;
// Raise the height-position (bottom-up)
$y++;
// Reached the image-height? Break the for-loop
if ($y>$height)
break;
}
// Calculation of the RGB-pixel (defined as BGR in image-data)
// Define $i_pos as absolute position in the body
$i_pos = $i*2;
$r = hexdec($body[$i_pos+4].$body[$i_pos+5]);
$g = hexdec($body[$i_pos+2].$body[$i_pos+3]);
$b = hexdec($body[$i_pos].$body[$i_pos+1]);
// Calculate and draw the pixel
$color = imagecolorallocate($image,$r,$g,$b);
imagesetpixel($image,$x,$height-$y,$color);
// Raise the horizontal position
$x++;
}
// Unset the body / free the memory
unset($body);
// Return image-object
return $image;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22
* @version 1.7.3c, 2010-06-01
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,31 +20,17 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Shared_Drawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Drawing.php';
/**
* PHPExcel_Shared_Excel5
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Excel5
{
@@ -59,8 +45,8 @@ class PHPExcel_Shared_Excel5
*/
public static function sizeCol($sheet, $col = 'A')
{
// default font size of workbook
$fontSize = $sheet->getParent()->getDefaultStyle()->getFont()->getSize();
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$columnDimensions = $sheet->getColumnDimensions();
@@ -70,17 +56,19 @@ class PHPExcel_Shared_Excel5
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize);
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize);
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else {
$pixelWidth = (int) 64 * $fontSize / 11; // here we interpolate from Calibri 11
// we don't even have any default column dimension. Width depends on default font
$pixelWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($font, true);
}
// now find the effective column width in pixels
@@ -104,6 +92,9 @@ class PHPExcel_Shared_Excel5
*/
public static function sizeRow($sheet, $row = 1)
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$rowDimensions = $sheet->getRowDimensions();
// first find the true row height in pixels (uncollapsed and unhidden)
@@ -122,7 +113,11 @@ class PHPExcel_Shared_Excel5
$pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
} else {
$pixelRowHeight = 20; // here we assume Calibri 11
// we don't even have any default row dimension. Height depends on default font
$pointRowHeight = PHPExcel_Shared_Font::getDefaultRowHeightByFont($font);
$pixelRowHeight = PHPExcel_Shared_Font::fontSizeToPixels($pointRowHeight);
}
// now find the effective row height in pixels
@@ -252,7 +247,7 @@ class PHPExcel_Shared_Excel5
list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinates);
$col_start = PHPExcel_Cell::columnIndexFromString($column) - 1;
$row_start = $row - 1;
$x1 = $offsetX;
$y1 = $offsetY;
@@ -301,8 +296,8 @@ class PHPExcel_Shared_Excel5
// Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
$x2 = $width / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = $height / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
$x2 = ($width + 1) / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
$startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_File
{
@@ -79,7 +79,7 @@ class PHPExcel_Shared_File
// Found something?
if ($returnValue == '' || is_null($returnValue)) {
$pathArray = split('/' , $pFilename);
$pathArray = explode('/' , $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
@@ -95,4 +95,42 @@ class PHPExcel_Shared_File
// Return
return $returnValue;
}
/**
* Get the systems temporary directory.
*
* @return string
*/
public static function sys_get_temp_dir()
{
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
if ( !function_exists('sys_get_temp_dir')) {
if( $temp = getenv('TMP') ) {
return realpath($temp);
}
if( $temp = getenv('TEMP') ) {
return realpath($temp);
}
if( $temp = getenv('TMPDIR') ) {
return realpath($temp);
}
// trick for creating a file in system's temporary dir
// without knowing the path of the system's temporary dir
$temp = tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return realpath(dirname($temp));
}
return null;
}
// use ordinary built-in PHP function
return realpath(sys_get_temp_dir());
}
}

View File

@@ -2,27 +2,27 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,10 +31,14 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Font
{
/* Methods for resolving autosize value */
const AUTOSIZE_METHOD_APPROX = 'approx';
const AUTOSIZE_METHOD_EXACT = 'exact';
/** Character set codes used by BIFF5-8 in Font records */
const CHARSET_ANSI_LATIN = 0x00;
const CHARSET_SYSTEM_DEFAULT = 0x01;
@@ -55,39 +59,304 @@ class PHPExcel_Shared_Font
const CHARSET_ANSI_THAI = 0xDE;
const CHARSET_ANSI_LATIN_II = 0xEE;
const CHARSET_OEM_LATIN_I = 0xFF;
// XXX: Constants created!
/** Font filenames */
const ARIAL = 'arial.ttf';
const ARIAL_BOLD = 'arialbd.ttf';
const ARIAL_ITALIC = 'ariali.ttf';
const ARIAL_BOLD_ITALIC = 'arialbi.ttf';
const CALIBRI = 'CALIBRI.TTF';
const CALIBRI_BOLD = 'CALIBRIB.TTF';
const CALIBRI_ITALIC = 'CALIBRII.TTF';
const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF';
const COMIC_SANS_MS = 'comic.ttf';
const COMIC_SANS_MS_BOLD = 'comicbd.ttf';
const COURIER_NEW = 'cour.ttf';
const COURIER_NEW_BOLD = 'courbd.ttf';
const COURIER_NEW_ITALIC = 'couri.ttf';
const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf';
const GEORGIA = 'georgia.ttf';
const GEORGIA_BOLD = 'georgiab.ttf';
const GEORGIA_ITALIC = 'georgiai.ttf';
const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf';
const IMPACT = 'impact.ttf';
const LIBERATION_SANS = 'LiberationSans-Regular.ttf';
const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf';
const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf';
const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf';
const LUCIDA_CONSOLE = 'lucon.ttf';
const LUCIDA_SANS_UNICODE = 'l_10646.ttf';
const MICROSOFT_SANS_SERIF = 'micross.ttf';
const PALATINO_LINOTYPE = 'pala.ttf';
const PALATINO_LINOTYPE_BOLD = 'palab.ttf';
const PALATINO_LINOTYPE_ITALIC = 'palai.ttf';
const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf';
const SYMBOL = 'symbol.ttf';
const TAHOMA = 'tahoma.ttf';
const TAHOMA_BOLD = 'tahomabd.ttf';
const TIMES_NEW_ROMAN = 'times.ttf';
const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf';
const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf';
const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf';
const TREBUCHET_MS = 'trebuc.ttf';
const TREBUCHET_MS_BOLD = 'trebucbd.ttf';
const TREBUCHET_MS_ITALIC = 'trebucit.ttf';
const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf';
const VERDANA = 'verdana.ttf';
const VERDANA_BOLD = 'verdanab.ttf';
const VERDANA_ITALIC = 'verdanai.ttf';
const VERDANA_BOLD_ITALIC = 'verdanaz.ttf';
/**
* AutoSize method
*
* @var string
*/
private static $autoSizeMethod = self::AUTOSIZE_METHOD_APPROX;
/**
* Path to folder containing TrueType font .ttf files
*
* @var string
*/
private static $trueTypeFontPath = null;
/**
* How wide is a default column for a given default font and size?
* Empirical data found by inspecting real Excel files and reading off the pixel width
* in Microsoft Office Excel 2007.
*
* @var array
*/
public static $defaultColumnWidths = array(
'Arial' => array(
1 => array('px' => 24, 'width' => 12.00000000),
2 => array('px' => 24, 'width' => 12.00000000),
3 => array('px' => 32, 'width' => 10.66406250),
4 => array('px' => 32, 'width' => 10.66406250),
5 => array('px' => 40, 'width' => 10.00000000),
6 => array('px' => 48, 'width' => 9.59765625),
7 => array('px' => 48, 'width' => 9.59765625),
8 => array('px' => 56, 'width' => 9.33203125),
9 => array('px' => 64, 'width' => 9.14062500),
10 => array('px' => 64, 'width' => 9.14062500),
),
'Calibri' => array(
1 => array('px' => 24, 'width' => 12.00000000),
2 => array('px' => 24, 'width' => 12.00000000),
3 => array('px' => 32, 'width' => 10.66406250),
4 => array('px' => 32, 'width' => 10.66406250),
5 => array('px' => 40, 'width' => 10.00000000),
6 => array('px' => 48, 'width' => 9.59765625),
7 => array('px' => 48, 'width' => 9.59765625),
8 => array('px' => 56, 'width' => 9.33203125),
9 => array('px' => 56, 'width' => 9.33203125),
10 => array('px' => 64, 'width' => 9.14062500),
11 => array('px' => 64, 'width' => 9.14062500),
),
'Verdana' => array(
1 => array('px' => 24, 'width' => 12.00000000),
2 => array('px' => 24, 'width' => 12.00000000),
3 => array('px' => 32, 'width' => 10.66406250),
4 => array('px' => 32, 'width' => 10.66406250),
5 => array('px' => 40, 'width' => 10.00000000),
6 => array('px' => 48, 'width' => 9.59765625),
7 => array('px' => 48, 'width' => 9.59765625),
8 => array('px' => 64, 'width' => 9.14062500),
9 => array('px' => 72, 'width' => 9.00000000),
10 => array('px' => 72, 'width' => 9.00000000),
),
);
/**
* Set autoSize method
*
* @param string $pValue
*/
public static function setAutoSizeMethod($pValue = 'approx')
{
self::$autoSizeMethod = $pValue;
}
/**
* Get autoSize method
*
* @return string
*/
public static function getAutoSizeMethod()
{
return self::$autoSizeMethod;
}
/**
* Set the path to the folder containing .ttf files. There should be a trailing slash.
* Typical locations on variout some platforms:
* <ul>
* <li>C:/Windows/Fonts/</li>
* <li>/usr/share/fonts/truetype/</li>
* <li>~/.fonts/</li>
* </ul>
*
* @param string $pValue
*/
public static function setTrueTypeFontPath($pValue = '')
{
self::$trueTypeFontPath = $pValue;
}
/**
* Get the path to the folder containing .ttf files.
*
* @return string
*/
public static function getTrueTypeFontPath()
{
return self::$trueTypeFontPath;
}
/**
* Calculate an (approximate) OpenXML column width, based on font size and text contained
*
* @param int $fontSize Font size (in pixels or points)
* @param bool $fontSizeInPixels Is the font size specified in pixels (true) or in points (false) ?
* @param string $columnText Text to calculate width
* @param string $cellText Text to calculate width
* @param int $rotation Rotation angle
* @return int Column width
*/
public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '', $rotation = 0) {
if (!$fontSizeInPixels) {
// Translate points size to pixel size
$fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize);
public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) {
// If it is rich text, use plain text
if ($cellText instanceof PHPExcel_RichText) {
$cellText = $cellText->getPlainText();
}
// If it is rich text, use rich text...
if ($columnText instanceof PHPExcel_RichText) {
$columnText = $columnText->getPlainText();
// Special case if there are one or more newline characters ("\n")
if (strpos($cellText, "\n") !== false) {
$lineTexts = explode("\n", $cellText);
$lineWitdhs = array();
foreach ($lineTexts as $lineText) {
$lineWidths[] = self::calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont);
}
return max($lineWidths); // width of longest line in cell
}
// Only measure the part before the first newline character
if (strpos($columnText, "\r") !== false) {
$columnText = substr($columnText, 0, strpos($columnText, "\r"));
// Try to get the exact text width in pixels
try {
// If autosize method is set to 'approx', use approximation
if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) {
throw new Exception('AutoSize method is set to approx');
}
// Width of text in pixels excl. padding
$columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation);
// Excel adds some padding, use 1.07 of the width of an 'n' glyph
$columnWidth += ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07); // pixels incl. padding
} catch (Exception $e) {
// Width of text in pixels excl. padding, approximation
$columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation);
// Excel adds some padding, just use approx width of 'n' glyph
$columnWidth += self::getTextWidthPixelsApprox('n', $font, 0);
}
if (strpos($columnText, "\n") !== false) {
$columnText = substr($columnText, 0, strpos($columnText, "\n"));
// Convert from pixel width to column width
$columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
// Return
return round($columnWidth, 6);
}
/**
* Get GD text width in pixels for a string of text in a certain font at a certain rotation angle
*
* @param string $text
* @param PHPExcel_Style_Font
* @param int $rotation
* @return int
* @throws Exception
*/
public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) {
if (!function_exists('imagettfbbox')) {
throw new Exception('GD library needs to be enabled');
}
// font size should really be supplied in pixels in GD2,
// but since GD2 seems to assume 72dpi, pixels and points are the same
$fontFile = self::getTrueTypeFontFileFromFont($font);
$textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text);
// Get corners positions
$lowerLeftCornerX = $textBox[0];
$lowerLeftCornerY = $textBox[1];
$lowerRightCornerX = $textBox[2];
$lowerRightCornerY = $textBox[3];
$upperRightCornerX = $textBox[4];
$upperRightCornerY = $textBox[5];
$upperLeftCornerX = $textBox[6];
$upperLeftCornerY = $textBox[7];
// Consider the rotation when calculating the width
$textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
return $textWidth;
}
/**
* Get approximate width in pixels for a string of text in a certain font at a certain rotation angle
*
* @param string $columnText
* @param PHPExcel_Style_Font $font
* @param int $rotation
* @return int Text width in pixels (no padding added)
*/
public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0)
{
$fontName = $font->getName();
$fontSize = $font->getSize();
// Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
switch ($fontName) {
case 'Calibri':
// value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
$columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
break;
case 'Arial':
// value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.
$columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
break;
case 'Verdana':
// value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
$columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
break;
default:
// just assume Calibri
$columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
break;
}
// Calculate column width
// values 1.025 and 0.584 found via interpolation by inspecting real Excel files with
// Calibri font. May need further adjustment
$columnWidth = 1.025 * strlen($columnText) + 0.584; // Excel adds some padding
// Calculate approximate rotated column width
if ($rotation !== 0) {
@@ -101,20 +370,21 @@ class PHPExcel_Shared_Font
}
}
// Return
return round($columnWidth, 6);
// pixel width is an integer
$columnWidth = (int) $columnWidth;
return $columnWidth;
}
/**
* Calculate an (approximate) pixel size, based on a font points size
*
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
*/
public static function fontSizeToPixels($fontSizeInPoints = 12) {
return ((16 / 12) * $fontSizeInPoints);
public static function fontSizeToPixels($fontSizeInPoints = 11) {
return (int) ((4 / 3) * $fontSizeInPoints);
}
/**
* Calculate an (approximate) pixel size, based on inch size
*
@@ -124,7 +394,7 @@ class PHPExcel_Shared_Font
public static function inchSizeToPixels($sizeInInch = 1) {
return ($sizeInInch * 96);
}
/**
* Calculate an (approximate) pixel size, based on centimeter size
*
@@ -135,6 +405,133 @@ class PHPExcel_Shared_Font
return ($sizeInCm * 37.795275591);
}
/**
* Returns the font path given the font
*
* @param PHPExcel_Style_Font
* @return string Path to TrueType font file
*/
public static function getTrueTypeFontFileFromFont($font) {
if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) {
throw new Exception('Valid directory to TrueType Font files not specified');
}
$name = $font->getName();
$bold = $font->getBold();
$italic = $font->getItalic();
// Check if we can map font to true type font file
switch ($name) {
case 'Arial':
$fontFile = (
$bold ? ($italic ? self::ARIAL_BOLD_ITALIC : self::ARIAL_BOLD)
: ($italic ? self::ARIAL_ITALIC : self::ARIAL)
);
break;
case 'Calibri':
$fontFile = (
$bold ? ($italic ? self::CALIBRI_BOLD_ITALIC : self::CALIBRI_BOLD)
: ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
);
break;
case 'Courier New':
$fontFile = (
$bold ? ($italic ? self::COURIER_NEW_BOLD_ITALIC : self::COURIER_NEW_BOLD)
: ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
);
break;
case 'Comic Sans MS':
$fontFile = (
$bold ? self::COMIC_SANS_MS_BOLD : self::COMIC_SANS_MS
);
break;
case 'Georgia':
$fontFile = (
$bold ? ($italic ? self::GEORGIA_BOLD_ITALIC : self::GEORGIA_BOLD)
: ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
);
break;
case 'Impact':
$fontFile = self::IMPACT;
break;
case 'Liberation Sans':
$fontFile = (
$bold ? ($italic ? self::LIBERATION_SANS_BOLD_ITALIC : self::LIBERATION_SANS_BOLD)
: ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
);
break;
case 'Lucida Console':
$fontFile = self::LUCIDA_CONSOLE;
break;
case 'Lucida Sans Unicode':
$fontFile = self::LUCIDA_SANS_UNICODE;
break;
case 'Microsoft Sans Serif':
$fontFile = self::MICROSOFT_SANS_SERIF;
break;
case 'Palatino Linotype':
$fontFile = (
$bold ? ($italic ? self::PALATINO_LINOTYPE_BOLD_ITALIC : self::PALATINO_LINOTYPE_BOLD)
: ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
);
break;
case 'Symbol':
$fontFile = self::SYMBOL;
break;
case 'Tahoma':
$fontFile = (
$bold ? self::TAHOMA_BOLD : self::TAHOMA
);
break;
case 'Times New Roman':
$fontFile = (
$bold ? ($italic ? self::TIMES_NEW_ROMAN_BOLD_ITALIC : self::TIMES_NEW_ROMAN_BOLD)
: ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
);
break;
case 'Trebuchet MS':
$fontFile = (
$bold ? ($italic ? self::TREBUCHET_MS_BOLD_ITALIC : self::TREBUCHET_MS_BOLD)
: ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
);
break;
case 'Verdana':
$fontFile = (
$bold ? ($italic ? self::VERDANA_BOLD_ITALIC : self::VERDANA_BOLD)
: ($italic ? self::VERDANA_ITALIC : self::VERDANA)
);
break;
default:
throw new Exception('Unknown font name "'. $name .'". Cannot map to TrueType font file');
break;
}
$fontFile = self::$trueTypeFontPath . $fontFile;
// Check if file actually exists
if (!file_exists($fontFile)) {
throw New Exception('TrueType Font file not found');
}
return $fontFile;
}
/**
* Returns the associated charset for the font name.
*
@@ -145,6 +542,7 @@ class PHPExcel_Shared_Font
{
switch ($name) {
// Add more cases. Check FONT records in real Excel files.
case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI;
case 'Wingdings': return self::CHARSET_SYMBOL;
case 'Wingdings 2': return self::CHARSET_SYMBOL;
case 'Wingdings 3': return self::CHARSET_SYMBOL;
@@ -152,4 +550,214 @@ class PHPExcel_Shared_Font
}
}
/**
* Get the effective column width for columns without a column dimension or column with width -1
* For example, for Calibri 11 this is 9.140625 (64 px)
*
* @param PHPExcel_Style_Font $font The workbooks default font
* @param boolean $pPixels true = return column width in pixels, false = return in OOXML units
* @return mixed Column width
*/
public static function getDefaultColumnWidthByFont(PHPExcel_Style_Font $font, $pPixels = false)
{
if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) {
// Exact width can be determined
$columnWidth = $pPixels ?
self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px']
: self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$columnWidth = $pPixels ?
self::$defaultColumnWidths['Calibri'][11]['px']
: self::$defaultColumnWidths['Calibri'][11]['width'];
$columnWidth = $columnWidth * $font->getSize() / 11;
// Round pixels to closest integer
if ($pPixels) {
$columnWidth = (int) round($columnWidth);
}
}
return $columnWidth;
}
/**
* Get the effective row height for rows without a row dimension or rows with height -1
* For example, for Calibri 11 this is 15 points
*
* @param PHPExcel_Style_Font $font The workbooks default font
* @return float Row height in points
*/
public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font)
{
switch ($font->getName()) {
case 'Arial':
switch ($font->getSize()) {
case 10:
// inspection of Arial 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
case 9:
// inspection of Arial 9 workbook says 12.00pt ~16px
$rowHeight = 12;
break;
case 8:
// inspection of Arial 8 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
case 7:
// inspection of Arial 7 workbook says 9.00pt ~12px
$rowHeight = 9;
break;
case 6:
case 5:
// inspection of Arial 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
case 4:
// inspection of Arial 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
case 3:
// inspection of Arial 3 workbook says 6.00pt ~8px
$rowHeight = 6;
break;
case 2:
case 1:
// inspection of Arial 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
default:
// use Arial 10 workbook as an approximation, extrapolation
$rowHeight = 12.75 * $font->getSize() / 10;
break;
}
break;
case 'Calibri':
switch ($font->getSize()) {
case 11:
// inspection of Calibri 11 workbook says 15.00pt ~20px
$rowHeight = 15;
break;
case 10:
// inspection of Calibri 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
case 9:
// inspection of Calibri 9 workbook says 12.00pt ~16px
$rowHeight = 12;
break;
case 8:
// inspection of Calibri 8 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
case 7:
// inspection of Calibri 7 workbook says 9.00pt ~12px
$rowHeight = 9;
break;
case 6:
case 5:
// inspection of Calibri 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
case 4:
// inspection of Calibri 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
case 3:
// inspection of Calibri 3 workbook says 6.00pt ~8px
$rowHeight = 6.00;
break;
case 2:
case 1:
// inspection of Calibri 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
default:
// use Calibri 11 workbook as an approximation, extrapolation
$rowHeight = 15 * $font->getSize() / 11;
break;
}
break;
case 'Verdana':
switch ($font->getSize()) {
case 10:
// inspection of Verdana 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
case 9:
// inspection of Verdana 9 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
case 8:
// inspection of Verdana 8 workbook says 10.50pt ~14px
$rowHeight = 10.50;
break;
case 7:
// inspection of Verdana 7 workbook says 9.00pt ~12px
$rowHeight = 9.00;
break;
case 6:
case 5:
// inspection of Verdana 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
case 4:
// inspection of Verdana 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
case 3:
// inspection of Verdana 3 workbook says 6.00pt ~8px
$rowHeight = 6;
break;
case 2:
case 1:
// inspection of Verdana 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
default:
// use Verdana 10 workbook as an approximation, extrapolation
$rowHeight = 12.75 * $font->getSize() / 10;
break;
}
break;
default:
// just use Calibri as an approximation
$rowHeight = 15 * $font->getSize() / 11;
break;
}
return $rowHeight;
}
}

View File

@@ -1,133 +1,149 @@
<?php
/**
* @package JAMA
*
* Cholesky decomposition class
*
* For a symmetric, positive definite matrix A, the Cholesky decomposition
* is an lower triangular matrix L so that A = L*L'.
*
* If the matrix is not symmetric or positive definite, the constructor
* returns a partial decomposition and sets an internal flag that may
* be queried by the isSPD() method.
*
* @author Paul Meagher
* @author Michael Bommarito
* @version 1.2
*/
* @package JAMA
*
* Cholesky decomposition class
*
* For a symmetric, positive definite matrix A, the Cholesky decomposition
* is an lower triangular matrix L so that A = L*L'.
*
* If the matrix is not symmetric or positive definite, the constructor
* returns a partial decomposition and sets an internal flag that may
* be queried by the isSPD() method.
*
* @author Paul Meagher
* @author Michael Bommarito
* @version 1.2
*/
class CholeskyDecomposition {
/**
* Decomposition storage
* @var array
* @access private
*/
var $L = array();
/**
* Matrix row and column dimension
* @var int
* @access private
*/
var $m;
/**
* Symmetric positive definite flag
* @var boolean
* @access private
*/
var $isspd = true;
/**
* CholeskyDecomposition
* Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix
*/
function CholeskyDecomposition( $A = null ) {
if( is_a($A, 'Matrix') ) {
$this->L = $A->getArray();
$this->m = $A->getRowDimension();
for( $i = 0; $i < $this->m; $i++ ) {
for( $j = $i; $j < $this->m; $j++ ) {
for( $sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; $k-- )
$sum -= $this->L[$i][$k] * $this->L[$j][$k];
if( $i == $j ) {
if( $sum >= 0 ) {
$this->L[$i][$i] = sqrt( $sum );
} else {
$this->isspd = false;
}
} else {
if( $this->L[$i][$i] != 0 )
$this->L[$j][$i] = $sum / $this->L[$i][$i];
}
}
for ($k = $i+1; $k < $this->m; $k++)
$this->L[$i][$k] = 0.0;
}
} else {
trigger_error(ArgumentTypeException, ERROR);
}
}
/**
* Is the matrix symmetric and positive definite?
* @return boolean
*/
function isSPD () {
return $this->isspd;
}
/**
* getL
* Return triangular factor.
* @return Matrix Lower triangular matrix
*/
function getL () {
return new Matrix($this->L);
}
/**
* Solve A*X = B
* @param $B Row-equal matrix
* @return Matrix L * L' * X = B
*/
function solve ( $B = null ) {
if( is_a($B, 'Matrix') ) {
if ($B->getRowDimension() == $this->m) {
if ($this->isspd) {
$X = $B->getArrayCopy();
$nx = $B->getColumnDimension();
for ($k = 0; $k < $this->m; $k++) {
for ($i = $k + 1; $i < $this->m; $i++)
for ($j = 0; $j < $nx; $j++)
$X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
for ($j = 0; $j < $nx; $j++)
$X[$k][$j] /= $this->L[$k][$k];
}
for ($k = $this->m - 1; $k >= 0; $k--) {
for ($j = 0; $j < $nx; $j++)
$X[$k][$j] /= $this->L[$k][$k];
for ($i = 0; $i < $k; $i++)
for ($j = 0; $j < $nx; $j++)
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
}
return new Matrix($X, $this->m, $nx);
} else {
trigger_error(MatrixSPDException, ERROR);
}
} else {
trigger_error(MatrixDimensionException, ERROR);
}
} else {
trigger_error(ArgumentTypeException, ERROR);
}
}
}
/**
* Decomposition storage
* @var array
* @access private
*/
private $L = array();
/**
* Matrix row and column dimension
* @var int
* @access private
*/
private $m;
/**
* Symmetric positive definite flag
* @var boolean
* @access private
*/
private $isspd = true;
/**
* CholeskyDecomposition
*
* Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix
*/
public function __construct($A = null) {
if ($A instanceof Matrix) {
$this->L = $A->getArray();
$this->m = $A->getRowDimension();
for($i = 0; $i < $this->m; ++$i) {
for($j = $i; $j < $this->m; ++$j) {
for($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
$sum -= $this->L[$i][$k] * $this->L[$j][$k];
}
if ($i == $j) {
if ($sum >= 0) {
$this->L[$i][$i] = sqrt($sum);
} else {
$this->isspd = false;
}
} else {
if ($this->L[$i][$i] != 0) {
$this->L[$j][$i] = $sum / $this->L[$i][$i];
}
}
}
for ($k = $i+1; $k < $this->m; ++$k) {
$this->L[$i][$k] = 0.0;
}
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
}
} // function __construct()
/**
* Is the matrix symmetric and positive definite?
*
* @return boolean
*/
public function isSPD() {
return $this->isspd;
} // function isSPD()
/**
* getL
*
* Return triangular factor.
* @return Matrix Lower triangular matrix
*/
public function getL() {
return new Matrix($this->L);
} // function getL()
/**
* Solve A*X = B
*
* @param $B Row-equal matrix
* @return Matrix L * L' * X = B
*/
public function solve($B = null) {
if ($B instanceof Matrix) {
if ($B->getRowDimension() == $this->m) {
if ($this->isspd) {
$X = $B->getArrayCopy();
$nx = $B->getColumnDimension();
for ($k = 0; $k < $this->m; ++$k) {
for ($i = $k + 1; $i < $this->m; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
}
}
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k];
}
}
for ($k = $this->m - 1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
}
}
}
return new Matrix($X, $this->m, $nx);
} else {
throw new Exception(JAMAError(MatrixSPDException));
}
} else {
throw new Exception(JAMAError(MatrixDimensionException));
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
}
} // function solve()
} // class CholeskyDecomposition

View File

@@ -1,222 +1,255 @@
<?php
/**
* @package JAMA
*
* For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
* unit lower triangular matrix L, an n-by-n upper triangular matrix U,
* and a permutation vector piv of length m so that A(piv,:) = L*U.
* If m < n, then L is m-by-m and U is m-by-n.
*
* The LU decompostion with pivoting always exists, even if the matrix is
* singular, so the constructor will never fail. The primary use of the
* LU decomposition is in the solution of square systems of simultaneous
* linear equations. This will fail if isNonsingular() returns false.
*
* @author Paul Meagher
* @author Bartosz Matosiuk
* @author Michael Bommarito
* @version 1.1
* @license PHP v3.0
*/
* @package JAMA
*
* For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
* unit lower triangular matrix L, an n-by-n upper triangular matrix U,
* and a permutation vector piv of length m so that A(piv,:) = L*U.
* If m < n, then L is m-by-m and U is m-by-n.
*
* The LU decompostion with pivoting always exists, even if the matrix is
* singular, so the constructor will never fail. The primary use of the
* LU decomposition is in the solution of square systems of simultaneous
* linear equations. This will fail if isNonsingular() returns false.
*
* @author Paul Meagher
* @author Bartosz Matosiuk
* @author Michael Bommarito
* @version 1.1
* @license PHP v3.0
*/
class LUDecomposition {
/**
* Decomposition storage
* @var array
*/
var $LU = array();
/**
* Row dimension.
* @var int
*/
var $m;
/**
* Column dimension.
* @var int
*/
var $n;
/**
* Pivot sign.
* @var int
*/
var $pivsign;
/**
* Decomposition storage
* @var array
*/
private $LU = array();
/**
* Internal storage of pivot vector.
* @var array
*/
var $piv = array();
/**
* LU Decomposition constructor.
* @param $A Rectangular matrix
* @return Structure to access L, U and piv.
*/
function LUDecomposition ($A) {
if( is_a($A, 'Matrix') ) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; $i++)
$this->piv[$i] = $i;
$this->pivsign = 1;
$LUrowi = array();
$LUcolj = array();
// Outer loop.
for ($j = 0; $j < $this->n; $j++) {
// Make a copy of the j-th column to localize references.
for ($i = 0; $i < $this->m; $i++)
$LUcolj[$i] = &$this->LU[$i][$j];
// Apply previous transformations.
for ($i = 0; $i < $this->m; $i++) {
$LUrowi = $this->LU[$i];
// Most of the time is spent in the following dot product.
$kmax = min($i,$j);
$s = 0.0;
for ($k = 0; $k < $kmax; $k++)
$s += $LUrowi[$k]*$LUcolj[$k];
$LUrowi[$j] = $LUcolj[$i] -= $s;
}
// Find pivot and exchange if necessary.
$p = $j;
for ($i = $j+1; $i < $this->m; $i++) {
if (abs($LUcolj[$i]) > abs($LUcolj[$p]))
$p = $i;
}
if ($p != $j) {
for ($k = 0; $k < $this->n; $k++) {
$t = $this->LU[$p][$k];
$this->LU[$p][$k] = $this->LU[$j][$k];
$this->LU[$j][$k] = $t;
}
$k = $this->piv[$p];
$this->piv[$p] = $this->piv[$j];
$this->piv[$j] = $k;
$this->pivsign = $this->pivsign * -1;
}
// Compute multipliers.
if ( ($j < $this->m) AND ($this->LU[$j][$j] != 0.0) ) {
for ($i = $j+1; $i < $this->m; $i++)
$this->LU[$i][$j] /= $this->LU[$j][$j];
}
}
} else {
trigger_error(ArgumentTypeException, ERROR);
}
}
/**
* Get lower triangular factor.
* @return array Lower triangular factor
*/
function getL () {
for ($i = 0; $i < $this->m; $i++) {
for ($j = 0; $j < $this->n; $j++) {
if ($i > $j)
$L[$i][$j] = $this->LU[$i][$j];
else if($i == $j)
$L[$i][$j] = 1.0;
else
$L[$i][$j] = 0.0;
}
}
return new Matrix($L);
}
/**
* Row dimension.
* @var int
*/
private $m;
/**
* Get upper triangular factor.
* @return array Upper triangular factor
*/
function getU () {
for ($i = 0; $i < $this->n; $i++) {
for ($j = 0; $j < $this->n; $j++) {
if ($i <= $j)
$U[$i][$j] = $this->LU[$i][$j];
else
$U[$i][$j] = 0.0;
}
}
return new Matrix($U);
}
/**
* Return pivot permutation vector.
* @return array Pivot vector
*/
function getPivot () {
return $this->piv;
}
/**
* Alias for getPivot
* @see getPivot
*/
function getDoublePivot () {
return $this->getPivot();
}
/**
* Column dimension.
* @var int
*/
private $n;
/**
* Is the matrix nonsingular?
* @return true if U, and hence A, is nonsingular.
*/
function isNonsingular () {
for ($j = 0; $j < $this->n; $j++) {
if ($this->LU[$j][$j] == 0)
return false;
}
return true;
}
/**
* Pivot sign.
* @var int
*/
private $pivsign;
/**
* Count determinants
* @return array d matrix deterninat
*/
function det() {
if ($this->m == $this->n) {
$d = $this->pivsign;
for ($j = 0; $j < $this->n; $j++)
$d *= $this->LU[$j][$j];
return $d;
} else {
trigger_error(MatrixDimensionException, ERROR);
}
}
/**
* Solve A*X = B
* @param $B A Matrix with as many rows as A and any number of columns.
* @return X so that L*U*X = B(piv,:)
* @exception IllegalArgumentException Matrix row dimensions must agree.
* @exception RuntimeException Matrix is singular.
*/
function solve($B) {
if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) {
// Copy right hand side with pivoting
$nx = $B->getColumnDimension();
$X = $B->getMatrix($this->piv, 0, $nx-1);
// Solve L*Y = B(piv,:)
for ($k = 0; $k < $this->n; $k++)
for ($i = $k+1; $i < $this->n; $i++)
for ($j = 0; $j < $nx; $j++)
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
// Solve U*X = Y;
for ($k = $this->n-1; $k >= 0; $k--) {
for ($j = 0; $j < $nx; $j++)
$X->A[$k][$j] /= $this->LU[$k][$k];
for ($i = 0; $i < $k; $i++)
for ($j = 0; $j < $nx; $j++)
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
return $X;
} else {
trigger_error(MatrixSingularException, ERROR);
}
} else {
trigger_error(MatrixSquareException, ERROR);
}
}
}
/**
* Internal storage of pivot vector.
* @var array
*/
private $piv = array();
/**
* LU Decomposition constructor.
*
* @param $A Rectangular matrix
* @return Structure to access L, U and piv.
*/
public function __construct($A) {
if ($A instanceof Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; ++$i) {
$this->piv[$i] = $i;
}
$this->pivsign = 1;
$LUrowi = $LUcolj = array();
// Outer loop.
for ($j = 0; $j < $this->n; ++$j) {
// Make a copy of the j-th column to localize references.
for ($i = 0; $i < $this->m; ++$i) {
$LUcolj[$i] = &$this->LU[$i][$j];
}
// Apply previous transformations.
for ($i = 0; $i < $this->m; ++$i) {
$LUrowi = $this->LU[$i];
// Most of the time is spent in the following dot product.
$kmax = min($i,$j);
$s = 0.0;
for ($k = 0; $k < $kmax; ++$k) {
$s += $LUrowi[$k] * $LUcolj[$k];
}
$LUrowi[$j] = $LUcolj[$i] -= $s;
}
// Find pivot and exchange if necessary.
$p = $j;
for ($i = $j+1; $i < $this->m; ++$i) {
if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
$p = $i;
}
}
if ($p != $j) {
for ($k = 0; $k < $this->n; ++$k) {
$t = $this->LU[$p][$k];
$this->LU[$p][$k] = $this->LU[$j][$k];
$this->LU[$j][$k] = $t;
}
$k = $this->piv[$p];
$this->piv[$p] = $this->piv[$j];
$this->piv[$j] = $k;
$this->pivsign = $this->pivsign * -1;
}
// Compute multipliers.
if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
for ($i = $j+1; $i < $this->m; ++$i) {
$this->LU[$i][$j] /= $this->LU[$j][$j];
}
}
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
}
} // function __construct()
/**
* Get lower triangular factor.
*
* @return array Lower triangular factor
*/
public function getL() {
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) {
$L[$i][$j] = $this->LU[$i][$j];
} elseif ($i == $j) {
$L[$i][$j] = 1.0;
} else {
$L[$i][$j] = 0.0;
}
}
}
return new Matrix($L);
} // function getL()
/**
* Get upper triangular factor.
*
* @return array Upper triangular factor
*/
public function getU() {
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) {
$U[$i][$j] = $this->LU[$i][$j];
} else {
$U[$i][$j] = 0.0;
}
}
}
return new Matrix($U);
} // function getU()
/**
* Return pivot permutation vector.
*
* @return array Pivot vector
*/
public function getPivot() {
return $this->piv;
} // function getPivot()
/**
* Alias for getPivot
*
* @see getPivot
*/
public function getDoublePivot() {
return $this->getPivot();
} // function getDoublePivot()
/**
* Is the matrix nonsingular?
*
* @return true if U, and hence A, is nonsingular.
*/
public function isNonsingular() {
for ($j = 0; $j < $this->n; ++$j) {
if ($this->LU[$j][$j] == 0) {
return false;
}
}
return true;
} // function isNonsingular()
/**
* Count determinants
*
* @return array d matrix deterninat
*/
public function det() {
if ($this->m == $this->n) {
$d = $this->pivsign;
for ($j = 0; $j < $this->n; ++$j) {
$d *= $this->LU[$j][$j];
}
return $d;
} else {
throw new Exception(JAMAError(MatrixDimensionException));
}
} // function det()
/**
* Solve A*X = B
*
* @param $B A Matrix with as many rows as A and any number of columns.
* @return X so that L*U*X = B(piv,:)
* @exception IllegalArgumentException Matrix row dimensions must agree.
* @exception RuntimeException Matrix is singular.
*/
public function solve($B) {
if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) {
// Copy right hand side with pivoting
$nx = $B->getColumnDimension();
$X = $B->getMatrix($this->piv, 0, $nx-1);
// Solve L*Y = B(piv,:)
for ($k = 0; $k < $this->n; ++$k) {
for ($i = $k+1; $i < $this->n; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
// Solve U*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$k][$j] /= $this->LU[$k][$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
return $X;
} else {
throw new Exception(JAMAError(MatrixSingularException));
}
} else {
throw new Exception(JAMAError(MatrixSquareException));
}
} // function solve()
} // class LUDecomposition

File diff suppressed because it is too large Load Diff

View File

@@ -1,195 +1,232 @@
<?php
/**
* @package JAMA
*
* For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n
* orthogonal matrix Q and an n-by-n upper triangular matrix R so that
* A = Q*R.
*
* The QR decompostion always exists, even if the matrix does not have
* full rank, so the constructor will never fail. The primary use of the
* QR decomposition is in the least squares solution of nonsquare systems
* of simultaneous linear equations. This will fail if isFullRank()
* returns false.
*
* @author Paul Meagher
* @license PHP v3.0
* @version 1.1
*/
/**
* @package JAMA
*
* For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n
* orthogonal matrix Q and an n-by-n upper triangular matrix R so that
* A = Q*R.
*
* The QR decompostion always exists, even if the matrix does not have
* full rank, so the constructor will never fail. The primary use of the
* QR decomposition is in the least squares solution of nonsquare systems
* of simultaneous linear equations. This will fail if isFullRank()
* returns false.
*
* @author Paul Meagher
* @license PHP v3.0
* @version 1.1
*/
class QRDecomposition {
/**
* Array for internal storage of decomposition.
* @var array
*/
var $QR = array();
/**
* Row dimension.
* @var integer
*/
var $m;
/**
* Array for internal storage of decomposition.
* @var array
*/
private $QR = array();
/**
* Column dimension.
* @var integer
*/
var $n;
/**
* Row dimension.
* @var integer
*/
private $m;
/**
* Array for internal storage of diagonal of R.
* @var array
*/
var $Rdiag = array();
/**
* Column dimension.
* @var integer
*/
private $n;
/**
* QR Decomposition computed by Householder reflections.
* @param matrix $A Rectangular matrix
* @return Structure to access R and the Householder vectors and compute Q.
*/
function QRDecomposition($A) {
if( is_a($A, 'Matrix') ) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
// Main loop.
for ($k = 0; $k < $this->n; $k++) {
// Compute 2-norm of k-th column without under/overflow.
$nrm = 0.0;
for ($i = $k; $i < $this->m; $i++)
$nrm = hypo($nrm, $this->QR[$i][$k]);
if ($nrm != 0.0) {
// Form k-th Householder vector.
if ($this->QR[$k][$k] < 0)
$nrm = -$nrm;
for ($i = $k; $i < $this->m; $i++)
$this->QR[$i][$k] /= $nrm;
$this->QR[$k][$k] += 1.0;
// Apply transformation to remaining columns.
for ($j = $k+1; $j < $this->n; $j++) {
$s = 0.0;
for ($i = $k; $i < $this->m; $i++)
$s += $this->QR[$i][$k] * $this->QR[$i][$j];
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; $i++)
$this->QR[$i][$j] += $s * $this->QR[$i][$k];
}
}
$this->Rdiag[$k] = -$nrm;
}
} else
trigger_error(ArgumentTypeException, ERROR);
}
/**
* Array for internal storage of diagonal of R.
* @var array
*/
private $Rdiag = array();
/**
* Is the matrix full rank?
* @return boolean true if R, and hence A, has full rank, else false.
*/
function isFullRank() {
for ($j = 0; $j < $this->n; $j++)
if ($this->Rdiag[$j] == 0)
return false;
return true;
}
/**
* Return the Householder vectors
* @return Matrix Lower trapezoidal matrix whose columns define the reflections
*/
function getH() {
for ($i = 0; $i < $this->m; $i++) {
for ($j = 0; $j < $this->n; $j++) {
if ($i >= $j)
$H[$i][$j] = $this->QR[$i][$j];
else
$H[$i][$j] = 0.0;
}
}
return new Matrix($H);
}
/**
* QR Decomposition computed by Householder reflections.
*
* @param matrix $A Rectangular matrix
* @return Structure to access R and the Householder vectors and compute Q.
*/
public function __construct($A) {
if($A instanceof Matrix) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
// Main loop.
for ($k = 0; $k < $this->n; ++$k) {
// Compute 2-norm of k-th column without under/overflow.
$nrm = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$nrm = hypo($nrm, $this->QR[$i][$k]);
}
if ($nrm != 0.0) {
// Form k-th Householder vector.
if ($this->QR[$k][$k] < 0) {
$nrm = -$nrm;
}
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$k] /= $nrm;
}
$this->QR[$k][$k] += 1.0;
// Apply transformation to remaining columns.
for ($j = $k+1; $j < $this->n; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $this->QR[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
$this->Rdiag[$k] = -$nrm;
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
}
} // function __construct()
/**
* Return the upper triangular factor
* @return Matrix upper triangular factor
*/
function getR() {
for ($i = 0; $i < $this->n; $i++) {
for ($j = 0; $j < $this->n; $j++) {
if ($i < $j)
$R[$i][$j] = $this->QR[$i][$j];
else if ($i == $j)
$R[$i][$j] = $this->Rdiag[$i];
else
$R[$i][$j] = 0.0;
}
}
return new Matrix($R);
}
/**
* Generate and return the (economy-sized) orthogonal factor
* @return Matrix orthogonal factor
*/
function getQ() {
for ($k = $this->n-1; $k >= 0; $k--) {
for ($i = 0; $i < $this->m; $i++)
$Q[$i][$k] = 0.0;
$Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; $j++) {
if ($this->QR[$k][$k] != 0) {
$s = 0.0;
for ($i = $k; $i < $this->m; $i++)
$s += $this->QR[$i][$k] * $Q[$i][$j];
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; $i++)
$Q[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
/*
for( $i = 0; $i < count($Q); $i++ )
for( $j = 0; $j < count($Q); $j++ )
if(! isset($Q[$i][$j]) )
$Q[$i][$j] = 0;
*/
return new Matrix($Q);
}
/**
* Least squares solution of A*X = B
* @param Matrix $B A Matrix with as many rows as A and any number of columns.
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
*/
function solve($B) {
if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) {
// Copy right hand side
$nx = $B->getColumnDimension();
$X = $B->getArrayCopy();
// Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; $k++) {
for ($j = 0; $j < $nx; $j++) {
$s = 0.0;
for ($i = $k; $i < $this->m; $i++)
$s += $this->QR[$i][$k] * $X[$i][$j];
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; $i++)
$X[$i][$j] += $s * $this->QR[$i][$k];
}
}
// Solve R*X = Y;
for ($k = $this->n-1; $k >= 0; $k--) {
for ($j = 0; $j < $nx; $j++)
$X[$k][$j] /= $this->Rdiag[$k];
for ($i = 0; $i < $k; $i++)
for ($j = 0; $j < $nx; $j++)
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
}
$X = new Matrix($X);
return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else
trigger_error(MatrixRankException, ERROR);
} else
trigger_error(MatrixDimensionException, ERROR);
}
}
/**
* Is the matrix full rank?
*
* @return boolean true if R, and hence A, has full rank, else false.
*/
public function isFullRank() {
for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) {
return false;
}
}
return true;
} // function isFullRank()
/**
* Return the Householder vectors
*
* @return Matrix Lower trapezoidal matrix whose columns define the reflections
*/
public function getH() {
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j];
} else {
$H[$i][$j] = 0.0;
}
}
}
return new Matrix($H);
} // function getH()
/**
* Return the upper triangular factor
*
* @return Matrix upper triangular factor
*/
public function getR() {
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j];
} elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i];
} else {
$R[$i][$j] = 0.0;
}
}
}
return new Matrix($R);
} // function getR()
/**
* Generate and return the (economy-sized) orthogonal factor
*
* @return Matrix orthogonal factor
*/
public function getQ() {
for ($k = $this->n-1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0;
}
$Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; ++$j) {
if ($this->QR[$k][$k] != 0) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $Q[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$Q[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
}
/*
for($i = 0; $i < count($Q); ++$i) {
for($j = 0; $j < count($Q); ++$j) {
if(! isset($Q[$i][$j]) ) {
$Q[$i][$j] = 0;
}
}
}
*/
return new Matrix($Q);
} // function getQ()
/**
* Least squares solution of A*X = B
*
* @param Matrix $B A Matrix with as many rows as A and any number of columns.
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
*/
public function solve($B) {
if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) {
// Copy right hand side
$nx = $B->getColumnDimension();
$X = $B->getArrayCopy();
// Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; ++$k) {
for ($j = 0; $j < $nx; ++$j) {
$s = 0.0;
for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $X[$i][$j];
}
$s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; ++$i) {
$X[$i][$j] += $s * $this->QR[$i][$k];
}
}
}
// Solve R*X = Y;
for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->Rdiag[$k];
}
for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
}
}
}
$X = new Matrix($X);
return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else {
throw new Exception(JAMAError(MatrixRankException));
}
} else {
throw new Exception(JAMAError(MatrixDimensionException));
}
} // function solve()
} // class QRDecomposition

View File

@@ -1,120 +1,82 @@
<?php
/**
* @package JAMA
*
* Error handling
* @author Michael Bommarito
* @version 01292005
*/
* @package JAMA
*
* Error handling
* @author Michael Bommarito
* @version 01292005
*/
//Language constant
define('LANG', 'EN');
define('JAMALANG', 'EN');
//Error type constants
define('ERROR', E_USER_ERROR);
define('WARNING', E_USER_WARNING);
define('NOTICE', E_USER_NOTICE);
//All errors may be defined by the following format:
//define('ExceptionName', N);
//$error['lang'][N] = 'Error message';
//$error['lang'][ExceptionName] = 'Error message';
$error = array();
/*
I've used Babelfish and a little poor knowledge of Romance/Germanic languages for the translations
here. Feel free to correct anything that looks amiss to you.
I've used Babelfish and a little poor knowledge of Romance/Germanic languages for the translations here.
Feel free to correct anything that looks amiss to you.
*/
define('PolymorphicArgumentException', -1);
$error['EN'][-1] = "Invalid argument pattern for polymorphic function.";
$error['FR'][-1] = "Modèle inadmissible d'argument pour la fonction polymorphe.".
$error['DE'][-1] = "Unzulässiges Argumentmuster für polymorphe Funktion.";
$error['EN'][PolymorphicArgumentException] = "Invalid argument pattern for polymorphic function.";
$error['FR'][PolymorphicArgumentException] = "Modèle inadmissible d'argument pour la fonction polymorphe.".
$error['DE'][PolymorphicArgumentException] = "Unzulässiges Argumentmuster für polymorphe Funktion.";
define('ArgumentTypeException', -2);
$error['EN'][-2] = "Invalid argument type.";
$error['FR'][-2] = "Type inadmissible d'argument.";
$error['DE'][-2] = "Unzulässige Argumentart.";
$error['EN'][ArgumentTypeException] = "Invalid argument type.";
$error['FR'][ArgumentTypeException] = "Type inadmissible d'argument.";
$error['DE'][ArgumentTypeException] = "Unzulässige Argumentart.";
define('ArgumentBoundsException', -3);
$error['EN'][-3] = "Invalid argument range.";
$error['FR'][-3] = "Gamme inadmissible d'argument.";
$error['DE'][-3] = "Unzulässige Argumentstrecke.";
$error['EN'][ArgumentBoundsException] = "Invalid argument range.";
$error['FR'][ArgumentBoundsException] = "Gamme inadmissible d'argument.";
$error['DE'][ArgumentBoundsException] = "Unzulässige Argumentstrecke.";
define('MatrixDimensionException', -4);
$error['EN'][-4] = "Matrix dimensions are not equal.";
$error['FR'][-4] = "Les dimensions de Matrix ne sont pas égales.";
$error['DE'][-4] = "Matrixmaße sind nicht gleich.";
$error['EN'][MatrixDimensionException] = "Matrix dimensions are not equal.";
$error['FR'][MatrixDimensionException] = "Les dimensions de Matrix ne sont pas égales.";
$error['DE'][MatrixDimensionException] = "Matrixmaße sind nicht gleich.";
define('PrecisionLossException', -5);
$error['EN'][-5] = "Significant precision loss detected.";
$error['FR'][-5] = "Perte significative de précision détectée.";
$error['DE'][-5] = "Bedeutender Präzision Verlust ermittelte.";
$error['EN'][PrecisionLossException] = "Significant precision loss detected.";
$error['FR'][PrecisionLossException] = "Perte significative de précision détectée.";
$error['DE'][PrecisionLossException] = "Bedeutender Präzision Verlust ermittelte.";
define('MatrixSPDException', -6);
$error['EN'][-6] = "Can only perform operation on symmetric positive definite matrix.";
$error['FR'][-6] = "Perte significative de précision détectée.";
$error['DE'][-6] = "Bedeutender Präzision Verlust ermittelte.";
$error['EN'][MatrixSPDException] = "Can only perform operation on symmetric positive definite matrix.";
$error['FR'][MatrixSPDException] = "Perte significative de précision détectée.";
$error['DE'][MatrixSPDException] = "Bedeutender Präzision Verlust ermittelte.";
define('MatrixSingularException', -7);
$error['EN'][-7] = "Can only perform operation on singular matrix.";
$error['EN'][MatrixSingularException] = "Can only perform operation on singular matrix.";
define('MatrixRankException', -8);
$error['EN'][-8] = "Can only perform operation on full-rank matrix.";
$error['EN'][MatrixRankException] = "Can only perform operation on full-rank matrix.";
define('ArrayLengthException', -9);
$error['EN'][-9] = "Array length must be a multiple of m.";
$error['EN'][ArrayLengthException] = "Array length must be a multiple of m.";
define('RowLengthException', -10);
$error['EN'][-10] = "All rows must have the same length.";
$error['EN'][RowLengthException] = "All rows must have the same length.";
/**
* Custom error handler
* @param int $type Error type: {ERROR, WARNING, NOTICE}
* @param int $num Error number
* @param string $file File in which the error occured
* @param int $line Line on which the error occured
*/
function JAMAError( $type = null, $num = null, $file = null, $line = null, $context = null ) {
global $error;
$lang = LANG;
if( isset($type) && isset($num) && isset($file) && isset($line) ) {
switch( $type ) {
case ERROR:
echo '<div class="errror"><b>Error:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
die();
break;
case WARNING:
echo '<div class="warning"><b>Warning:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
break;
case NOTICE:
//echo '<div class="notice"><b>Notice:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
break;
* Custom error handler
* @param int $num Error number
*/
function JAMAError($errorNumber = null) {
global $error;
case E_NOTICE:
//echo '<div class="errror"><b>Notice:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
break;
case E_STRICT:
break;
case E_WARNING:
break;
default:
echo "<div class=\"error\"><b>Unknown Error Type:</b> $type - $file @ L{$line}</div>";
die();
break;
}
} else {
die( "Invalid arguments to JAMAError()" );
}
if (isset($errorNumber)) {
if (isset($error[JAMALANG][$errorNumber])) {
return $error[JAMALANG][$errorNumber];
} else {
return $error['EN'][$errorNumber];
}
} else {
return ("Invalid argument to JAMAError()");
}
}
// TODO MarkBaker
//set_error_handler('JAMAError');
//error_reporting(ERROR | WARNING);

View File

@@ -1,40 +1,43 @@
<?php
/**
* @package JAMA
*
* Pythagorean Theorem:
*
* a = 3
* b = 4
* r = sqrt(square(a) + square(b))
* r = 5
*
* r = sqrt(a^2 + b^2) without under/overflow.
*/
/**
* @package JAMA
*
* Pythagorean Theorem:
*
* a = 3
* b = 4
* r = sqrt(square(a) + square(b))
* r = 5
*
* r = sqrt(a^2 + b^2) without under/overflow.
*/
function hypo($a, $b) {
if (abs($a) > abs($b)) {
$r = $b/$a;
$r = abs($a)* sqrt(1+$r*$r);
} else if ($b != 0) {
$r = $a/$b;
$r = abs($b)*sqrt(1+$r*$r);
} else
$r = 0.0;
return $r;
}
if (abs($a) > abs($b)) {
$r = $b / $a;
$r = abs($a) * sqrt(1 + $r * $r);
} elseif ($b != 0) {
$r = $a / $b;
$r = abs($b) * sqrt(1 + $r * $r);
} else {
$r = 0.0;
}
return $r;
} // function hypo()
/**
* Mike Bommarito's version.
* Compute n-dimensional hyotheneuse.
*
* Mike Bommarito's version.
* Compute n-dimensional hyotheneuse.
*
function hypot() {
$s = 0;
foreach (func_get_args() as $d) {
if (is_numeric($d))
$s += pow($d, 2);
else
trigger_error(ArgumentTypeException, ERROR);
}
return sqrt($s);
$s = 0;
foreach (func_get_args() as $d) {
if (is_numeric($d)) {
$s += pow($d, 2);
} else {
throw new Exception(JAMAError(ArgumentTypeException));
}
}
return sqrt($s);
}
*/

View File

@@ -19,19 +19,6 @@
//
// $Id: OLE.php,v 1.13 2007/03/07 14:38:25 schmidt Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_File.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_Root.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/ChainedBlockStream.php';
/**
* Array for storing OLE instances that are accessed from
@@ -527,20 +514,9 @@ class PHPExcel_Shared_OLE
// factor used for separating numbers into 4 bytes parts
$factor = pow(2,32);
$high_part = 0;
for ($i = 0; $i < 4; ++$i) {
list(, $high_part) = unpack('C', $string{(7 - $i)});
if ($i < 3) {
$high_part *= 0x100;
}
}
$low_part = 0;
for ($i = 4; $i < 8; ++$i) {
list(, $low_part) = unpack('C', $string{(7 - $i)});
if ($i < 7) {
$low_part *= 0x100;
}
}
list(, $high_part) = unpack('V', substr($string, 4, 4));
list(, $low_part) = unpack('V', substr($string, 0, 4));
$big_date = ($high_part * $factor) + $low_part;
// translate to seconds
$big_date /= 10000000;

View File

@@ -2,18 +2,18 @@
/**
* PHPExcel
*
* Copyright (C) 2006 - 2009 PHPExcel
* Copyright (C) 2006 - 2010 PHPExcel
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -22,19 +22,9 @@
* @package PHPExcel_Shared_OLE
* @copyright Copyright (c) 2006 - 2007 Christian Schmidt
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE.php';
/**
* PHPExcel_Shared_OLE_ChainedBlockStream
*

View File

@@ -20,16 +20,6 @@
// $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE.php';
/**
* Class for creating PPS's for OLE containers
*
@@ -162,13 +152,13 @@ class PHPExcel_Shared_OLE_PPS
if (!isset($this->_data)) {
return 0;
}
if (isset($this->_PPS_FILE)) {
fseek($this->_PPS_FILE, 0);
$stats = fstat($this->_PPS_FILE);
return $stats[7];
} else {
//if (isset($this->_PPS_FILE)) {
// fseek($this->_PPS_FILE, 0);
// $stats = fstat($this->_PPS_FILE);
// return $stats[7];
//} else {
return strlen($this->_data);
}
//}
}
/**

View File

@@ -20,16 +20,6 @@
// $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
/**
* Class for creating File PPS's for OLE containers
*
@@ -39,12 +29,6 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
*/
class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
{
/**
* The temporary dir for storing the OLE file
* @var string
*/
public $_tmp_dir;
/**
* The constructor
*
@@ -54,9 +38,8 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/
public function __construct($name)
{
$this->_tmp_dir = '';
parent::__construct(
null,
null,
$name,
PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE,
null,
@@ -68,22 +51,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
array());
}
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
public function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
/**
* Initialization method. Has to be called right after OLE_PPS_File().
*
@@ -92,15 +59,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/
public function init()
{
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
$fh = fopen($this->_tmp_filename, "w+b");
if ($fh === false) {
throw new Exception("Can't create temporary file");
}
$this->_PPS_FILE = $fh;
if ($this->_PPS_FILE) {
fseek($this->_PPS_FILE, 0);
}
return true;
}
@@ -112,11 +70,7 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/
public function append($data)
{
if ($this->_PPS_FILE) {
fwrite($this->_PPS_FILE, $data);
} else {
$this->_data .= $data;
}
$this->_data .= $data;
}
/**

View File

@@ -20,16 +20,6 @@
// $Id: Root.php,v 1.9 2005/04/23 21:53:49 dufuz Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
/**
* Class for creating Root PPS's for OLE containers
*
@@ -39,19 +29,12 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
*/
class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
{
/**
* The temporary dir for storing the OLE file
* @var string
*/
public $_tmp_dir;
/**
* @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp
*/
public function __construct($time_1st, $time_2nd, $raChild)
{
$this->_tmp_dir = '';
parent::__construct(
null,
PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'),
@@ -65,28 +48,14 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$raChild);
}
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
public function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
/**
* Method for saving the whole OLE container (including files).
* In fact, if called with an empty argument (or '-'), it saves to a
* temporary file and then outputs it's contents to stdout.
* If a resource pointer to a stream created by fopen() is passed
* it will be used, but you have to close such stream by yourself.
*
* @param string $filename The name of the file where to save the OLE container
* @param string|resource $filename The name of the file or stream where to save the OLE container.
* @access public
* @return mixed true on success
*/
@@ -98,18 +67,19 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$this->_SMALL_BLOCK_SIZE= pow(2,
((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
// Open temp file if we are sending output to stdout
if ($filename == '-' || $filename == '') {
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) {
throw new Exception("Can't create temporary file.");
if (is_resource($filename)) {
$this->_FILEH_ = $filename;
} else if ($filename == '-' || $filename == '') {
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) {
throw new Exception("Can't create temporary file.");
}
} else {
$this->_FILEH_ = fopen($filename, "wb");
if ($this->_FILEH_ == false) {
throw new Exception("Can't open $filename. It may be in use or protected.");
}
}
if ($this->_FILEH_ == false) {
throw new Exception("Can't open $filename. It may be in use or protected.");
}
// Make an array of PPS's (for Save)
$aList = array();
@@ -128,16 +98,10 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$this->_savePps($aList);
// Write Big Block Depot and BDList and Adding Header informations
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
// Close File, send it to stdout if necessary
if (($filename == '-') || ($filename == '')) {
fseek($this->_FILEH_, 0);
fpassthru($this->_FILEH_);
fclose($this->_FILEH_);
// Delete the temporary file.
unlink($this->_tmp_filename);
} else {
fclose($this->_FILEH_);
}
if (!is_resource($filename)) {
fclose($this->_FILEH_);
}
return true;
}
@@ -248,7 +212,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
. pack("V", 0)
. pack("V", 0x1000)
. pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot
. pack("V", 1)
. pack("V", $iSBDcnt)
);
// Extra BDList Start, Count
if ($iBdCnt < $i1stBdL) {
@@ -290,16 +254,16 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
(($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data)))
{
// Write Data
if (isset($raList[$i]->_PPS_FILE)) {
$iLen = 0;
fseek($raList[$i]->_PPS_FILE, 0); // To The Top
while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
$iLen += strlen($sBuff);
fwrite($FILE, $sBuff);
}
} else {
//if (isset($raList[$i]->_PPS_FILE)) {
// $iLen = 0;
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top
// while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
// $iLen += strlen($sBuff);
// fwrite($FILE, $sBuff);
// }
//} else {
fwrite($FILE, $raList[$i]->_data);
}
//}
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); ++$j) {
@@ -313,11 +277,11 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
}
// Close file for each PPS, and unlink it
if (isset($raList[$i]->_PPS_FILE)) {
fclose($raList[$i]->_PPS_FILE);
$raList[$i]->_PPS_FILE = null;
unlink($raList[$i]->_tmp_filename);
}
//if (isset($raList[$i]->_PPS_FILE)) {
// fclose($raList[$i]->_PPS_FILE);
// $raList[$i]->_PPS_FILE = null;
// unlink($raList[$i]->_tmp_filename);
//}
}
}
}
@@ -349,15 +313,15 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
}
fwrite($FILE, pack("V", -2));
// Add to Data String(this will be written for RootEntry)
if ($raList[$i]->_PPS_FILE) {
fseek($raList[$i]->_PPS_FILE, 0); // To The Top
while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
$sRes .= $sBuff;
}
} else {
//// Add to Data String(this will be written for RootEntry)
//if ($raList[$i]->_PPS_FILE) {
// fseek($raList[$i]->_PPS_FILE, 0); // To The Top
// while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
// $sRes .= $sBuff;
// }
//} else {
$sRes .= $raList[$i]->_data;
}
//}
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) {
$sRes .= "\x00";

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
@@ -162,7 +162,6 @@ class PHPExcel_Shared_OLERead {
$this->entry = $this->_readData($block);
$this->_readPropertySets();
}
/**
@@ -213,6 +212,58 @@ class PHPExcel_Shared_OLERead {
}
}
/**
* Extract binary stream data, summary information
*
* @return string|null
*/
public function getSummaryInformation()
{
if (!isset($this->summaryInformation)) {
return null;
}
if ($this->props[$this->summaryInformation]['size'] < self::SMALL_BLOCK_THRESHOLD){
$rootdata = $this->_readData($this->props[$this->rootentry]['startBlock']);
$streamData = '';
$block = $this->props[$this->summaryInformation]['startBlock'];
$pos = 0;
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
$block = $this->smallBlockChain[$block];
}
return $streamData;
} else {
$numBlocks = $this->props[$this->summaryInformation]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$this->summaryInformation]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
if ($numBlocks == 0) return '';
$streamData = '';
$block = $this->props[$this->summaryInformation]['startBlock'];
$pos = 0;
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block];
}
return $streamData;
}
}
/**
* Read a standard stream (by joining sectors using information from SAT)
*
@@ -271,7 +322,7 @@ class PHPExcel_Shared_OLERead {
'size' => $size);
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
if (($name == 'Workbook') || ($name == 'Book') || ($name == 'WORKBOOK')) {
if (($name == 'Workbook') || ($name == 'Book') || ($name == 'WORKBOOK') || ($name == 'BOOK')) {
$this->wrkbook = count($this->props) - 1;
}
@@ -280,6 +331,11 @@ class PHPExcel_Shared_OLERead {
$this->rootentry = count($this->props) - 1;
}
// Summary information
if ($name == chr(5) . 'SummaryInformation') {
$this->summaryInformation = count($this->props) - 1;
}
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_PasswordHasher
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,10 +31,16 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_String
{
/** Constants */
/** Regular Expressions */
// Fraction
const STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)';
/**
* Control characters array
*
@@ -42,6 +48,27 @@ class PHPExcel_Shared_String
*/
private static $_controlCharacters = array();
/**
* SYLK Characters array
*
* $var array
*/
private static $_SYLKCharacters = array();
/**
* Decimal separator
*
* @var string
*/
private static $_decimalSeparator;
/**
* Thousands separator
*
* @var string
*/
private static $_thousandsSeparator;
/**
* Is mbstring extension avalable?
*
@@ -60,7 +87,7 @@ class PHPExcel_Shared_String
* Build control characters array
*/
private static function _buildControlCharacters() {
for ($i = 0; $i <= 19; ++$i) {
for ($i = 0; $i <= 31; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
$replace = chr($i);
@@ -69,6 +96,171 @@ class PHPExcel_Shared_String
}
}
/**
* Build SYLK characters array
*/
private static function _buildSYLKCharacters()
{
self::$_SYLKCharacters = array(
"\x1B 0" => chr(0),
"\x1B 1" => chr(1),
"\x1B 2" => chr(2),
"\x1B 3" => chr(3),
"\x1B 4" => chr(4),
"\x1B 5" => chr(5),
"\x1B 6" => chr(6),
"\x1B 7" => chr(7),
"\x1B 8" => chr(8),
"\x1B 9" => chr(9),
"\x1B :" => chr(10),
"\x1B ;" => chr(11),
"\x1B <" => chr(12),
"\x1B :" => chr(13),
"\x1B >" => chr(14),
"\x1B ?" => chr(15),
"\x1B!0" => chr(16),
"\x1B!1" => chr(17),
"\x1B!2" => chr(18),
"\x1B!3" => chr(19),
"\x1B!4" => chr(20),
"\x1B!5" => chr(21),
"\x1B!6" => chr(22),
"\x1B!7" => chr(23),
"\x1B!8" => chr(24),
"\x1B!9" => chr(25),
"\x1B!:" => chr(26),
"\x1B!;" => chr(27),
"\x1B!<" => chr(28),
"\x1B!=" => chr(29),
"\x1B!>" => chr(30),
"\x1B!?" => chr(31),
"\x1B'?" => chr(127),
"\x1B(0" => '€', // 128 in CP1252
"\x1B(2" => '', // 130 in CP1252
"\x1B(3" => 'ƒ', // 131 in CP1252
"\x1B(4" => '„', // 132 in CP1252
"\x1B(5" => '…', // 133 in CP1252
"\x1B(6" => '†', // 134 in CP1252
"\x1B(7" => '‡', // 135 in CP1252
"\x1B(8" => 'ˆ', // 136 in CP1252
"\x1B(9" => '‰', // 137 in CP1252
"\x1B(:" => 'Š', // 138 in CP1252
"\x1B(;" => '', // 139 in CP1252
"\x1BNj" => 'Œ', // 140 in CP1252
"\x1B(>" => 'Ž', // 142 in CP1252
"\x1B)1" => '', // 145 in CP1252
"\x1B)2" => '', // 146 in CP1252
"\x1B)3" => '“', // 147 in CP1252
"\x1B)4" => '”', // 148 in CP1252
"\x1B)5" => '•', // 149 in CP1252
"\x1B)6" => '', // 150 in CP1252
"\x1B)7" => '—', // 151 in CP1252
"\x1B)8" => '˜', // 152 in CP1252
"\x1B)9" => '™', // 153 in CP1252
"\x1B):" => 'š', // 154 in CP1252
"\x1B);" => '', // 155 in CP1252
"\x1BNz" => 'œ', // 156 in CP1252
"\x1B)>" => 'ž', // 158 in CP1252
"\x1B)?" => 'Ÿ', // 159 in CP1252
"\x1B*0" => ' ', // 160 in CP1252
"\x1BN!" => '¡', // 161 in CP1252
"\x1BN\"" => '¢', // 162 in CP1252
"\x1BN#" => '£', // 163 in CP1252
"\x1BN(" => '¤', // 164 in CP1252
"\x1BN%" => '¥', // 165 in CP1252
"\x1B*6" => '¦', // 166 in CP1252
"\x1BN'" => '§', // 167 in CP1252
"\x1BNH " => '¨', // 168 in CP1252
"\x1BNS" => '©', // 169 in CP1252
"\x1BNc" => 'ª', // 170 in CP1252
"\x1BN+" => '«', // 171 in CP1252
"\x1B*<" => '¬', // 172 in CP1252
"\x1B*=" => '­', // 173 in CP1252
"\x1BNR" => '®', // 174 in CP1252
"\x1B*?" => '¯', // 175 in CP1252
"\x1BN0" => '°', // 176 in CP1252
"\x1BN1" => '±', // 177 in CP1252
"\x1BN2" => '²', // 178 in CP1252
"\x1BN3" => '³', // 179 in CP1252
"\x1BNB " => '´', // 180 in CP1252
"\x1BN5" => 'µ', // 181 in CP1252
"\x1BN6" => '¶', // 182 in CP1252
"\x1BN7" => '·', // 183 in CP1252
"\x1B+8" => '¸', // 184 in CP1252
"\x1BNQ" => '¹', // 185 in CP1252
"\x1BNk" => 'º', // 186 in CP1252
"\x1BN;" => '»', // 187 in CP1252
"\x1BN<" => '¼', // 188 in CP1252
"\x1BN=" => '½', // 189 in CP1252
"\x1BN>" => '¾', // 190 in CP1252
"\x1BN?" => '¿', // 191 in CP1252
"\x1BNAA" => 'À', // 192 in CP1252
"\x1BNBA" => 'Á', // 193 in CP1252
"\x1BNCA" => 'Â', // 194 in CP1252
"\x1BNDA" => 'Ã', // 195 in CP1252
"\x1BNHA" => 'Ä', // 196 in CP1252
"\x1BNJA" => 'Å', // 197 in CP1252
"\x1BNa" => 'Æ', // 198 in CP1252
"\x1BNKC" => 'Ç', // 199 in CP1252
"\x1BNAE" => 'È', // 200 in CP1252
"\x1BNBE" => 'É', // 201 in CP1252
"\x1BNCE" => 'Ê', // 202 in CP1252
"\x1BNHE" => 'Ë', // 203 in CP1252
"\x1BNAI" => 'Ì', // 204 in CP1252
"\x1BNBI" => 'Í', // 205 in CP1252
"\x1BNCI" => 'Î', // 206 in CP1252
"\x1BNHI" => 'Ï', // 207 in CP1252
"\x1BNb" => 'Ð', // 208 in CP1252
"\x1BNDN" => 'Ñ', // 209 in CP1252
"\x1BNAO" => 'Ò', // 210 in CP1252
"\x1BNBO" => 'Ó', // 211 in CP1252
"\x1BNCO" => 'Ô', // 212 in CP1252
"\x1BNDO" => 'Õ', // 213 in CP1252
"\x1BNHO" => 'Ö', // 214 in CP1252
"\x1B-7" => '×', // 215 in CP1252
"\x1BNi" => 'Ø', // 216 in CP1252
"\x1BNAU" => 'Ù', // 217 in CP1252
"\x1BNBU" => 'Ú', // 218 in CP1252
"\x1BNCU" => 'Û', // 219 in CP1252
"\x1BNHU" => 'Ü', // 220 in CP1252
"\x1B-=" => 'Ý', // 221 in CP1252
"\x1BNl" => 'Þ', // 222 in CP1252
"\x1BN{" => 'ß', // 223 in CP1252
"\x1BNAa" => 'à', // 224 in CP1252
"\x1BNBa" => 'á', // 225 in CP1252
"\x1BNCa" => 'â', // 226 in CP1252
"\x1BNDa" => 'ã', // 227 in CP1252
"\x1BNHa" => 'ä', // 228 in CP1252
"\x1BNJa" => 'å', // 229 in CP1252
"\x1BNq" => 'æ', // 230 in CP1252
"\x1BNKc" => 'ç', // 231 in CP1252
"\x1BNAe" => 'è', // 232 in CP1252
"\x1BNBe" => 'é', // 233 in CP1252
"\x1BNCe" => 'ê', // 234 in CP1252
"\x1BNHe" => 'ë', // 235 in CP1252
"\x1BNAi" => 'ì', // 236 in CP1252
"\x1BNBi" => 'í', // 237 in CP1252
"\x1BNCi" => 'î', // 238 in CP1252
"\x1BNHi" => 'ï', // 239 in CP1252
"\x1BNs" => 'ð', // 240 in CP1252
"\x1BNDn" => 'ñ', // 241 in CP1252
"\x1BNAo" => 'ò', // 242 in CP1252
"\x1BNBo" => 'ó', // 243 in CP1252
"\x1BNCo" => 'ô', // 244 in CP1252
"\x1BNDo" => 'õ', // 245 in CP1252
"\x1BNHo" => 'ö', // 246 in CP1252
"\x1B/7" => '÷', // 247 in CP1252
"\x1BNy" => 'ø', // 248 in CP1252
"\x1BNAu" => 'ù', // 249 in CP1252
"\x1BNBu" => 'ú', // 250 in CP1252
"\x1BNCu" => 'û', // 251 in CP1252
"\x1BNHu" => 'ü', // 252 in CP1252
"\x1B/=" => 'ý', // 253 in CP1252
"\x1BN|" => 'þ', // 254 in CP1252
"\x1BNHy" => 'ÿ', // 255 in CP1252
);
}
/**
* Get whether mbstring extension is available
*
@@ -97,14 +289,37 @@ class PHPExcel_Shared_String
return self::$_isIconvEnabled;
}
// IBM AIX iconv() does not work
self::$_isIconvEnabled = function_exists('iconv') &&
!(defined('PHP_OS') && @stristr(PHP_OS, 'AIX') && defined('ICONV_IMPL')
&& (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && defined('ICONV_VERSION')
&& (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) ?
true : false;
// Fail if iconv doesn't exist
if (!function_exists('iconv')) {
self::$_isIconvEnabled = false;
return false;
}
return self::$_isIconvEnabled;
// Sometimes iconv is not working, and e.g. iconv('UTF-8', 'UTF-16LE', 'x') just returns false,
if (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
self::$_isIconvEnabled = false;
return false;
}
// Sometimes iconv_substr('A', 0, 1, 'UTF-8') just returns false in PHP 5.2.0
// we cannot use iconv in that case either (http://bugs.php.net/bug.php?id=37773)
if (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
self::$_isIconvEnabled = false;
return false;
}
// CUSTOM: IBM AIX iconv() does not work
if ( defined('PHP_OS') && @stristr(PHP_OS, 'AIX')
&& defined('ICONV_IMPL') && (@strcasecmp(ICONV_IMPL, 'unknown') == 0)
&& defined('ICONV_VERSION') && (@strcasecmp(ICONV_VERSION, 'unknown') == 0) )
{
self::$_isIconvEnabled = false;
return false;
}
// If we reach here no problems were detected with iconv
self::$_isIconvEnabled = true;
return true;
}
/**
@@ -172,7 +387,7 @@ class PHPExcel_Shared_String
// else, no conversion
return $value;
}
/**
* Check if a string contains UTF8 data
*
@@ -213,7 +428,7 @@ class PHPExcel_Shared_String
$ln = self::CountCharacters($value, 'UTF-8');
// option flags
$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
0x0001 : 0x0000;
// characters
@@ -239,7 +454,7 @@ class PHPExcel_Shared_String
$ln = self::CountCharacters($value, 'UTF-8');
// option flags
$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
0x0001 : 0x0000;
// characters
@@ -250,7 +465,7 @@ class PHPExcel_Shared_String
}
/**
* Convert string from one encoding to another. First try mbstring, then iconv, or no convertion
* Convert string from one encoding to another. First try iconv, then mbstring, or no convertion
*
* @param string $value
* @param string $to Encoding to convert to, e.g. 'UTF-8'
@@ -268,11 +483,46 @@ class PHPExcel_Shared_String
$value = mb_convert_encoding($value, $to, $from);
return $value;
}
if($from == 'UTF-16LE'){
return self::utf16_decode($value, false);
}else if($from == 'UTF-16BE'){
return self::utf16_decode($value);
}
// else, no conversion
return $value;
}
/**
* Decode UTF-16 encoded strings.
*
* Can handle both BOM'ed data and un-BOM'ed data.
* Assumes Big-Endian byte order if no BOM is available.
* This function was taken from http://php.net/manual/en/function.utf8-decode.php
* and $bom_be parameter added.
*
* @param string $str UTF-16 encoded data to decode.
* @return string UTF-8 / ISO encoded data.
* @access public
* @version 0.2 / 2010-05-13
* @author Rasmus Andersson {@link http://rasmusandersson.se/}
* @author vadik56
*/
function utf16_decode( $str, $bom_be=true ) {
if( strlen($str) < 2 ) return $str;
$c0 = ord($str{0});
$c1 = ord($str{1});
if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
$len = strlen($str);
$newstr = '';
for($i=0;$i<$len;$i+=2) {
if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
$newstr .= ($val == 0x228) ? "\n" : chr($val);
}
return $newstr;
}
/**
* Get character count. First try mbstring, then iconv, finally strlen
*
@@ -322,4 +572,106 @@ class PHPExcel_Shared_String
return $string;
}
/**
* Identify whether a string contains a fractional numeric value,
* and convert it to a numeric if it is
*
* @param string &$operand string value to test
* @return boolean
*/
public static function convertToNumberIfFraction(&$operand) {
if (preg_match('/^'.self::STRING_REGEXP_FRACTION.'$/i', $operand, $match)) {
$sign = ($match[1] == '-') ? '-' : '+';
$fractionFormula = '='.$sign.$match[2].$sign.$match[3];
$operand = PHPExcel_Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
return true;
}
return false;
} // function convertToNumberIfFraction()
/**
* Get the decimal separator. If it has not yet been set explicitly, try to obtain number
* formatting information from locale.
*
* @return string
*/
public static function getDecimalSeparator()
{
if (!isset(self::$_decimalSeparator)) {
$localeconv = localeconv();
self::$_decimalSeparator = $localeconv['decimal_point'] != ''
? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
if (self::$_decimalSeparator == '')
{
// Default to .
self::$_decimalSeparator = '.';
}
}
return self::$_decimalSeparator;
}
/**
* Set the decimal separator. Only used by PHPExcel_Style_NumberFormat::toFormattedString()
* to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF
*
* @param string $pValue Character for decimal separator
*/
public static function setDecimalSeparator($pValue = '.')
{
self::$_decimalSeparator = $pValue;
}
/**
* Get the thousands separator. If it has not yet been set explicitly, try to obtain number
* formatting information from locale.
*
* @return string
*/
public static function getThousandsSeparator()
{
if (!isset(self::$_thousandsSeparator)) {
$localeconv = localeconv();
self::$_thousandsSeparator = $localeconv['thousands_sep'] != ''
? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
}
return self::$_thousandsSeparator;
}
/**
* Set the thousands separator. Only used by PHPExcel_Style_NumberFormat::toFormattedString()
* to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF
*
* @param string $pValue Character for thousands separator
*/
public static function setThousandsSeparator($pValue = ',')
{
self::$_thousandsSeparator = $pValue;
}
/**
* Convert SYLK encoded string to UTF-8
*
* @param string $pValue
* @return string UTF-8 encoded string
*/
public static function SYLKtoUTF8($pValue = '')
{
// If there is no escape character in the string there is nothing to do
if (strpos($pValue, '') === false) {
return $pValue;
}
if(empty(self::$_SYLKCharacters)) {
self::_buildSYLKCharacters();
}
foreach (self::$_SYLKCharacters as $k => $v) {
$pValue = str_replace($k, $v, $pValue);
}
return $pValue;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
if (!defined('DATE_W3C')) {
@@ -34,7 +34,7 @@ if (!defined('DATE_W3C')) {
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_XMLWriter {
/** Temporary storage method */

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,22 +20,18 @@
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** Register new zip wrapper */
PHPExcel_Shared_ZipStreamWrapper::register();
/**
* PHPExcel_Shared_ZipStreamWrapper
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipStreamWrapper {
/**
@@ -83,24 +79,9 @@ class PHPExcel_Shared_ZipStreamWrapper {
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
}
// Parse URL
$url = @parse_url($path);
// Fix URL
if (!is_array($url)) {
$url['host'] = substr($path, strlen('zip://'));
$url['path'] = '';
}
if (strpos($url['host'], '#') !== false) {
if (!isset($url['fragment'])) {
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
unset($url['path']);
}
} else {
$url['host'] = $url['host'] . $url['path'];
unset($url['path']);
}
$pos = strrpos($path, '#');
$url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
$url['fragment'] = substr($path, $pos + 1);
// Open archive
$this->_archive = new ZipArchive();

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Best_Fit
{
@@ -239,7 +239,11 @@ class PHPExcel_Best_Fit
$this->_SSResiduals = $SSres;
$this->_DFResiduals = $this->_valueCount - 1 - $const;
$this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
if ($this->_DFResiduals == 0.0) {
$this->_stdevOfResiduals = 0.0;
} else {
$this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
}
if (($SStot == 0.0) || ($SSres == $SStot)) {
$this->_goodnessOfFit = 1;
} else {
@@ -252,9 +256,17 @@ class PHPExcel_Best_Fit
$this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
$this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2));
if ($this->_SSResiduals != 0.0) {
$this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals);
if ($this->_DFResiduals == 0.0) {
$this->_F = 0.0;
} else {
$this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals);
}
} else {
$this->_F = $this->_SSRegression / $this->_DFResiduals;
if ($this->_DFResiduals == 0.0) {
$this->_F = 0.0;
} else {
$this->_F = $this->_SSRegression / $this->_DFResiduals;
}
}
} // function _calculateGoodnessOfFit()

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
{
@@ -84,8 +76,14 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
private function _exponential_regression($yValues, $xValues, $const) {
$mArray = $xValues;
$yValues = array_map('log',$yValues);
foreach($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _exponential_regression()

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
{
@@ -68,8 +60,14 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
private function _logarithmic_regression($yValues, $xValues, $const) {
$mArray = $xValues;
$xValues = array_map('log',$xValues);
foreach($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _logarithmic_regression()

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
@@ -43,7 +35,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2009 PHPExcel
* Copyright (c) 2006 - 2010 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
* @version 1.7.3c, 2010-06-01
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
@@ -42,7 +34,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
{
@@ -76,10 +68,22 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
private function _power_regression($yValues, $xValues, $const) {
$mArray = $xValues;
sort($mArray,SORT_NUMERIC);
$xValues = array_map('log',$xValues);
$yValues = array_map('log',$yValues);
foreach($xValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
foreach($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const);
} // function _power_regression()

View File

@@ -1,13 +1,5 @@
<?php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php';

Some files were not shown because too many files have changed in this diff Show More