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. + [doc] Incorporate synchronisation docs into main document.
+ [core] Include Content Security Policy HTTP headers. + [core] Include Content Security Policy HTTP headers.
- bug #3004216 [CSS] Field attributes use inline CSS - 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) 3.3.4.0 (not yet released)
- bug #2996161 [import] properly escape import value - bug #2996161 [import] properly escape import value
- bug #2998889 [import] Import button does not work in Catalan - bug #2998889 [import] Import button does not work in Catalan
- [browse] Fix handling of sort order if only column is specified. - [browse] Fix handling of sort order if only column is specified.
+ [lang] Greek update, thanks to Panagiotis Papazoglou - panos78 + [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) 3.3.3.0 (2010-05-10)
- patch #2982480 [navi] Do not group if there would be one table in group, - 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> <h3>Currently phpMyAdmin can:</h3>
<ul><li>browse and drop databases, tables, views, fields and indexes</li> <ul><li>browse and drop databases, tables, views, columns and indexes</li>
<li>create, copy, drop, rename and alter databases, tables, fields and <li>create, copy, drop, rename and alter databases, tables, columns and
indexes</li> indexes</li>
<li>maintenance server, databases and tables, with proposals on server <li>maintenance server, databases and tables, with proposals on server
configuration</li> configuration</li>
@@ -328,7 +328,7 @@ rm -rf config # remove not needed directory
<p> For a whole set of new features (bookmarks, comments, <p> For a whole set of new features (bookmarks, comments,
<abbr title="structured query language">SQL</abbr>-history, <abbr title="structured query language">SQL</abbr>-history,
tracking mechanism, 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 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 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 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 <span id="cfg_Servers_relation">$cfg['Servers'][$i]['relation']</span> string
</dt> </dt>
<dd>Since release 2.2.4 you can describe, in a special 'relation' table, <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 currently uses this to
<ul><li>make clickable, when you browse the master table, the data values <ul><li>make clickable, when you browse the master table, the data values
that point to the foreign table;</li> 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 when browsing the master table, if you move the mouse to a column
containing a foreign key (use also the 'table_info' table);<br /> containing a foreign key (use also the 'table_info' table);<br />
(see <a href="#faqdisplay"><abbr title="Frequently Asked Questions"> (see <a href="#faqdisplay"><abbr title="Frequently Asked Questions">
FAQ</abbr> 6.7</a>)</li> FAQ</abbr> 6.7</a>)</li>
<li>in edit/insert mode, display a drop-down list of possible foreign <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"> (see <a href="#faq6_21"><abbr title="Frequently Asked Questions">
FAQ</abbr> 6.21</a>)</li> FAQ</abbr> 6.21</a>)</li>
<li>display links on the table properties page, to check referential <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> <tt>$cfg['Servers'][$i]['relation']</tt></li>
<li>now as normal user open phpMyAdmin and for each one of your <li>now as normal user open phpMyAdmin and for each one of your
tables where you want to use this feature, click 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> </li>
</ul> </ul>
Please note that in the current version, <tt>master_db</tt> 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. future development of the cross-db relations.
</dd> </dd>
@@ -939,7 +940,7 @@ since this link provides funding for phpMyAdmin.
</dt> </dt>
<dd> <dd>
Since release 2.3.0 you can describe, in a special 'table_info' 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 /> cursor over the corresponding key.<br />
This configuration variable will hold the name of this special This configuration variable will hold the name of this special
table. To allow the usage of this functionality: 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 <li>put the table name in
<tt>$cfg['Servers'][$i]['table_info']</tt></li> <tt>$cfg['Servers'][$i]['table_info']</tt></li>
<li>then for each table where you want to use this feature, <li>then for each table where you want to use this feature,
click &quot;Structure/Relation view/Choose field to display&quot; click &quot;Structure/Relation view/Choose column to display&quot;
to choose the field.</li> to choose the column.</li>
</ul> </ul>
Usage tip: <a href="#faqdisplay">Display field</a>. Usage tip: <a href="#faqdisplay">Display column</a>.
</dd> </dd>
<dt id="table_coords"> <dt id="table_coords">
<span id="cfg_Servers_table_coords">$cfg['Servers'][$i]['table_coords']</span> string<br /> <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"> based on the following table structure. See <a href="#transformations">
Transformations</a> for further information. To use the Transformations</a> for further information. To use the
MIME-transformation system, your column_info table has to have the three 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 /> <br /><br />
To allow the usage of this functionality: 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><span id="cfg_Servers_verbose_check">$cfg['Servers'][$i]['verbose_check']</span> boolean
</dt> </dt>
<dd>Because release 2.5.0 introduced the new MIME-transformation support, the <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 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 latest table structure available. If not, it will emit a warning to the
superuser.<br /><br /> 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> 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> <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; 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> DATE, DATETIME and TIMESTAMP, ascending order else- by default.</dd>
<dt id="cfg_DisplayBinaryAsHex">$cfg['DisplayBinaryAsHex'] boolean </dt> <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> option is ticked by default.</dd>
<dt id="cfg_ProtectBinary">$cfg['ProtectBinary'] boolean or string</dt> <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: from editing when browsing a table's content. Valid values are:
<ul><li><tt>FALSE</tt> to allow editing of all fields;</li> <ul><li><tt>FALSE</tt> to allow editing of all columns;</li>
<li><tt>'blob'</tt> to allow editing of all fields except <tt>BLOBS</tt>;</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 <li><tt>'all'</tt> to disallow editing of all <tt>BINARY</tt> or
<tt>BLOB</tt> fields.</li> <tt>BLOB</tt> columns.</li>
</ul> </ul>
</dd> </dd>
@@ -1564,10 +1565,10 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre>
<dt id="cfg_CharEditing">$cfg['CharEditing'] string</dt> <dt id="cfg_CharEditing">$cfg['CharEditing'] string</dt>
<dd>Defines which type of editing controls should be used for CHAR and <dd>Defines which type of editing controls should be used for CHAR and
VARCHAR fields. Possible values are: VARCHAR columns. Possible values are:
<ul><li>input - this allows to limit size of text to size of field in <ul><li>input - this allows to limit size of text to size of columns in
MySQL, but has problems with newlines in fields</li> MySQL, but has problems with newlines in columns</li>
<li>textarea - no problems with newlines in fields, but also no <li>textarea - no problems with newlines in columns, but also no
length limitations</li> length limitations</li>
</ul> </ul>
Default is old behavior so input.</dd> Default is old behavior so input.</dd>
@@ -1850,7 +1851,7 @@ $cfg['TrustedProxies'] =
<dt><span id="cfg_LongtextDoubleTextarea">$cfg['LongtextDoubleTextarea'] </span>boolean <dt><span id="cfg_LongtextDoubleTextarea">$cfg['LongtextDoubleTextarea'] </span>boolean
</dt> </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><span id="cfg_TextareaAutoSelect">$cfg['TextareaAutoSelect'] </span>boolean
</dt> </dt>
@@ -1863,7 +1864,7 @@ $cfg['TrustedProxies'] =
editing.</dd> editing.</dd>
<dt id="cfg_LimitChars">$cfg['LimitChars'] integer</dt> <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> Can be turned off by a toggle button on the browse page.</dd>
<dt><span id="cfg_ModifyDeleteAtLeft">$cfg['ModifyDeleteAtLeft'] </span>boolean <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. <dd>There are 3 display modes: horizontal, horizontalflipped and vertical.
Define which one is displayed by default. The first mode displays each Define which one is displayed by default. The first mode displays each
row on a horizontal line, the second rotates the headers by 90 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 contain small values and still print them out. The vertical mode sorts
each row on a vertical lineup. each row on a vertical lineup.
</dd> </dd>
@@ -1903,9 +1904,9 @@ $cfg['TrustedProxies'] =
'vertical' you can have each field lined up vertically beneath each '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 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 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 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 /> <dt id="cfg_ShowBrowseComments">$cfg['ShowBrowseComments'] boolean<br />
<span id="cfg_ShowPropertyComments">$cfg['ShowPropertyComments'] </span>boolean <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 display of column comments in Browse or Property display. In browse
mode, the comments are shown inside the header. In property mode, mode, the comments are shown inside the header. In property mode,
comments are displayed using a CSS-formatted dashed-line below the 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> </dd>
<dt id ="cfg_SQLQuery_Edit">$cfg['SQLQuery']['Edit'] boolean</dt> <dt id ="cfg_SQLQuery_Edit">$cfg['SQLQuery']['Edit'] boolean</dt>
@@ -2208,7 +2209,7 @@ setfacl -d -m "g:www-data:rwx" tmp
</dt> </dt>
<dd>Default queries that will be displayed in query boxes when user didn't <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 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> applicable to <tt>$cfg['DefaultQueryTable']</tt>.</dd>
<dt id="cfg_SQP_fmtType">$cfg['SQP']['fmtType'] string [<tt>html</tt>|<tt>none</tt>]</dt> <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> edit this.</dd>
<dt id="cfg_AttributeTypes">$cfg['AttributeTypes'] array</dt> <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> this.</dd>
<dt id="cfg_Functions">$cfg['Functions'] array</dt> <dt id="cfg_Functions">$cfg['Functions'] array</dt>
@@ -2343,21 +2344,21 @@ setfacl -d -m "g:www-data:rwx" tmp
in table.</dd> in table.</dd>
<dt id="cfg_NumOperators">$cfg['NumOperators'] array</dt> <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> </dd>
<dt id="cfg_TextOperators">$cfg['TextOperators'] array</dt> <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 Note that we put <code>LIKE</code> by default instead of
<code>LIKE %...%</code>, to avoid unintended performance problems <code>LIKE %...%</code>, to avoid unintended performance problems
in case of huge tables.</dd> in case of huge tables.</dd>
<dt id="cfg_EnumOperators">$cfg['EnumOperators'] array</dt> <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> <dt id="cfg_NullOperators">$cfg['NullOperators'] array</dt>
<dd>Additional operators available for search operations when the <dd>Additional operators available for search operations when the
field can be null.</dd> column can be null.</dd>
</dl> </dl>
@@ -2375,14 +2376,14 @@ setfacl -d -m "g:www-data:rwx" tmp
and the proper directives. Please see the <a href="#config">Configuration and the proper directives. Please see the <a href="#config">Configuration
section</a> on how to do so.</p> section</a> on how to do so.</p>
<p> You can apply different transformations to the contents of each field. The <p> You can apply different transformations to the contents of each column. The
transformation will take the content of each field and transform it with transformation will take the content of each column and transform it with
certain rules defined in the selected transformation.</p> 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 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 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 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> 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 <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 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 the end of the line. They are called 'MIME-type', 'Browser transformation' and
'Transformation options'.</p> '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 <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 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 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 <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> 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 <p> Please see the libraries/transformations/TEMPLATE file for adding your own transform
function. See the libraries/transformations/TEMPLATE_MIMETYPE for adding a mimetype function. See the libraries/transformations/TEMPLATE_MIMETYPE for adding a mimetype
without a transform function. Also note the introduction of a function description in without a transform function.</p>
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>
<p> To create a new transform function please see <p> To create a new transform function please see
<tt>libraries/transformations/template_generator.sh</tt>. <tt>libraries/transformations/template_generator.sh</tt>.
@@ -2565,15 +2562,15 @@ setfacl -d -m "g:www-data:rwx" tmp
you want to transform.</li> you want to transform.</li>
<li><b>$options</b> - Contains any user-passed options to a transform function <li><b>$options</b> - Contains any user-passed options to a transform function
as an array.</li> 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 The data is drawn from the output of the
<a href="http://www.php.net/mysql_fetch_field">mysql_fetch_field()</a> <a href="http://www.php.net/mysql_fetch_field">mysql_fetch_field()</a>
function. This means, all object properties described on the function. This means, all object properties described on the
<a href="http://www.php.net/mysql_fetch_field">manual page</a> are <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 /> to unsigned/zerofill/not_null/... properties.<br />
The $meta-&gt;mimetype variable contains the original MIME-type of the 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> </ol>
<p> Additionally you should also provide additional function to provide <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> and try to increase it.</p>
<h4 id="faq1_15"> <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> </h4>
<p> In previous MySQL versions, the <tt>User</tt> and <tt>Password</tt> fields <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 field were named <tt>user</tt> and <tt>password</tt>. Please modify your column
names to align with current standards.</p> names to align with current standards.</p>
<h4 id="faq1_16"> <h4 id="faq1_16">
@@ -2905,7 +2902,7 @@ setfacl -d -m "g:www-data:rwx" tmp
<h4 id="faq1_23"> <h4 id="faq1_23">
<a href="#faq1_23">1.23 I'm running MySQL on a Win32 machine. Each time I create <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> <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 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> available starting with MySQL&nbsp;3.23.56 / 4.0.11-gamma.</p>
<h4 id="faq1_29"> <h4 id="faq1_29">
<a href="#faq1_29">1.29 When I create a table or modify a field, I get an error <a href="#faq1_29">1.29 When I create a table or modify a column, I get an error
and the fields are duplicated.</a></h4> and the columns are duplicated.</a></h4>
<p> It is possible to configure Apache in such a way that PHP has problems <p> It is possible to configure Apache in such a way that PHP has problems
interpreting .php files.</p> interpreting .php files.</p>
@@ -3106,7 +3103,7 @@ RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
<p> <p>
Suhosin configuration might lead to malfunction in some cases and it can 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 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 what Suhosin tries to prevent. Generally all
<code>suhosin.request.*</code>, <code>suhosin.post.*</code> and <code>suhosin.request.*</code>, <code>suhosin.post.*</code> and
<code>suhosin.get.*</code> directives can have negative effect on <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> <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, <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 In Query-by-example (Query), automatic generation of the query
LEFT JOIN from the foreign table.<br /><br/> LEFT JOIN from the foreign table.<br /><br/>
</p> </p>
<h4 id="faq3_7"> <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 I get series of errors like &quot;Warning: unable to parse url&quot;. How
can this be fixed?</a></h4> can this be fixed?</a></h4>
<p> <p>
@@ -3452,7 +3449,7 @@ have either the <a href="http://pecl.php.net/package/APC">APC</a> extension
</p> </p>
<h4 id="faq3_8"> <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> a MIME-Transformation onto!</a></h4>
<p> Due to a surrounding form-container (for multi-row delete checkboxes), no <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"> <h4 id="faq5_1">
<a href="#faq5_1">5.1 I get an out of memory error, and my controls are non-functional, <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> </a></h4>
<p> <p>
We could reproduce this problem only under Win98/98SE. Testing under 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 /> <br />
A workaround is to create a smaller number of fields, then come back to A workaround is to create a smaller number of columns, then come back to
your table properties and add the other fields. your table properties and add the other columns.
</p> </p>
<h4 id="faq5_2"> <h4 id="faq5_2">
@@ -3756,7 +3753,8 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
<h4 id="faq5_6"> <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") <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> </a></h4>
<p> <p>
Your table neither have a primary key nor an unique one, so we must use a 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> </a></h4>
<p> <p>
Examine the <abbr title="structured query language">SQL</abbr> error with care. Often the problem is caused by 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: Common errors include:
</p> </p>
<ul> <ul>
@@ -3889,11 +3887,12 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
</p> </p>
<h4 id="faq6_2"> <h4 id="faq6_2">
<a href="#faq6_2">6.2 When I create a table, I set an index for two fields and <a href="#faq6_2">6.2 When I create a table, I set an index for two
phpMyAdmin generates only one index with those two fields. columns and
phpMyAdmin generates only one index with those two columns.
</a></h4> </a></h4>
<p> <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 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 table, save, then display the table properties and click the Index link to
create the other index. create the other index.
@@ -3902,11 +3901,11 @@ $cfg['Servers'][$i]['AllowDeny']['rules'] = array(
<h4 id="faq6_3"> <h4 id="faq6_3">
<a href="#faq6_3">6.3 How can I insert a null value into my table?</a></h4> <a href="#faq6_3">6.3 How can I insert a null value into my table?</a></h4>
<p> <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 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 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> </p>
<h4 id="faq6_4"> <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;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>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>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> <li>repeat the two previous steps for table &quot;REL_countries&quot;</li>
</ul> </ul>
@@ -3998,7 +3997,7 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
<li>Choose &quot;Query&quot;</li> <li>Choose &quot;Query&quot;</li>
<li>Use tables: persons, towns, countries</li> <li>Use tables: persons, towns, countries</li>
<li>Click &quot;Update query&quot;</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> &quot;Show&quot; tickbox </li>
<li>Do the same for towns.description and countries.descriptions in the <li>Do the same for towns.description and countries.descriptions in the
other 2 columns</li> other 2 columns</li>
@@ -4008,13 +4007,13 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
</ul> </ul>
<h4 id="faqdisplay"> <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> <p>
Starting from the previous example, create the pma_table_info as explained Starting from the previous example, create the pma_table_info as explained
in the configuration section, then browse your persons table, in the configuration section, then browse your persons table,
and move the mouse over a town code or country code. and move the mouse over a town code or country code.
<br /><br /> <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. enables: drop-down list of possible values.
</p> </p>
@@ -4098,8 +4097,8 @@ INSERT INTO REL_towns VALUES ('M', 'Montr&eacute;al');
different structure.</li> different structure.</li>
<li>&quot;Add AUTO_INCREMENT value&quot; ensures that AUTO_INCREMENT value <li>&quot;Add AUTO_INCREMENT value&quot; ensures that AUTO_INCREMENT value
(if any) will be included in backup.</li> (if any) will be included in backup.</li>
<li>&quot;Enclose table and field names with backquotes&quot; ensures that <li>&quot;Enclose table and column names with backquotes&quot; ensures that
field and table names formed with special characters are protected.</li> column and table names formed with special characters are protected.</li>
<li>&quot;Add into comments&quot; includes column comments, relations, and MIME <li>&quot;Add into comments&quot; includes column comments, relations, and MIME
types set in the pmadb in the dump as types set in the pmadb in the dump as
<abbr title="structured query language">SQL</abbr> comments (<i>/* xxx */</i>). <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> We utilize it as free SOAP service.</p>
<h4 id="faq6_15"> <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 it, but MySQL says &quot;BLOB column '...' used in key specification without
a key length&quot;.</a></h4> 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; 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 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"> <h4 id="faq6_16">
<a href="#faq6_16">6.16 How can I simply move in page with plenty <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> WTF is this feature then useful for?</a></h4>
<p> Slow down :). Defining mimetypes is of no use, if you can't put transformations <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, your own mimetype will cause serious syntax checking issues and validation,
this introduces a high-risk false-user-input situation. Instead you have to this introduces a high-risk false-user-input situation. Instead you have to
initialize mimetypes using functions or empty mimetype definitions.<br /> 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"> <h4 id="faq6_21">
<a href="#faq6_21">6.21 In edit/insert mode, how can I see a list of <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 <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> <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 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. foreign table, a drop-down list of values will be available.
You will see two lists of values, the first list containing the key 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 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 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 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. also contributed the French translation.
</li> </li>
<li>Alexandr Bravo &lt;abravo_at_hq.admiral.ru&gt; who contributed <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>
<li>Chris Jackson &lt;chrisj_at_ctel.net&gt; added support for MySQL <li>Chris Jackson &lt;chrisj_at_ctel.net&gt; added support for MySQL
functions in tbl_change.php3. He also added the 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); $fields_cnt = PMA_DBI_num_rows($result);
if (PMA_MYSQL_INT_VERSION < 50025) { if (PMA_MYSQL_INT_VERSION < 50025) {
@@ -171,7 +171,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) {
?> ?>
<table width="100%" class="print"> <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> <th width="80"><?php echo __('Type'); ?></th>
<?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?> <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
<th width="40"><?php echo __('Null'); ?></th> <th width="40"><?php echo __('Null'); ?></th>

View File

@@ -380,6 +380,8 @@ if (!$is_information_schema) {
<input type="text" name="comment" class="textfield" size="30" <input type="text" name="comment" class="textfield" size="30"
value="<?php value="<?php
echo htmlspecialchars(PMA_getDBComment($db)); ?>" /> echo htmlspecialchars(PMA_getDBComment($db)); ?>" />
</fieldset>
<fieldset class="tblFooters">
<input type="submit" value="<?php echo __('Go'); ?>" /> <input type="submit" value="<?php echo __('Go'); ?>" />
</fieldset> </fieldset>
</form> </form>
@@ -422,6 +424,8 @@ if (!$is_information_schema) {
echo 'INSERT INTO ... SELECT'; echo 'INSERT INTO ... SELECT';
//} //}
echo ')'; ?> 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); ?>')" /> <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> </fieldset>
</form> </form>
@@ -599,6 +603,8 @@ if (!$is_information_schema) {
. ' </legend>' . "\n" . ' </legend>' . "\n"
. PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
'db_collation', 'select_db_collation', $db_collation, false, 3) 'db_collation', 'select_db_collation', $db_collation, false, 3)
. '</fieldset>'
. '<fieldset class="tblFooters">'
. ' <input type="submit" name="submitcollation"' . ' <input type="submit" name="submitcollation"'
. ' value="' . __('Go') . '" />' . "\n" . ' value="' . __('Go') . '" />' . "\n"
. '</fieldset>' . "\n" . '</fieldset>' . "\n"
@@ -631,79 +637,15 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''; WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$test_rs = PMA_query_as_controluser($test_query, null, PMA_DBI_QUERY_STORE); $test_rs = PMA_query_as_controluser($test_query, null, PMA_DBI_QUERY_STORE);
if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?> if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
<!-- PDF schema --> include('./libraries/display_pdf_schema.lib.php');
<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
} // end if } // end if
echo '<br /><a href="pdf_pages.php?' . $url_query . '">'; echo '<fieldset><a href="pdf_pages.php?' . $url_query . '">';
if ($cfg['PropertiesIconic']) { if ($cfg['PropertiesIconic']) {
echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"' echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
.' alt="" width="16" height="16" />'; .' alt="" width="16" height="16" />';
} }
echo __('Edit PDF Pages') . '</a>'; echo __('Edit PDF Pages') . '</a></fieldset>';
} // end if } // end if
/** /**

View File

@@ -102,7 +102,7 @@ else {
<thead> <thead>
<tr> <tr>
<th><?php echo __('Table'); ?></th> <th><?php echo __('Table'); ?></th>
<th><?php echo __('Records'); ?></th> <th><?php echo __('Rows'); ?></th>
<th><?php echo __('Type'); ?></th> <th><?php echo __('Type'); ?></th>
<?php <?php
if ($cfg['ShowStats']) { if ($cfg['ShowStats']) {
@@ -219,7 +219,7 @@ else {
?> ?>
<tr> <tr>
<th align="center"> <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>
<th align="right" nowrap="nowrap"> <th align="right" nowrap="nowrap">
<?php echo PMA_formatNumber($sum_entries, 0); ?> <?php echo PMA_formatNumber($sum_entries, 0); ?>

View File

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

View File

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

View File

@@ -477,7 +477,7 @@ if ($is_show_stats) {
if ($num_tables == 0) if ($num_tables == 0)
$tableReductionCount = 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> </th>
<?php <?php

View File

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

View File

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

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,45 +20,31 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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')) { if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/'); 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 * PHPExcel
* *
* @category PHPExcel * @category PHPExcel
* @package 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 class PHPExcel
{ {
@@ -146,6 +132,16 @@ class PHPExcel
$this->addCellStyleXf(new PHPExcel_Style); $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 * Get properties
* *
@@ -212,6 +208,8 @@ class PHPExcel
* Add sheet * Add sheet
* *
* @param PHPExcel_Worksheet $pSheet * @param PHPExcel_Worksheet $pSheet
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @return PHPExcel_Worksheet
* @throws Exception * @throws Exception
*/ */
public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null)
@@ -229,7 +227,14 @@ class PHPExcel
0, 0,
array($pSheet) 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(); 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 * Get sheet names
* *
@@ -390,10 +412,11 @@ class PHPExcel
* Add external sheet * Add external sheet
* *
* @param PHPExcel_Worksheet $pSheet External sheet to add * @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 * @throws Exception
* @return PHPExcel_Worksheet * @return PHPExcel_Worksheet
*/ */
public function addExternalSheet(PHPExcel_Worksheet $pSheet) { public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null) {
if (!is_null($this->getSheetByName($pSheet->getTitle()))) { if (!is_null($this->getSheetByName($pSheet->getTitle()))) {
throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); 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); $pSheet->rebindParent($this);
// update the cellXfs // update the cellXfs
foreach ($pSheet->getCellCollection(false) as $cell) { foreach ($pSheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$cell->setXfIndex( $cell->getXfIndex() + $countCellXfs ); $cell->setXfIndex( $cell->getXfIndex() + $countCellXfs );
} }
return $this->addSheet($pSheet); return $this->addSheet($pSheet, $iSheetIndex);
} }
/** /**
@@ -433,7 +457,13 @@ class PHPExcel
* @return PHPExcel * @return PHPExcel
*/ */
public function addNamedRange(PHPExcel_NamedRange $namedRange) { 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; return true;
} }
@@ -441,57 +471,42 @@ class PHPExcel
* Get named range * Get named range
* *
* @param string $namedRange * @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) { public function getNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
$returnValue = null;
if ($namedRange != '' && !is_null($namedRange)) { if ($namedRange != '' && !is_null($namedRange)) {
if (!is_null($pSheet)) { // first look for global defined name
$key = $pSheet->getTitle().'!'.$namedRange; if (isset($this->_namedRanges[$namedRange])) {
if (isset($this->_namedRanges[$key])) { $returnValue = $this->_namedRanges[$namedRange];
return $this->_namedRanges[$key];
}
} }
$returnCount = 0;
foreach($this->_namedRanges as $_namedRange) { // then look for local defined name (has priority over global defined name if both names exist)
if ($_namedRange->getName() == $namedRange) { if (!is_null($pSheet) && isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) { $returnValue = $this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange];
return $_namedRange;
} else {
$returnCount++;
$returnValue = $_namedRange;
}
}
}
if ($returnCount == 1) {
return $returnValue;
} }
} }
return null; return $returnValue;
} }
/** /**
* Remove named range * Remove named range
* *
* @param string $namedRange * @param string $namedRange
* @param PHPExcel_Worksheet|null $pSheet. Scope. Use null for global scope.
* @return PHPExcel * @return PHPExcel
*/ */
public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) { public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
if ($namedRange != '' && !is_null($namedRange)) { if (is_null($pSheet)) {
if (!is_null($pSheet)) { if (isset($this->_namedRanges[$namedRange])) {
$key = $pSheet->getTitle().'!'.$namedRange; unset($this->_namedRanges[$namedRange]);
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
} }
foreach($this->_namedRanges as $_namedRange) { } else {
if ($_namedRange->getName() == $namedRange) { if (isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) { unset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]);
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
}
}
} }
} }
return $this; return $this;
@@ -612,7 +627,8 @@ class PHPExcel
// then update cellXf indexes for cells // then update cellXf indexes for cells
foreach ($this->_workSheetCollection as $worksheet) { foreach ($this->_workSheetCollection as $worksheet) {
foreach ($worksheet->getCellCollection(false) as $cell) { foreach ($worksheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$xfIndex = $cell->getXfIndex(); $xfIndex = $cell->getXfIndex();
if ($xfIndex > $pIndex ) { if ($xfIndex > $pIndex ) {
// decrease xf index by 1 // 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() public function garbageCollect()
{ {
@@ -711,12 +728,28 @@ class PHPExcel
} }
foreach ($this->getWorksheetIterator() as $sheet) { 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()]; ++$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; $countNeededCellXfs = 0;
foreach ($this->_cellXfCollection as $index => $cellXf) { foreach ($this->_cellXfCollection as $index => $cellXf) {
if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first 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); $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) { if (count($this->_cellXfCollection) == 0) {
$this->_cellXfCollection[] = new PHPExcel_Style(); $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 ($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()] ); $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 // also do garbage collection for all the sheets

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -19,21 +19,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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()
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()
/** 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';

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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 * @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 * @category PHPExcel
* @package PHPExcel_Calculation * @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 { class PHPExcel_Calculation_Exception extends Exception {
/** /**

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,28 +20,17 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 * @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 * PHPExcel_Calculation_ExceptionHandler
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 {
/** /**

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 * @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 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 * PHPExcel_Calculation_FormulaParser
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 { class PHPExcel_Calculation_FormulaParser {
/* Character constants */ /* Character constants */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 * @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 * @category PHPExcel
* @package PHPExcel_Calculation * @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 { class PHPExcel_Calculation_FormulaToken {
/* Token types */ /* Token types */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @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 * @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 * @category PHPExcel
* @package PHPExcel_Calculation * @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 { class PHPExcel_Calculation_Function {
/* Function categories */ /* Function categories */

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,51 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * PHPExcel_Cell
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 class PHPExcel_Cell
{ {
@@ -124,6 +91,24 @@ class PHPExcel_Cell
*/ */
private $_xfIndex; 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 * 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) 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 // Initialise cell coordinate
$this->_column = strtoupper($pColumn); $this->_column = strtoupper($pColumn);
$this->_row = $pRow; $this->_row = $pRow;
@@ -171,7 +151,7 @@ class PHPExcel_Cell
*/ */
public function getColumn() public function getColumn()
{ {
return strtoupper($this->_column); return $this->_column;
} }
/** /**
@@ -226,26 +206,48 @@ class PHPExcel_Cell
* @param mixed $pValue Value * @param mixed $pValue Value
* @param string $pDataType Explicit data type * @param string $pDataType Explicit data type
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws Exception
*/ */
public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{ {
// check strings that they are ok // set the value according to data type
// TODO: fix also for RichText switch ($pDataType) {
if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING && !($pValue instanceof PHPExcel_RichText)) { case PHPExcel_Cell_DataType::TYPE_STRING:
// string must never be longer than 32,767 characters, truncate if necessary case PHPExcel_Cell_DataType::TYPE_NULL:
$pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767); 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" case PHPExcel_Cell_DataType::TYPE_NUMERIC:
$pValue = str_replace(array("\r\n", "\r"), "\n", $pValue); $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; // set the datatype
$this->_dataType = $pDataType; $this->_dataType = $pDataType;
return $this;
$this->notifyCacheController();
return $this;
} }
/** /**
* Get caluclated cell value * Get calculated cell value
* *
* @return mixed * @return mixed
*/ */
@@ -256,9 +258,11 @@ class PHPExcel_Cell
try { try {
// echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />'; // echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />';
$result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog); $result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog);
// echo $this->getCoordinate().' calculation result is '.$result.'<br />';
} catch ( Exception $ex ) { } catch ( Exception $ex ) {
// echo 'Calculation Exception: '.$ex->getMessage().'<br />'; // echo 'Calculation Exception: '.$ex->getMessage().'<br />';
$result = '#N/A'; $result = '#N/A';
throw(new Exception($ex->getMessage()));
} }
if ((is_string($result)) && ($result == '#Not Yet Implemented')) { if ((is_string($result)) && ($result == '#Not Yet Implemented')) {
@@ -293,6 +297,8 @@ class PHPExcel_Cell
if (!is_null($pValue)) { if (!is_null($pValue)) {
$this->_calculatedValue = $pValue; $this->_calculatedValue = $pValue;
} }
$this->notifyCacheController();
return $this; return $this;
} }
@@ -325,6 +331,8 @@ class PHPExcel_Cell
public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING) public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{ {
$this->_dataType = $pDataType; $this->_dataType = $pDataType;
$this->notifyCacheController();
return $this; return $this;
} }
@@ -371,6 +379,8 @@ class PHPExcel_Cell
} }
$this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation); $this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation);
$this->notifyCacheController();
return $this; return $this;
} }
@@ -418,6 +428,8 @@ class PHPExcel_Cell
} }
$this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink); $this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink);
$this->notifyCacheController();
return $this; return $this;
} }
@@ -438,6 +450,8 @@ class PHPExcel_Cell
*/ */
public function rebindParent(PHPExcel_Worksheet $parent) { public function rebindParent(PHPExcel_Worksheet $parent) {
$this->_parent = $parent; $this->_parent = $parent;
$this->notifyCacheController();
return $this; return $this;
} }
@@ -492,22 +506,17 @@ class PHPExcel_Cell
{ {
if (strpos($pCoordinateString,':') !== false) { if (strpos($pCoordinateString,':') !== false) {
throw new Exception('Cell coordinate string can not be a range of cells.'); throw new Exception('Cell coordinate string can not be a range of cells.');
} else if ($pCoordinateString == '') { } else if ($pCoordinateString == '') {
throw new Exception('Cell coordinate can not be zero-length string.'); throw new Exception('Cell coordinate can not be zero-length string.');
} else {
// Column
$column = '';
// Row } else if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
$row = ''; list(, $column, $row) = $matches;
// Convert a cell reference
if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
list(, $column, $row) = $matches;
}
// Return array
return array($column, $row); 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) ); 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 * Column index from string
* *
@@ -615,6 +648,14 @@ class PHPExcel_Cell
*/ */
public static function columnIndexFromString($pString = 'A') 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 // Convert to uppercase
$pString = strtoupper($pString); $pString = strtoupper($pString);
@@ -745,6 +786,10 @@ class PHPExcel_Cell
* @return PHPExcel_Cell_IValueBinder * @return PHPExcel_Cell_IValueBinder
*/ */
public static function getValueBinder() { public static function getValueBinder() {
if (is_null(self::$_valueBinder)) {
self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
}
return self::$_valueBinder; return self::$_valueBinder;
} }
@@ -795,6 +840,8 @@ class PHPExcel_Cell
public function setXfIndex($pValue = 0) public function setXfIndex($pValue = 0)
{ {
$this->_xfIndex = $pValue; $this->_xfIndex = $pValue;
$this->notifyCacheController();
return $this; return $this;
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,45 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * PHPExcel_Cell_AdvancedValueBinder
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{ {
@@ -92,7 +65,7 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
return true; 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)) { if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
list($h, $m) = explode(':', $value); list($h, $m) = explode(':', $value);
$days = $h / 24 + $m / 1440; $days = $h / 24 + $m / 1440;
@@ -106,34 +79,43 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
return true; return true;
} }
// Check for date // Check for time with seconds '9:45:59', '09:45:59'
if (strtotime($value) !== false) { if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)) {
// make sure we have UTC for the sake of strtotime list($h, $m, $s) = explode(':', $value);
$saveTimeZone = date_default_timezone_get(); $days = $h / 24 + $m / 1440 + $s / 86400;
date_default_timezone_set('UTC');
// Convert value to Excel date // Convert value to number
$cell->setValueExplicit( PHPExcel_Shared_Date::PHPToExcel(strtotime($value)), PHPExcel_Cell_DataType::TYPE_NUMERIC); $cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style // Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2 ); $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 );
// restore original value for timezone
date_default_timezone_set($saveTimeZone);
return true; return true;
} }
}
// Style logic - Numbers // Check for datetime, e.g. '2008-12-31', '2008-12-31 15:59', '2008-12-31 15:59:10'
if ($dataType === PHPExcel_Cell_DataType::TYPE_NUMERIC) { if (($v = PHPExcel_Shared_Date::stringToExcel($value)) !== false) {
// Leading zeroes? // Convert value to Excel date
if (preg_match('/^\-?[0]+[0-9]*\.?[0-9]*$/', $value)) { $cell->setValueExplicit($v, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Convert value to string
$cell->setValueExplicit( $value, PHPExcel_Cell_DataType::TYPE_STRING); // 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 // Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT ); $cell->getParent()->getStyle( $cell->getCoordinate() )->getAlignment()->setWrapText(true);
return true; return true;
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * PHPExcel_Cell_DataType
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 class PHPExcel_Cell_DataType
{ {
@@ -82,4 +70,44 @@ class PHPExcel_Cell_DataType
public static function dataTypeForValue($pValue = null) { public static function dataTypeForValue($pValue = null) {
return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue); 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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * @category PHPExcel
* @package PHPExcel_Cell * @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 class PHPExcel_Cell_DataValidation
{ {
@@ -151,20 +151,12 @@ class PHPExcel_Cell_DataValidation
*/ */
private $_prompt; private $_prompt;
/**
* Parent cell
*
* @var PHPExcel_Cell
*/
private $_parent;
/** /**
* Create a new PHPExcel_Cell_DataValidation * Create a new PHPExcel_Cell_DataValidation
* *
* @param PHPExcel_Cell $pCell Parent cell
* @throws Exception * @throws Exception
*/ */
public function __construct(PHPExcel_Cell $pCell = null) public function __construct()
{ {
// Initialise member variables // Initialise member variables
$this->_formula1 = ''; $this->_formula1 = '';
@@ -180,9 +172,6 @@ class PHPExcel_Cell_DataValidation
$this->_error = ''; $this->_error = '';
$this->_promptTitle = ''; $this->_promptTitle = '';
$this->_prompt = ''; $this->_prompt = '';
// Set cell
$this->_parent = $pCell;
} }
/** /**
@@ -445,26 +434,6 @@ class PHPExcel_Cell_DataValidation
return $this; 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 * Get hash code
* *
@@ -485,7 +454,6 @@ class PHPExcel_Cell_DataValidation
. $this->_error . $this->_error
. $this->_promptTitle . $this->_promptTitle
. $this->_prompt . $this->_prompt
. $this->_parent->getCoordinate()
. __CLASS__ . __CLASS__
); );
} }
@@ -494,12 +462,9 @@ class PHPExcel_Cell_DataValidation
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone() {
// unbind parent
$this->setParent(null);
$vars = get_object_vars($this); $vars = get_object_vars($this);
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (is_object($value) && $key != '_parent') { if (is_object($value)) {
$this->$key = clone $value; $this->$key = clone $value;
} else { } else {
$this->$key = $value; $this->$key = $value;

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,39 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * PHPExcel_Cell_DefaultValueBinder
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{ {
@@ -87,22 +66,31 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
// Match the value against a few data types // Match the value against a few data types
if (is_null($pValue)) { if (is_null($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NULL; return PHPExcel_Cell_DataType::TYPE_NULL;
} elseif ($pValue === '') { } elseif ($pValue === '') {
return PHPExcel_Cell_DataType::TYPE_STRING; return PHPExcel_Cell_DataType::TYPE_STRING;
} elseif ($pValue instanceof PHPExcel_RichText) { } elseif ($pValue instanceof PHPExcel_RichText) {
return PHPExcel_Cell_DataType::TYPE_STRING; return PHPExcel_Cell_DataType::TYPE_STRING;
} elseif ($pValue{0} === '=') {
} elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
return PHPExcel_Cell_DataType::TYPE_FORMULA; return PHPExcel_Cell_DataType::TYPE_FORMULA;
} elseif (is_bool($pValue)) { } elseif (is_bool($pValue)) {
return PHPExcel_Cell_DataType::TYPE_BOOL; return PHPExcel_Cell_DataType::TYPE_BOOL;
} elseif (is_float($pValue) || is_int($pValue)) { } elseif (is_float($pValue) || is_int($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NUMERIC; 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; return PHPExcel_Cell_DataType::TYPE_NUMERIC;
} elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) { } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
return PHPExcel_Cell_DataType::TYPE_ERROR; return PHPExcel_Cell_DataType::TYPE_ERROR;
} else { } else {
return PHPExcel_Cell_DataType::TYPE_STRING; return PHPExcel_Cell_DataType::TYPE_STRING;
} }
} }
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * @category PHPExcel
* @package PHPExcel_Cell * @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 class PHPExcel_Cell_Hyperlink
{ {
/**
* Cell representing the hyperlink
*
* @var PHPExcel_Cell
*/
private $_cell;
/** /**
* URL to link the cell to * URL to link the cell to
* *
@@ -59,19 +52,15 @@ class PHPExcel_Cell_Hyperlink
/** /**
* Create a new 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 $pUrl Url to link the cell to
* @param string $pTooltip Tooltip to display on the hyperlink * @param string $pTooltip Tooltip to display on the hyperlink
* @throws Exception * @throws Exception
*/ */
public function __construct(PHPExcel_Cell $pCell = null, $pUrl = '', $pTooltip = '') public function __construct($pUrl = '', $pTooltip = '')
{ {
// Initialise member variables // Initialise member variables
$this->_url = $pUrl; $this->_url = $pUrl;
$this->_tooltip = $pTooltip; $this->_tooltip = $pTooltip;
// Set cell
$this->_parent = $pCell;
} }
/** /**
@@ -123,26 +112,6 @@ class PHPExcel_Cell_Hyperlink
return strpos($this->_url, 'sheet://') !== false; 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 * Get hash code
* *
@@ -152,7 +121,6 @@ class PHPExcel_Cell_Hyperlink
return md5( return md5(
$this->_url $this->_url
. $this->_tooltip . $this->_tooltip
. $this->_parent->getCoordinate()
. __CLASS__ . __CLASS__
); );
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 * @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 * PHPExcel_Cell_IValueBinder
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @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 interface PHPExcel_Cell_IValueBinder
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,36 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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 * PHPExcel_Comment
* *
* @category PHPExcel * @category PHPExcel
* @package 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 class PHPExcel_Comment implements PHPExcel_IComparable
{ {
@@ -290,37 +272,6 @@ class PHPExcel_Comment implements PHPExcel_IComparable
); );
} }
/**
* 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. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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 * @category PHPExcel
* @package 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 class PHPExcel_DocumentProperties
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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 * PHPExcel_DocumentSecurity
* *
* @category PHPExcel * @category PHPExcel
* @package 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 class PHPExcel_DocumentSecurity
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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 * PHPExcel_HashTable
* *
* @category PHPExcel * @category PHPExcel
* @package 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 class PHPExcel_HashTable
{ {
@@ -101,26 +89,10 @@ class PHPExcel_HashTable
* @throws Exception * @throws Exception
*/ */
public function add(PHPExcel_IComparable $pSource = null) { public function add(PHPExcel_IComparable $pSource = null) {
// Determine hashcode if (!isset($this->_items[ $pSource->getHashCode() ])) {
$hashCode = null; $this->_items[ $pSource->getHashCode() ] = $pSource;
$hashIndex = $pSource->getHashIndex(); $this->_keyMap[ count($this->_items) - 1 ] = $pSource->getHashCode();
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() );
}
} }
/** /**

View File

@@ -18,9 +18,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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 * @category PHPExcel
* @package 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 interface PHPExcel_IComparable
{ {
@@ -40,23 +40,4 @@ interface PHPExcel_IComparable
*/ */
public function getHashCode(); 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,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,43 +20,42 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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')) { if (!defined('PHPEXCEL_ROOT')) {
/** /**
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); 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 * PHPExcel_IOFactory
* *
* @category PHPExcel * @category PHPExcel
* @package 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 class PHPExcel_IOFactory
{ {
/** /**
* Search locations * Search locations
* *
* @var array * @var array
* @access private
* @static
*/ */
private static $_searchLocations = array( private static $_searchLocations = array(
array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ), array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ),
@@ -64,36 +63,45 @@ class PHPExcel_IOFactory
); );
/** /**
* Autoresolve classes * Autoresolve classes
* *
* @var array * @var array
* @access private
* @static
*/ */
private static $_autoResolveClasses = array( private static $_autoResolveClasses = array(
'Excel2007', 'Excel2007',
'Excel5', 'Excel5',
'Excel2003XML',
'OOCalc',
'SYLK',
'Serialized', 'Serialized',
'CSV' 'CSV',
); );
/** /**
* Private constructor for PHPExcel_IOFactory * Private constructor for PHPExcel_IOFactory
*/ */
private function __construct() { } private function __construct() { }
/** /**
* Get search locations * Get search locations
* *
* @return array * @static
* @access public
* @return array
*/ */
public static function getSearchLocations() { public static function getSearchLocations() {
return self::$_searchLocations; return self::$_searchLocations;
} } // function getSearchLocations()
/** /**
* Set search locations * Set search locations
* *
* @param array $value * @static
* @throws Exception * @access public
* @param array $value
* @throws Exception
*/ */
public static function setSearchLocations($value) { public static function setSearchLocations($value) {
if (is_array($value)) { if (is_array($value)) {
@@ -101,25 +109,30 @@ class PHPExcel_IOFactory
} else { } else {
throw new Exception('Invalid parameter passed.'); throw new Exception('Invalid parameter passed.');
} }
} } // function setSearchLocations()
/** /**
* Add search location * Add search location
* *
* @param string $type Example: IWriter * @static
* @param string $location Example: PHPExcel/Writer/{0}.php * @access public
* @param string $classname Example: PHPExcel_Writer_{0} * @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 = '') { public static function addSearchLocation($type = '', $location = '', $classname = '') {
self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname ); self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname );
} } // function addSearchLocation()
/** /**
* Create PHPExcel_Writer_IWriter * Create PHPExcel_Writer_IWriter
* *
* @param PHPExcel $phpExcel * @static
* @param string $writerType Example: Excel2007 * @access public
* @return PHPExcel_Writer_IWriter * @param PHPExcel $phpExcel
* @param string $writerType Example: Excel2007
* @return PHPExcel_Writer_IWriter
* @throws Exception
*/ */
public static function createWriter(PHPExcel $phpExcel, $writerType = '') { public static function createWriter(PHPExcel $phpExcel, $writerType = '') {
// Search type // Search type
@@ -131,10 +144,6 @@ class PHPExcel_IOFactory
$className = str_replace('{0}', $writerType, $searchLocation['class']); $className = str_replace('{0}', $writerType, $searchLocation['class']);
$classFile = str_replace('{0}', $writerType, $searchLocation['path']); $classFile = str_replace('{0}', $writerType, $searchLocation['path']);
if (!class_exists($className)) {
require_once PHPEXCEL_ROOT . $classFile;
}
$instance = new $className($phpExcel); $instance = new $className($phpExcel);
if (!is_null($instance)) { if (!is_null($instance)) {
return $instance; return $instance;
@@ -144,13 +153,16 @@ class PHPExcel_IOFactory
// Nothing found... // Nothing found...
throw new Exception("No $searchType found for type $writerType"); throw new Exception("No $searchType found for type $writerType");
} } // function createWriter()
/** /**
* Create PHPExcel_Reader_IReader * Create PHPExcel_Reader_IReader
* *
* @param string $readerType Example: Excel2007 * @static
* @return PHPExcel_Reader_IReader * @access public
* @param string $readerType Example: Excel2007
* @return PHPExcel_Reader_IReader
* @throws Exception
*/ */
public static function createReader($readerType = '') { public static function createReader($readerType = '') {
// Search type // Search type
@@ -162,10 +174,6 @@ class PHPExcel_IOFactory
$className = str_replace('{0}', $readerType, $searchLocation['class']); $className = str_replace('{0}', $readerType, $searchLocation['class']);
$classFile = str_replace('{0}', $readerType, $searchLocation['path']); $classFile = str_replace('{0}', $readerType, $searchLocation['path']);
if (!class_exists($className)) {
require_once PHPEXCEL_ROOT . $classFile;
}
$instance = new $className(); $instance = new $className();
if (!is_null($instance)) { if (!is_null($instance)) {
return $instance; return $instance;
@@ -175,27 +183,88 @@ class PHPExcel_IOFactory
// Nothing found... // Nothing found...
throw new Exception("No $searchType found for type $readerType"); 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 * @static
* @return PHPExcel * @access public
* @param string $pFileName
* @return PHPExcel
* @throws Exception
*/ */
public static function load($pFilename) { public static function load($pFilename) {
$reader = self::createReaderForFile($pFilename); $reader = self::createReaderForFile($pFilename);
return $reader->load($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 * @static
* @return PHPExcel_Reader_IReader * @access public
* @throws Exception * @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) { 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 // Try loading using self::$_autoResolveClasses
foreach (self::$_autoResolveClasses as $autoResolveClass) { foreach (self::$_autoResolveClasses as $autoResolveClass) {
$reader = self::createReader($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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,36 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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 * PHPExcel_NamedRange
* *
* @category PHPExcel * @category PHPExcel
* @package 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 class PHPExcel_NamedRange
{ {
@@ -81,6 +63,13 @@ class PHPExcel_NamedRange
*/ */
private $_localOnly; private $_localOnly;
/**
* Scope
*
* @var PHPExcel_Worksheet
*/
private $_scope;
/** /**
* Create a new NamedRange * Create a new NamedRange
* *
@@ -88,8 +77,9 @@ class PHPExcel_NamedRange
* @param PHPExcel_Worksheet $pWorksheet * @param PHPExcel_Worksheet $pWorksheet
* @param string $pRange * @param string $pRange
* @param bool $pLocalOnly * @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 // Validate data
if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) { if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) {
@@ -101,6 +91,8 @@ class PHPExcel_NamedRange
$this->_worksheet = $pWorksheet; $this->_worksheet = $pWorksheet;
$this->_range = $pRange; $this->_range = $pRange;
$this->_localOnly = $pLocalOnly; $this->_localOnly = $pLocalOnly;
$this->_scope = ($pLocalOnly == true) ?
(($pScope == null) ? $pWorksheet : $pScope) : null;
} }
/** /**
@@ -201,6 +193,28 @@ class PHPExcel_NamedRange
*/ */
public function setLocalOnly($value = false) { public function setLocalOnly($value = false) {
$this->_localOnly = $value; $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; return $this;
} }
@@ -208,7 +222,7 @@ class PHPExcel_NamedRange
* Resolve a named range to a regular cell range * Resolve a named range to a regular cell range
* *
* @param string $pNamedRange Named 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 * @return PHPExcel_NamedRange
*/ */
public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) { public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 * @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,84 +32,91 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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 * PHPExcel_Reader_CSV
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 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; private $_delimiter;
/** /**
* Enclosure * Enclosure
* *
* @var string * @access private
* @var string
*/ */
private $_enclosure; private $_enclosure;
/** /**
* Line ending * Line ending
* *
* @var string * @access private
* @var string
*/ */
private $_lineEnding; private $_lineEnding;
/** /**
* Sheet index to read * Sheet index to read
* *
* @var int * @access private
* @var int
*/ */
private $_sheetIndex; private $_sheetIndex;
/** /**
* PHPExcel_Reader_IReadFilter instance * PHPExcel_Reader_IReadFilter instance
* *
* @var PHPExcel_Reader_IReadFilter * @access private
* @var PHPExcel_Reader_IReadFilter
*/ */
private $_readFilter = null; private $_readFilter = null;
/** /**
* Create a new PHPExcel_Reader_CSV * Create a new PHPExcel_Reader_CSV
*/ */
public function __construct() { public function __construct() {
$this->_inputEncoding = 'UTF-8';
$this->_delimiter = ','; $this->_delimiter = ',';
$this->_enclosure = '"'; $this->_enclosure = '"';
$this->_lineEnding = PHP_EOL; $this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0; $this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); $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 * @access public
* @return boolean * @param string $pFileName
* @return boolean
* @throws Exception
*/ */
public function canRead($pFilename) public function canRead($pFilename)
{ {
@@ -118,15 +125,16 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
} }
// Check if it is a CSV file (using file name) return true;
return (substr(strtolower($pFilename), -3) == 'csv'); } // function canRead()
}
/** /**
* Loads PHPExcel from file * Loads PHPExcel from file
* *
* @param string $pFilename * @access public
* @throws Exception * @param string $pFilename
* @return PHPExcel
* @throws Exception
*/ */
public function load($pFilename) public function load($pFilename)
{ {
@@ -135,32 +143,60 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
// Load into this instance // Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel); return $this->loadIntoExisting($pFilename, $objPHPExcel);
} } // function load()
/** /**
* Read filter * Read filter
* *
* @return PHPExcel_Reader_IReadFilter * @access public
* @return PHPExcel_Reader_IReadFilter
*/ */
public function getReadFilter() { public function getReadFilter() {
return $this->_readFilter; 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) { public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue; $this->_readFilter = $pValue;
} return $this;
} // function setReadFilter()
/** /**
* Loads PHPExcel from file into PHPExcel instance * Set input encoding
* *
* @param string $pFilename * @access public
* @param PHPExcel $objPHPExcel * @param string $pValue Input encoding
* @throws Exception */
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) 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."); 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; $currentRow = 0;
$rowData = array(); $rowData = array();
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) { 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, $rowData[$i]);
$rowData[$i] = str_replace($this->_enclosure . $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 // Set cell value
$objPHPExcel->getActiveSheet()->setCellValue( $objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowData[$i]);
$columnLetter . $currentRow, $rowData[$i]
);
} }
} }
} }
@@ -207,42 +256,46 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
// Return // Return
return $objPHPExcel; return $objPHPExcel;
} } // function loadIntoExisting()
/** /**
* Get delimiter * Get delimiter
* *
* @return string * @access public
* @return string
*/ */
public function getDelimiter() { public function getDelimiter() {
return $this->_delimiter; return $this->_delimiter;
} } // function getDelimiter()
/** /**
* Set delimiter * Set delimiter
* *
* @param string $pValue Delimiter, defaults to , * @access public
* @return PHPExcel_Reader_CSV * @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_CSV
*/ */
public function setDelimiter($pValue = ',') { public function setDelimiter($pValue = ',') {
$this->_delimiter = $pValue; $this->_delimiter = $pValue;
return $this; return $this;
} } // function setDelimiter()
/** /**
* Get enclosure * Get enclosure
* *
* @return string * @access public
* @return string
*/ */
public function getEnclosure() { public function getEnclosure() {
return $this->_enclosure; return $this->_enclosure;
} } // function getEnclosure()
/** /**
* Set enclosure * Set enclosure
* *
* @param string $pValue Enclosure, defaults to " * @access public
* @return PHPExcel_Reader_CSV * @param string $pValue Enclosure, defaults to "
* @return PHPExcel_Reader_CSV
*/ */
public function setEnclosure($pValue = '"') { public function setEnclosure($pValue = '"') {
if ($pValue == '') { if ($pValue == '') {
@@ -250,45 +303,49 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
} }
$this->_enclosure = $pValue; $this->_enclosure = $pValue;
return $this; return $this;
} } // function setEnclosure()
/** /**
* Get line ending * Get line ending
* *
* @return string * @access public
* @return string
*/ */
public function getLineEnding() { public function getLineEnding() {
return $this->_lineEnding; return $this->_lineEnding;
} } // function getLineEnding()
/** /**
* Set line ending * Set line ending
* *
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL) * @access public
* @return PHPExcel_Reader_CSV * @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
* @return PHPExcel_Reader_CSV
*/ */
public function setLineEnding($pValue = PHP_EOL) { public function setLineEnding($pValue = PHP_EOL) {
$this->_lineEnding = $pValue; $this->_lineEnding = $pValue;
return $this; return $this;
} } // function setLineEnding()
/** /**
* Get sheet index * Get sheet index
* *
* @return int * @access public
* @return int
*/ */
public function getSheetIndex() { public function getSheetIndex() {
return $this->_sheetIndex; return $this->_sheetIndex;
} } // function getSheetIndex()
/** /**
* Set sheet index * Set sheet index
* *
* @param int $pValue Sheet index * @access public
* @return PHPExcel_Reader_CSV * @param int $pValue Sheet index
* @return PHPExcel_Reader_CSV
*/ */
public function setSheetIndex($pValue = 0) { public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue; $this->_sheetIndex = $pValue;
return $this; return $this;
} } // function setSheetIndex()
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 * @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 * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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 * PHPExcel_Reader_DefaultReadFilter
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
{ {

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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,49 +20,17 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader_Excel5 * @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 * @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 * PHPExcel_Reader_Excel5_Escher
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader_Excel5 * @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 class PHPExcel_Reader_Excel5_Escher
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 * @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 * @category PHPExcel
* @package PHPExcel_Reader * @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 interface PHPExcel_Reader_IReadFilter
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 * @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 * @category PHPExcel
* @package PHPExcel_Reader * @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 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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 * @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 * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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 * PHPExcel_Reader_Serialized
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @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 class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * 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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PHPExcel
* @package 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 * @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_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) * PHPExcel_ReferenceHelper (Singleton)
* *
* @category PHPExcel * @category PHPExcel
* @package 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_ReferenceHelper class PHPExcel_ReferenceHelper
{ {
@@ -86,37 +56,31 @@ class PHPExcel_ReferenceHelper
} }
/** /**
* Create a new PHPExcel_Calculation * Create a new PHPExcel_ReferenceHelper
*/ */
protected function __construct() { protected function __construct() {
} }
/** /**
* Insert a new column, updating all possible related data * Insert a new column, updating all possible related data
* *
* @param int $pBefore Insert before this one * @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert * @param int $pNumCols Number of columns to insert
* @param int $pNumRows Number of rows to insert * @param int $pNumRows Number of rows to insert
* @throws Exception * @throws Exception
*/ */
public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) { 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;
}*/
$aCellCollection = $pSheet->getCellCollection(); $aCellCollection = $pSheet->getCellCollection();
// Get coordinates of $pBefore // Get coordinates of $pBefore
$beforeColumn = 'A'; $beforeColumn = 'A';
$beforeRow = 1; $beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore ); list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
// Clear cells if we are removing columns or rows // Clear cells if we are removing columns or rows
$highestColumn = $pSheet->getHighestColumn(); $highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow(); $highestRow = $pSheet->getHighestRow();
// 1. Clear column strips if we are removing columns // 1. Clear column strips if we are removing columns
if ($pNumCols < 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols > 0) { 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 // 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 // New coordinates
$newCoordinates = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1 + $pNumCols ) . ($cell->getRow() + $pNumRows); $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. // Should the cell be updated? Move value and cellXf index from one cell to another.
if ( if (
(PHPExcel_Cell::columnIndexFromString( $cell->getColumn() ) >= PHPExcel_Cell::columnIndexFromString($beforeColumn)) && (PHPExcel_Cell::columnIndexFromString( $cell->getColumn() ) >= PHPExcel_Cell::columnIndexFromString($beforeColumn)) &&
($cell->getRow() >= $beforeRow) ($cell->getRow() >= $beforeRow)
) { ) {
// Update cell styles // Update cell styles
@@ -165,24 +131,22 @@ class PHPExcel_ReferenceHelper
// Insert this cell at its new location // Insert this cell at its new location
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) { if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted // Formula should be adjusted
$pSheet->setCellValue( $pSheet->getCell($newCoordinates)
$newCoordinates ->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows));
, $this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows)
);
} else { } else {
// Formula should not be adjusted // Formula should not be adjusted
$pSheet->setCellValue($newCoordinates, $cell->getValue()); $pSheet->getCell($newCoordinates)->setValue($cell->getValue());
} }
// Clear the original cell // Clear the original cell
$pSheet->setCellValue($cell->getCoordinate(), ''); $pSheet->getCell($cell->getCoordinate())->setValue('');
} }
} }
// Duplicate styles for the newly inserted cells // Duplicate styles for the newly inserted cells
$highestColumn = $pSheet->getHighestColumn(); $highestColumn = $pSheet->getHighestColumn();
$highestRow = $pSheet->getHighestRow(); $highestRow = $pSheet->getHighestRow();
if ($pNumCols > 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 > 0) { if ($pNumCols > 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 > 0) {
for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) { for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) {
@@ -303,14 +267,13 @@ class PHPExcel_ReferenceHelper
// Update worksheet: merge cells // Update worksheet: merge cells
$aMergeCells = array_reverse($pSheet->getMergeCells(), true); $aMergeCells = $pSheet->getMergeCells();
foreach ($aMergeCells as $key => $value) { $aNewMergeCells = array(); // the new array of all merge cells
foreach ($aMergeCells as $key => &$value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) { $aNewMergeCells[$newReference] = $newReference;
$pSheet->mergeCells( $newReference );
$pSheet->unmergeCells( $key );
}
} }
$pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array
// Update worksheet: protected cells // Update worksheet: protected cells
@@ -365,57 +328,74 @@ class PHPExcel_ReferenceHelper
// Garbage collect // Garbage collect
$pSheet->garbageCollect(); $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 // Parse formula into a tree of tokens
$tokenisedFormula = PHPExcel_Calculation::getInstance()->parseFormula($pFormula); $tokenisedFormula = PHPExcel_Calculation::getInstance()->parseFormula($pFormula);
$newCellTokens = $cellTokens = array(); $newCellTokens = $cellTokens = array();
$adjustCount = 0;
// Build the translation table of cell tokens // Build the translation table of cell tokens
foreach($tokenisedFormula as $token) { foreach($tokenisedFormula as $token) {
$token = $token['value'];
if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) { if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) {
$newCellTokens[] = $this->updateCellReference($token, $pBefore, $pNumCols, $pNumRows); list($column,$row) = PHPExcel_Cell::coordinateFromString($token);
$cellTokens[] = '/'.$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 // Update cell references in the formula
$formulaBlocks = explode('"',$pFormula); $formulaBlocks = explode('"',$pFormula);
$i = 0; foreach($formulaBlocks as $i => &$formulaBlock) {
foreach($formulaBlocks as $formulaBlockKey => $formulaBlock) {
// Only count/replace in alternate array entries // Only count/replace in alternate array entries
if (($i++ % 2) == 0) { if (($i % 2) == 0) {
$formulaBlocks[$formulaBlockKey] = preg_replace($cellTokens,$newCellTokens,$formulaBlock); $formulaBlock = preg_replace($cellTokens,$newCellTokens,$formulaBlock);
} }
} }
unset($formulaBlock);
// Then rebuild the formula string // Then rebuild the formula string
return implode('"',$formulaBlocks); return implode('"',$formulaBlocks);
} }
/** /**
* Update cell reference * Update cell reference
* *
* @param string $pCellRange Cell range * @param string $pCellRange Cell range
* @param int $pBefore Insert before this one * @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment * @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment * @param int $pNumRows Number of rows to increment
* @return string Updated cell range * @return string Updated cell range
* @throws Exception * @throws Exception
*/ */
public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
// Is it in another worksheet? Will not have to update anything. // Is it in another worksheet? Will not have to update anything.
if (strpos($pCellRange, "!") !== false) { if (strpos($pCellRange, "!") !== false) {
return $pCellRange; return $pCellRange;
@@ -423,25 +403,30 @@ class PHPExcel_ReferenceHelper
} elseif (strpos($pCellRange, ':') === false && strpos($pCellRange, ',') === false) { } elseif (strpos($pCellRange, ':') === false && strpos($pCellRange, ',') === false) {
// Single cell // Single cell
return $this->_updateSingleCellReference($pCellRange, $pBefore, $pNumCols, $pNumRows); return $this->_updateSingleCellReference($pCellRange, $pBefore, $pNumCols, $pNumRows);
} else if (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) { } elseif (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) {
// Range // Range
return $this->_updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows); return $this->_updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows);
} else { } else {
// Return original // Return original
return $pCellRange; return $pCellRange;
} }
} }
/** /**
* Update named formulas (i.e. containing worksheet references / named ranges) * Update named formulas (i.e. containing worksheet references / named ranges)
* *
* @param PHPExcel $pPhpExcel Object to update * @param PHPExcel $pPhpExcel Object to update
* @param string $oldName Old name (name to replace) * @param string $oldName Old name (name to replace)
* @param string $newName New name * @param string $newName New name
*/ */
public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') { public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') {
foreach ($pPhpExcel->getWorksheetIterator() as $sheet) { if ($oldName == '') {
foreach ($sheet->getCellCollection(false) as $cell) { 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) { if (!is_null($cell) && $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
$formula = $cell->getValue(); $formula = $cell->getValue();
if (strpos($formula, $oldName) !== false) { if (strpos($formula, $oldName) !== false) {
@@ -451,56 +436,56 @@ class PHPExcel_ReferenceHelper
} }
} }
} }
} }
} }
/** /**
* Update cell range * Update cell range
* *
* @param string $pCellRange Cell range * @param string $pCellRange Cell range
* @param int $pBefore Insert before this one * @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment * @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment * @param int $pNumRows Number of rows to increment
* @return string Updated cell range * @return string Updated cell range
* @throws Exception * @throws Exception
*/ */
private function _updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { private function _updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) { if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) {
// Update range // Update range
$range = PHPExcel_Cell::splitRange($pCellRange); $range = PHPExcel_Cell::splitRange($pCellRange);
for ($i = 0; $i < count($range); $i++) { for ($i = 0; $i < count($range); ++$i) {
for ($j = 0; $j < count($range[$i]); $j++) { for ($j = 0; $j < count($range[$i]); ++$j) {
$range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); $range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows);
} }
} }
// Recreate range string // Recreate range string
return PHPExcel_Cell::buildRange($range); return PHPExcel_Cell::buildRange($range);
} else { } else {
throw new Exception("Only cell ranges may be passed to this method."); throw new Exception("Only cell ranges may be passed to this method.");
} }
} }
/** /**
* Update single cell reference * Update single cell reference
* *
* @param string $pCellReference Single cell reference * @param string $pCellReference Single cell reference
* @param int $pBefore Insert before this one * @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment * @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment * @param int $pNumRows Number of rows to increment
* @return string Updated cell reference * @return string Updated cell reference
* @throws Exception * @throws Exception
*/ */
private function _updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { private function _updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) { if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) {
// Get coordinates of $pBefore // Get coordinates of $pBefore
$beforeColumn = 'A'; $beforeColumn = 'A';
$beforeRow = 1; $beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore ); list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
// Get coordinates // Get coordinates
$newColumn = 'A'; $newColumn = 'A';
$newRow = 1; $newRow = 1;
list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString( $pCellReference ); list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString( $pCellReference );
// Make sure the reference can be used // Make sure the reference can be used
@@ -520,20 +505,20 @@ class PHPExcel_ReferenceHelper
// Create new column reference // Create new column reference
if ($updateColumn) { 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 // Create new row reference
if ($updateRow) { if ($updateRow) {
$newRow = $newRow + $pNumRows; $newRow = $newRow + $pNumRows;
} }
// Return new reference // Return new reference
return $newColumn . $newRow; return $newColumn . $newRow;
} else { } else {
throw new Exception("Only single cell references may be passed to this method."); throw new Exception("Only single cell references may be passed to this method.");
} }
} }
/** /**
* __clone implementation. Cloning should not be allowed in a Singleton! * __clone implementation. Cloning should not be allowed in a Singleton!

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,47 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 * @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 * PHPExcel_RichText
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 class PHPExcel_RichText implements PHPExcel_IComparable
{ {
@@ -71,13 +42,6 @@ class PHPExcel_RichText implements PHPExcel_IComparable
*/ */
private $_richTextElements; private $_richTextElements;
/**
* Parent cell
*
* @var PHPExcel_Cell
*/
private $_parent;
/** /**
* Create a new PHPExcel_RichText instance * Create a new PHPExcel_RichText instance
* *
@@ -89,20 +53,17 @@ class PHPExcel_RichText implements PHPExcel_IComparable
// Initialise variables // Initialise variables
$this->_richTextElements = array(); $this->_richTextElements = array();
// Set parent? // Rich-Text string attached to cell?
if (!is_null($pCell)) { if (!is_null($pCell)) {
// Set parent cell
$this->_parent = $pCell;
// Add cell text and style // Add cell text and style
if ($this->_parent->getValue() != "") { if ($pCell->getValue() != "") {
$objRun = new PHPExcel_RichText_Run($this->_parent->getValue()); $objRun = new PHPExcel_RichText_Run($pCell->getValue());
$objRun->setFont(clone $this->_parent->getParent()->getStyle($this->_parent->getCoordinate())->getFont()); $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont());
$this->addText($objRun); $this->addText($objRun);
} }
// Set parent value // Set parent value
$this->_parent->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING); $pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
} }
} }
@@ -157,7 +118,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
// Return value // Return value
$returnValue = ''; $returnValue = '';
// Loop trough all PHPExcel_RichText_ITextElement // Loop through all PHPExcel_RichText_ITextElement
foreach ($this->_richTextElements as $text) { foreach ($this->_richTextElements as $text) {
$returnValue .= $text->getText(); $returnValue .= $text->getText();
} }
@@ -202,44 +163,6 @@ class PHPExcel_RichText implements PHPExcel_IComparable
return $this; 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 * Get hash code
* *
@@ -257,45 +180,12 @@ class PHPExcel_RichText implements PHPExcel_IComparable
); );
} }
/**
* 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. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone() {
$vars = get_object_vars($this); $vars = get_object_vars($this);
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if ($key == '_parent') continue;
if (is_object($value)) { if (is_object($value)) {
$this->$key = clone $value; $this->$key = clone $value;
} else { } else {

View File

@@ -18,30 +18,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 * @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 * PHPExcel_RichText_ITextElement
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 interface PHPExcel_RichText_ITextElement
{ {

View File

@@ -18,36 +18,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 * @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 * PHPExcel_RichText_Run
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{ {

View File

@@ -18,33 +18,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 * @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 * PHPExcel_RichText_TextElement
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @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 class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{ {

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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -21,33 +21,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * PHPExcel_Shared_Date
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 class PHPExcel_Shared_Date
{ {
@@ -106,12 +91,15 @@ class PHPExcel_Shared_Date
// Perform conversion // Perform conversion
if ($dateValue >= 1) { if ($dateValue >= 1) {
$utcDays = $dateValue - $myExcelBaseDate; $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 { } else {
$hours = round($dateValue * 24); $hours = round($dateValue * 24);
$mins = round($dateValue * 24 * 60) - round($hours * 60); $mins = round($dateValue * 24 * 60) - round($hours * 60);
$secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 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 // Return
@@ -132,8 +120,10 @@ class PHPExcel_Shared_Date
$hours = round($time / 3600); $hours = round($time / 3600);
$minutes = round($time / 60) - ($hours * 60); $minutes = round($time / 60) - ($hours * 60);
$seconds = round($time) - ($hours * 3600) - ($minutes * 60); $seconds = round($time) - ($hours * 3600) - ($minutes * 60);
$dateObj = date_create('1-Jan-1970+'.$days.' days'); $dateObj = date_create('1-Jan-1970+'.$days.' days');
$dateObj->setTime($hours,$minutes,$seconds); $dateObj->setTime($hours,$minutes,$seconds);
return $dateObj; return $dateObj;
} // function ExcelToPHPObject() } // function ExcelToPHPObject()
@@ -274,4 +264,40 @@ class PHPExcel_Shared_Date
// No date... // No date...
return false; return false;
} // function isDateTimeFormatCode() } // 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,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared * @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 class PHPExcel_Shared_Drawing
{ {
@@ -60,31 +60,65 @@ class PHPExcel_Shared_Drawing
} }
/** /**
* 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 * 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. * 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 $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 * @return int Value in cell dimension
*/ */
public static function pixelsToCellDimension($pValue = 0, $pFontSize = 11) { public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
return $pValue * $pFontSize / 11 / 7; // 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 {
// 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 cell width to pixels * Convert column width from (intrinsic) Excel units to pixels
* *
* @param int $pValue Value in cell dimension * @param float $pValue Value in cell dimension
* @param int $pFontSize Default font size of workbook * @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in pixels * @return int Value in pixels
*/ */
public static function cellDimensionToPixels($pValue = 0, $pFontSize = 11) { public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
if ($pValue != 0) { // Font name and size
return $pValue * 7 * $pFontSize / 11; $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 { } else {
return 0; // 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;
} }
/** /**
@@ -134,4 +168,105 @@ class PHPExcel_Shared_Drawing
return 0; 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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DgContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DgContainer_SpgrContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DggContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DggContainer_BstoreContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Escher * @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 class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,31 +20,17 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * PHPExcel_Shared_Excel5
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 class PHPExcel_Shared_Excel5
{ {
@@ -59,8 +45,8 @@ class PHPExcel_Shared_Excel5
*/ */
public static function sizeCol($sheet, $col = 'A') public static function sizeCol($sheet, $col = 'A')
{ {
// default font size of workbook // default font of the workbook
$fontSize = $sheet->getParent()->getDefaultStyle()->getFont()->getSize(); $font = $sheet->getParent()->getDefaultStyle()->getFont();
$columnDimensions = $sheet->getColumnDimensions(); $columnDimensions = $sheet->getColumnDimensions();
@@ -70,17 +56,19 @@ class PHPExcel_Shared_Excel5
// then we have column dimension with explicit width // then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col]; $columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth(); $width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize); $pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) { } else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width // then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension(); $defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth(); $width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize); $pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else { } 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 // now find the effective column width in pixels
@@ -104,6 +92,9 @@ class PHPExcel_Shared_Excel5
*/ */
public static function sizeRow($sheet, $row = 1) public static function sizeRow($sheet, $row = 1)
{ {
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$rowDimensions = $sheet->getRowDimensions(); $rowDimensions = $sheet->getRowDimensions();
// first find the true row height in pixels (uncollapsed and unhidden) // 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); $pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
} else { } 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 // now find the effective row height in pixels
@@ -301,8 +296,8 @@ class PHPExcel_Shared_Excel5
// Convert the pixel values to the percentage value expected by Excel // Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024; $x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256; $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 $x2 = ($width + 1) / 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 $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
$startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1); $startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1); $endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared * @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 class PHPExcel_Shared_File
{ {
@@ -79,7 +79,7 @@ class PHPExcel_Shared_File
// Found something? // Found something?
if ($returnValue == '' || is_null($returnValue)) { if ($returnValue == '' || is_null($returnValue)) {
$pathArray = split('/' , $pFilename); $pathArray = explode('/' , $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') { while(in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) { for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) { if ($pathArray[$i] == '..' && $i > 0) {
@@ -95,4 +95,42 @@ class PHPExcel_Shared_File
// Return // Return
return $returnValue; 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,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared * @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 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 */ /** Character set codes used by BIFF5-8 in Font records */
const CHARSET_ANSI_LATIN = 0x00; const CHARSET_ANSI_LATIN = 0x00;
const CHARSET_SYSTEM_DEFAULT = 0x01; const CHARSET_SYSTEM_DEFAULT = 0x01;
@@ -56,38 +60,303 @@ class PHPExcel_Shared_Font
const CHARSET_ANSI_LATIN_II = 0xEE; const CHARSET_ANSI_LATIN_II = 0xEE;
const CHARSET_OEM_LATIN_I = 0xFF; 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 * Calculate an (approximate) OpenXML column width, based on font size and text contained
* *
* @param int $fontSize Font size (in pixels or points) * @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 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 * @param int $rotation Rotation angle
* @return int Column width * @return int Column width
*/ */
public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '', $rotation = 0) { public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) {
if (!$fontSizeInPixels) {
// Translate points size to pixel size // If it is rich text, use plain text
$fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize); if ($cellText instanceof PHPExcel_RichText) {
$cellText = $cellText->getPlainText();
} }
// If it is rich text, use rich text... // Special case if there are one or more newline characters ("\n")
if ($columnText instanceof PHPExcel_RichText) { if (strpos($cellText, "\n") !== false) {
$columnText = $columnText->getPlainText(); $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 // Try to get the exact text width in pixels
if (strpos($columnText, "\r") !== false) { try {
$columnText = substr($columnText, 0, strpos($columnText, "\r")); // If autosize method is set to 'approx', use approximation
} if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) {
if (strpos($columnText, "\n") !== false) { throw new Exception('AutoSize method is set to approx');
$columnText = substr($columnText, 0, strpos($columnText, "\n")); }
// 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);
} }
// Calculate column width // Convert from pixel width to column width
// values 1.025 and 0.584 found via interpolation by inspecting real Excel files with $columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
// Calibri font. May need further adjustment
$columnWidth = 1.025 * strlen($columnText) + 0.584; // Excel adds some padding // 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 approximate rotated column width // Calculate approximate rotated column width
if ($rotation !== 0) { if ($rotation !== 0) {
@@ -101,8 +370,9 @@ class PHPExcel_Shared_Font
} }
} }
// Return // pixel width is an integer
return round($columnWidth, 6); $columnWidth = (int) $columnWidth;
return $columnWidth;
} }
/** /**
@@ -111,8 +381,8 @@ class PHPExcel_Shared_Font
* @param int $fontSizeInPoints Font size (in points) * @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels) * @return int Font size (in pixels)
*/ */
public static function fontSizeToPixels($fontSizeInPoints = 12) { public static function fontSizeToPixels($fontSizeInPoints = 11) {
return ((16 / 12) * $fontSizeInPoints); return (int) ((4 / 3) * $fontSizeInPoints);
} }
/** /**
@@ -135,6 +405,133 @@ class PHPExcel_Shared_Font
return ($sizeInCm * 37.795275591); 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. * Returns the associated charset for the font name.
* *
@@ -145,6 +542,7 @@ class PHPExcel_Shared_Font
{ {
switch ($name) { switch ($name) {
// Add more cases. Check FONT records in real Excel files. // 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': return self::CHARSET_SYMBOL;
case 'Wingdings 2': return self::CHARSET_SYMBOL; case 'Wingdings 2': return self::CHARSET_SYMBOL;
case 'Wingdings 3': 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 <?php
/** /**
* @package JAMA * @package JAMA
* *
* Cholesky decomposition class * Cholesky decomposition class
* *
* For a symmetric, positive definite matrix A, the Cholesky decomposition * For a symmetric, positive definite matrix A, the Cholesky decomposition
* is an lower triangular matrix L so that A = L*L'. * is an lower triangular matrix L so that A = L*L'.
* *
* If the matrix is not symmetric or positive definite, the constructor * If the matrix is not symmetric or positive definite, the constructor
* returns a partial decomposition and sets an internal flag that may * returns a partial decomposition and sets an internal flag that may
* be queried by the isSPD() method. * be queried by the isSPD() method.
* *
* @author Paul Meagher * @author Paul Meagher
* @author Michael Bommarito * @author Michael Bommarito
* @version 1.2 * @version 1.2
*/ */
class CholeskyDecomposition { class CholeskyDecomposition {
/**
* Decomposition storage
* @var array
* @access private
*/
var $L = array();
/** /**
* Matrix row and column dimension * Decomposition storage
* @var int * @var array
* @access private * @access private
*/ */
var $m; private $L = array();
/** /**
* Symmetric positive definite flag * Matrix row and column dimension
* @var boolean * @var int
* @access private * @access private
*/ */
var $isspd = true; private $m;
/** /**
* CholeskyDecomposition * Symmetric positive definite flag
* Class constructor - decomposes symmetric positive definite matrix * @var boolean
* @param mixed Matrix square symmetric positive definite matrix * @access private
*/ */
function CholeskyDecomposition( $A = null ) { private $isspd = true;
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 ) { * CholeskyDecomposition
$this->L[$i][$i] = sqrt( $sum ); *
} else { * Class constructor - decomposes symmetric positive definite matrix
$this->isspd = false; * @param mixed Matrix square symmetric positive definite matrix
} */
} else { public function __construct($A = null) {
if( $this->L[$i][$i] != 0 ) if ($A instanceof Matrix) {
$this->L[$j][$i] = $sum / $this->L[$i][$i]; $this->L = $A->getArray();
} $this->m = $A->getRowDimension();
}
for ($k = $i+1; $k < $this->m; $k++) for($i = 0; $i < $this->m; ++$i) {
$this->L[$i][$k] = 0.0; for($j = $i; $j < $this->m; ++$j) {
} for($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
} else { $sum -= $this->L[$i][$k] * $this->L[$j][$k];
trigger_error(ArgumentTypeException, ERROR); }
} 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) {
* Is the matrix symmetric and positive definite? $this->L[$i][$k] = 0.0;
* @return boolean }
*/ }
function isSPD () { } else {
return $this->isspd; throw new Exception(JAMAError(ArgumentTypeException));
} }
} // function __construct()
/**
* getL
* Return triangular factor.
* @return Matrix Lower triangular matrix
*/
function getL () {
return new Matrix($this->L);
}
/** /**
* Solve A*X = B * Is the matrix symmetric and positive definite?
* @param $B Row-equal matrix *
* @return Matrix L * L' * X = B * @return boolean
*/ */
function solve ( $B = null ) { public function isSPD() {
if( is_a($B, 'Matrix') ) { return $this->isspd;
if ($B->getRowDimension() == $this->m) { } // function isSPD()
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]; * getL
} *
* Return triangular factor.
* @return Matrix Lower triangular matrix
*/
public function getL() {
return new Matrix($this->L);
} // function getL()
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++) * Solve A*X = B
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i]; *
} * @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();
return new Matrix($X, $this->m, $nx); for ($k = 0; $k < $this->m; ++$k) {
} else { for ($i = $k + 1; $i < $this->m; ++$i) {
trigger_error(MatrixSPDException, ERROR); for ($j = 0; $j < $nx; ++$j) {
} $X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
} else { }
trigger_error(MatrixDimensionException, ERROR); }
} for ($j = 0; $j < $nx; ++$j) {
} else { $X[$k][$j] /= $this->L[$k][$k];
trigger_error(ArgumentTypeException, ERROR); }
} }
}
} 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 <?php
/** /**
* @package JAMA * @package JAMA
* *
* For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n * 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, * 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. * 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. * 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 * The LU decompostion with pivoting always exists, even if the matrix is
* singular, so the constructor will never fail. The primary use of the * singular, so the constructor will never fail. The primary use of the
* LU decomposition is in the solution of square systems of simultaneous * LU decomposition is in the solution of square systems of simultaneous
* linear equations. This will fail if isNonsingular() returns false. * linear equations. This will fail if isNonsingular() returns false.
* *
* @author Paul Meagher * @author Paul Meagher
* @author Bartosz Matosiuk * @author Bartosz Matosiuk
* @author Michael Bommarito * @author Michael Bommarito
* @version 1.1 * @version 1.1
* @license PHP v3.0 * @license PHP v3.0
*/ */
class LUDecomposition { class LUDecomposition {
/**
* Decomposition storage
* @var array
*/
var $LU = array();
/** /**
* Row dimension. * Decomposition storage
* @var int * @var array
*/ */
var $m; private $LU = array();
/** /**
* Column dimension. * Row dimension.
* @var int * @var int
*/ */
var $n; private $m;
/** /**
* Pivot sign. * Column dimension.
* @var int * @var int
*/ */
var $pivsign; private $n;
/** /**
* Internal storage of pivot vector. * Pivot sign.
* @var array * @var int
*/ */
var $piv = array(); private $pivsign;
/** /**
* LU Decomposition constructor. * Internal storage of pivot vector.
* @param $A Rectangular matrix * @var array
* @return Structure to access L, U and piv. */
*/ private $piv = array();
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);
}
/** /**
* Get upper triangular factor. * LU Decomposition constructor.
* @return array Upper triangular factor *
*/ * @param $A Rectangular matrix
function getU () { * @return Structure to access L, U and piv.
for ($i = 0; $i < $this->n; $i++) { */
for ($j = 0; $j < $this->n; $j++) { public function __construct($A) {
if ($i <= $j) if ($A instanceof Matrix) {
$U[$i][$j] = $this->LU[$i][$j]; // Use a "left-looking", dot-product, Crout/Doolittle algorithm.
else $this->LU = $A->getArrayCopy();
$U[$i][$j] = 0.0; $this->m = $A->getRowDimension();
} $this->n = $A->getColumnDimension();
} for ($i = 0; $i < $this->m; ++$i) {
return new Matrix($U); $this->piv[$i] = $i;
} }
$this->pivsign = 1;
$LUrowi = $LUcolj = array();
/** // Outer loop.
* Return pivot permutation vector. for ($j = 0; $j < $this->n; ++$j) {
* @return array Pivot vector // Make a copy of the j-th column to localize references.
*/ for ($i = 0; $i < $this->m; ++$i) {
function getPivot () { $LUcolj[$i] = &$this->LU[$i][$j];
return $this->piv; }
} // 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()
/**
* Alias for getPivot
* @see getPivot
*/
function getDoublePivot () {
return $this->getPivot();
}
/** /**
* Is the matrix nonsingular? * Get lower triangular factor.
* @return true if U, and hence A, is nonsingular. *
*/ * @return array Lower triangular factor
function isNonsingular () { */
for ($j = 0; $j < $this->n; $j++) { public function getL() {
if ($this->LU[$j][$j] == 0) for ($i = 0; $i < $this->m; ++$i) {
return false; for ($j = 0; $j < $this->n; ++$j) {
} if ($i > $j) {
return true; $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()
/**
* 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 * Get upper triangular factor.
* @param $B A Matrix with as many rows as A and any number of columns. *
* @return X so that L*U*X = B(piv,:) * @return array Upper triangular factor
* @exception IllegalArgumentException Matrix row dimensions must agree. */
* @exception RuntimeException Matrix is singular. public function getU() {
*/ for ($i = 0; $i < $this->n; ++$i) {
function solve($B) { for ($j = 0; $j < $this->n; ++$j) {
if ($B->getRowDimension() == $this->m) { if ($i <= $j) {
if ($this->isNonsingular()) { $U[$i][$j] = $this->LU[$i][$j];
// Copy right hand side with pivoting } else {
$nx = $B->getColumnDimension(); $U[$i][$j] = 0.0;
$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++) return new Matrix($U);
for ($j = 0; $j < $nx; $j++) } // function getU()
$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++) * Return pivot permutation vector.
$X->A[$k][$j] /= $this->LU[$k][$k]; *
for ($i = 0; $i < $k; $i++) * @return array Pivot vector
for ($j = 0; $j < $nx; $j++) */
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k]; public function getPivot() {
} return $this->piv;
return $X; } // function getPivot()
} else {
trigger_error(MatrixSingularException, ERROR);
} /**
} else { * Alias for getPivot
trigger_error(MatrixSquareException, ERROR); *
} * @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 <?php
/** /**
* @package JAMA * @package JAMA
* *
* For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n * 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 * orthogonal matrix Q and an n-by-n upper triangular matrix R so that
* A = Q*R. * A = Q*R.
* *
* The QR decompostion always exists, even if the matrix does not have * 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 * full rank, so the constructor will never fail. The primary use of the
* QR decomposition is in the least squares solution of nonsquare systems * QR decomposition is in the least squares solution of nonsquare systems
* of simultaneous linear equations. This will fail if isFullRank() * of simultaneous linear equations. This will fail if isFullRank()
* returns false. * returns false.
* *
* @author Paul Meagher * @author Paul Meagher
* @license PHP v3.0 * @license PHP v3.0
* @version 1.1 * @version 1.1
*/ */
class QRDecomposition { class QRDecomposition {
/**
* Array for internal storage of decomposition.
* @var array
*/
var $QR = array();
/** /**
* Row dimension. * Array for internal storage of decomposition.
* @var integer * @var array
*/ */
var $m; private $QR = array();
/** /**
* Column dimension. * Row dimension.
* @var integer * @var integer
*/ */
var $n; private $m;
/** /**
* Array for internal storage of diagonal of R. * Column dimension.
* @var array * @var integer
*/ */
var $Rdiag = array(); private $n;
/** /**
* QR Decomposition computed by Householder reflections. * Array for internal storage of diagonal of R.
* @param matrix $A Rectangular matrix * @var array
* @return Structure to access R and the Householder vectors and compute Q. */
*/ private $Rdiag = array();
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);
}
/**
* 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 * QR Decomposition computed by Householder reflections.
* @return Matrix Lower trapezoidal matrix whose columns define the reflections *
*/ * @param matrix $A Rectangular matrix
function getH() { * @return Structure to access R and the Householder vectors and compute Q.
for ($i = 0; $i < $this->m; $i++) { */
for ($j = 0; $j < $this->n; $j++) { public function __construct($A) {
if ($i >= $j) if($A instanceof Matrix) {
$H[$i][$j] = $this->QR[$i][$j]; // Initialize.
else $this->QR = $A->getArrayCopy();
$H[$i][$j] = 0.0; $this->m = $A->getRowDimension();
} $this->n = $A->getColumnDimension();
} // Main loop.
return new Matrix($H); 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 * Is the matrix full rank?
* @return Matrix orthogonal factor *
*/ * @return boolean true if R, and hence A, has full rank, else false.
function getQ() { */
for ($k = $this->n-1; $k >= 0; $k--) { public function isFullRank() {
for ($i = 0; $i < $this->m; $i++) for ($j = 0; $j < $this->n; ++$j) {
$Q[$i][$k] = 0.0; if ($this->Rdiag[$j] == 0) {
$Q[$k][$k] = 1.0; return false;
for ($j = $k; $j < $this->n; $j++) { }
if ($this->QR[$k][$k] != 0) { }
$s = 0.0; return true;
for ($i = $k; $i < $this->m; $i++) } // function isFullRank()
$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 the Householder vectors
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B. *
*/ * @return Matrix Lower trapezoidal matrix whose columns define the reflections
function solve($B) { */
if ($B->getRowDimension() == $this->m) { public function getH() {
if ($this->isFullRank()) { for ($i = 0; $i < $this->m; ++$i) {
// Copy right hand side for ($j = 0; $j < $this->n; ++$j) {
$nx = $B->getColumnDimension(); if ($i >= $j) {
$X = $B->getArrayCopy(); $H[$i][$j] = $this->QR[$i][$j];
// Compute Y = transpose(Q)*B } else {
for ($k = 0; $k < $this->n; $k++) { $H[$i][$j] = 0.0;
for ($j = 0; $j < $nx; $j++) { }
$s = 0.0; }
for ($i = $k; $i < $this->m; $i++) }
$s += $this->QR[$i][$k] * $X[$i][$j]; return new Matrix($H);
$s = -$s/$this->QR[$k][$k]; } // function getH()
for ($i = $k; $i < $this->m; $i++)
$X[$i][$j] += $s * $this->QR[$i][$k];
} /**
} * Return the upper triangular factor
// Solve R*X = Y; *
for ($k = $this->n-1; $k >= 0; $k--) { * @return Matrix upper triangular factor
for ($j = 0; $j < $nx; $j++) */
$X[$k][$j] /= $this->Rdiag[$k]; public function getR() {
for ($i = 0; $i < $k; $i++) for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $this->n; ++$j) {
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k]; if ($i < $j) {
} $R[$i][$j] = $this->QR[$i][$j];
$X = new Matrix($X); } elseif ($i == $j) {
return ($X->getMatrix(0, $this->n-1, 0, $nx)); $R[$i][$j] = $this->Rdiag[$i];
} else } else {
trigger_error(MatrixRankException, ERROR); $R[$i][$j] = 0.0;
} else }
trigger_error(MatrixDimensionException, ERROR); }
} }
} 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,501 +1,526 @@
<?php <?php
/** /**
* @package JAMA * @package JAMA
* *
* For an m-by-n matrix A with m >= n, the singular value decomposition is * For an m-by-n matrix A with m >= n, the singular value decomposition is
* an m-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and * an m-by-n orthogonal matrix U, an n-by-n diagonal matrix S, and
* an n-by-n orthogonal matrix V so that A = U*S*V'. * an n-by-n orthogonal matrix V so that A = U*S*V'.
* *
* The singular values, sigma[$k] = S[$k][$k], are ordered so that * The singular values, sigma[$k] = S[$k][$k], are ordered so that
* sigma[0] >= sigma[1] >= ... >= sigma[n-1]. * sigma[0] >= sigma[1] >= ... >= sigma[n-1].
* *
* The singular value decompostion always exists, so the constructor will * The singular value decompostion always exists, so the constructor will
* never fail. The matrix condition number and the effective numerical * never fail. The matrix condition number and the effective numerical
* rank can be computed from this decomposition. * rank can be computed from this decomposition.
* *
* @author Paul Meagher * @author Paul Meagher
* @license PHP v3.0 * @license PHP v3.0
* @version 1.1 * @version 1.1
*/ */
class SingularValueDecomposition { class SingularValueDecomposition {
/** /**
* Internal storage of U. * Internal storage of U.
* @var array * @var array
*/ */
var $U = array(); private $U = array();
/** /**
* Internal storage of V. * Internal storage of V.
* @var array * @var array
*/ */
var $V = array(); private $V = array();
/** /**
* Internal storage of singular values. * Internal storage of singular values.
* @var array * @var array
*/ */
var $s = array(); private $s = array();
/** /**
* Row dimension. * Row dimension.
* @var int * @var int
*/ */
var $m; private $m;
/** /**
* Column dimension. * Column dimension.
* @var int * @var int
*/ */
var $n; private $n;
/**
* Construct the singular value decomposition
*
* Derived from LINPACK code.
*
* @param $A Rectangular matrix
* @return Structure to access U, S and V.
*/
function SingularValueDecomposition ($Arg) {
// Initialize. /**
* Construct the singular value decomposition
*
* Derived from LINPACK code.
*
* @param $A Rectangular matrix
* @return Structure to access U, S and V.
*/
public function __construct($Arg) {
$A = $Arg->getArrayCopy(); // Initialize.
$this->m = $Arg->getRowDimension(); $A = $Arg->getArrayCopy();
$this->n = $Arg->getColumnDimension(); $this->m = $Arg->getRowDimension();
$nu = min($this->m, $this->n); $this->n = $Arg->getColumnDimension();
$e = array(); $nu = min($this->m, $this->n);
$work = array(); $e = array();
$wantu = true; $work = array();
$wantv = true; $wantu = true;
$nct = min($this->m - 1, $this->n); $wantv = true;
$nrt = max(0, min($this->n - 2, $this->m)); $nct = min($this->m - 1, $this->n);
$nrt = max(0, min($this->n - 2, $this->m));
// Reduce A to bidiagonal form, storing the diagonal elements // Reduce A to bidiagonal form, storing the diagonal elements
// in s and the super-diagonal elements in e. // in s and the super-diagonal elements in e.
for ($k = 0; $k < max($nct,$nrt); ++$k) {
for ($k = 0; $k < max($nct,$nrt); $k++) { if ($k < $nct) {
// Compute the transformation for the k-th column and
// place the k-th diagonal in s[$k].
// Compute 2-norm of k-th column without under/overflow.
$this->s[$k] = 0;
for ($i = $k; $i < $this->m; ++$i) {
$this->s[$k] = hypo($this->s[$k], $A[$i][$k]);
}
if ($this->s[$k] != 0.0) {
if ($A[$k][$k] < 0.0) {
$this->s[$k] = -$this->s[$k];
}
for ($i = $k; $i < $this->m; ++$i) {
$A[$i][$k] /= $this->s[$k];
}
$A[$k][$k] += 1.0;
}
$this->s[$k] = -$this->s[$k];
}
if ($k < $nct) { for ($j = $k + 1; $j < $this->n; ++$j) {
// Compute the transformation for the k-th column and if (($k < $nct) & ($this->s[$k] != 0.0)) {
// place the k-th diagonal in s[$k]. // Apply the transformation.
// Compute 2-norm of k-th column without under/overflow. $t = 0;
$this->s[$k] = 0; for ($i = $k; $i < $this->m; ++$i) {
for ($i = $k; $i < $this->m; $i++) $t += $A[$i][$k] * $A[$i][$j];
$this->s[$k] = hypo($this->s[$k], $A[$i][$k]); }
if ($this->s[$k] != 0.0) { $t = -$t / $A[$k][$k];
if ($A[$k][$k] < 0.0) for ($i = $k; $i < $this->m; ++$i) {
$this->s[$k] = -$this->s[$k]; $A[$i][$j] += $t * $A[$i][$k];
for ($i = $k; $i < $this->m; $i++) }
$A[$i][$k] /= $this->s[$k]; // Place the k-th row of A into e for the
$A[$k][$k] += 1.0; // subsequent calculation of the row transformation.
} $e[$j] = $A[$k][$j];
$this->s[$k] = -$this->s[$k]; }
} }
for ($j = $k + 1; $j < $this->n; $j++) { if ($wantu AND ($k < $nct)) {
if (($k < $nct) & ($this->s[$k] != 0.0)) { // Place the transformation in U for subsequent back
// Apply the transformation. // multiplication.
$t = 0; for ($i = $k; $i < $this->m; ++$i) {
for ($i = $k; $i < $this->m; $i++) $this->U[$i][$k] = $A[$i][$k];
$t += $A[$i][$k] * $A[$i][$j]; }
$t = -$t / $A[$k][$k]; }
for ($i = $k; $i < $this->m; $i++)
$A[$i][$j] += $t * $A[$i][$k];
// Place the k-th row of A into e for the
// subsequent calculation of the row transformation.
$e[$j] = $A[$k][$j];
}
}
if ($wantu AND ($k < $nct)) { if ($k < $nrt) {
// Place the transformation in U for subsequent back // Compute the k-th row transformation and place the
// multiplication. // k-th super-diagonal in e[$k].
for ($i = $k; $i < $this->m; $i++) // Compute 2-norm without under/overflow.
$this->U[$i][$k] = $A[$i][$k]; $e[$k] = 0;
} for ($i = $k + 1; $i < $this->n; ++$i) {
$e[$k] = hypo($e[$k], $e[$i]);
}
if ($e[$k] != 0.0) {
if ($e[$k+1] < 0.0) {
$e[$k] = -$e[$k];
}
for ($i = $k + 1; $i < $this->n; ++$i) {
$e[$i] /= $e[$k];
}
$e[$k+1] += 1.0;
}
$e[$k] = -$e[$k];
if (($k+1 < $this->m) AND ($e[$k] != 0.0)) {
// Apply the transformation.
for ($i = $k+1; $i < $this->m; ++$i) {
$work[$i] = 0.0;
}
for ($j = $k+1; $j < $this->n; ++$j) {
for ($i = $k+1; $i < $this->m; ++$i) {
$work[$i] += $e[$j] * $A[$i][$j];
}
}
for ($j = $k + 1; $j < $this->n; ++$j) {
$t = -$e[$j] / $e[$k+1];
for ($i = $k + 1; $i < $this->m; ++$i) {
$A[$i][$j] += $t * $work[$i];
}
}
}
if ($wantv) {
// Place the transformation in V for subsequent
// back multiplication.
for ($i = $k + 1; $i < $this->n; ++$i) {
$this->V[$i][$k] = $e[$i];
}
}
}
}
if ($k < $nrt) { // Set up the final bidiagonal matrix or order p.
// Compute the k-th row transformation and place the $p = min($this->n, $this->m + 1);
// k-th super-diagonal in e[$k]. if ($nct < $this->n) {
// Compute 2-norm without under/overflow. $this->s[$nct] = $A[$nct][$nct];
$e[$k] = 0; }
for ($i = $k + 1; $i < $this->n; $i++) if ($this->m < $p) {
$e[$k] = hypo($e[$k], $e[$i]); $this->s[$p-1] = 0.0;
if ($e[$k] != 0.0) { }
if ($e[$k+1] < 0.0) if ($nrt + 1 < $p) {
$e[$k] = -$e[$k]; $e[$nrt] = $A[$nrt][$p-1];
for ($i = $k + 1; $i < $this->n; $i++) }
$e[$i] /= $e[$k]; $e[$p-1] = 0.0;
$e[$k+1] += 1.0; // If required, generate U.
} if ($wantu) {
$e[$k] = -$e[$k]; for ($j = $nct; $j < $nu; ++$j) {
if (($k+1 < $this->m) AND ($e[$k] != 0.0)) { for ($i = 0; $i < $this->m; ++$i) {
// Apply the transformation. $this->U[$i][$j] = 0.0;
for ($i = $k+1; $i < $this->m; $i++) }
$work[$i] = 0.0; $this->U[$j][$j] = 1.0;
for ($j = $k+1; $j < $this->n; $j++) }
for ($i = $k+1; $i < $this->m; $i++) for ($k = $nct - 1; $k >= 0; --$k) {
$work[$i] += $e[$j] * $A[$i][$j]; if ($this->s[$k] != 0.0) {
for ($j = $k + 1; $j < $this->n; $j++) { for ($j = $k + 1; $j < $nu; ++$j) {
$t = -$e[$j] / $e[$k+1]; $t = 0;
for ($i = $k + 1; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$A[$i][$j] += $t * $work[$i]; $t += $this->U[$i][$k] * $this->U[$i][$j];
} }
} $t = -$t / $this->U[$k][$k];
if ($wantv) { for ($i = $k; $i < $this->m; ++$i) {
// Place the transformation in V for subsequent $this->U[$i][$j] += $t * $this->U[$i][$k];
// back multiplication. }
for ($i = $k + 1; $i < $this->n; $i++) }
$this->V[$i][$k] = $e[$i]; for ($i = $k; $i < $this->m; ++$i ) {
} $this->U[$i][$k] = -$this->U[$i][$k];
} }
} $this->U[$k][$k] = 1.0 + $this->U[$k][$k];
for ($i = 0; $i < $k - 1; ++$i) {
$this->U[$i][$k] = 0.0;
}
} else {
for ($i = 0; $i < $this->m; ++$i) {
$this->U[$i][$k] = 0.0;
}
$this->U[$k][$k] = 1.0;
}
}
}
// Set up the final bidiagonal matrix or order p. // If required, generate V.
$p = min($this->n, $this->m + 1); if ($wantv) {
if ($nct < $this->n) for ($k = $this->n - 1; $k >= 0; --$k) {
$this->s[$nct] = $A[$nct][$nct]; if (($k < $nrt) AND ($e[$k] != 0.0)) {
if ($this->m < $p) for ($j = $k + 1; $j < $nu; ++$j) {
$this->s[$p-1] = 0.0; $t = 0;
if ($nrt + 1 < $p) for ($i = $k + 1; $i < $this->n; ++$i) {
$e[$nrt] = $A[$nrt][$p-1]; $t += $this->V[$i][$k]* $this->V[$i][$j];
$e[$p-1] = 0.0; }
// If required, generate U. $t = -$t / $this->V[$k+1][$k];
if ($wantu) { for ($i = $k + 1; $i < $this->n; ++$i) {
for ($j = $nct; $j < $nu; $j++) { $this->V[$i][$j] += $t * $this->V[$i][$k];
for ($i = 0; $i < $this->m; $i++) }
$this->U[$i][$j] = 0.0; }
$this->U[$j][$j] = 1.0; }
} for ($i = 0; $i < $this->n; ++$i) {
for ($k = $nct - 1; $k >= 0; $k--) { $this->V[$i][$k] = 0.0;
if ($this->s[$k] != 0.0) { }
for ($j = $k + 1; $j < $nu; $j++) { $this->V[$k][$k] = 1.0;
$t = 0; }
for ($i = $k; $i < $this->m; $i++) }
$t += $this->U[$i][$k] * $this->U[$i][$j];
$t = -$t / $this->U[$k][$k];
for ($i = $k; $i < $this->m; $i++)
$this->U[$i][$j] += $t * $this->U[$i][$k];
}
for ($i = $k; $i < $this->m; $i++ )
$this->U[$i][$k] = -$this->U[$i][$k];
$this->U[$k][$k] = 1.0 + $this->U[$k][$k];
for ($i = 0; $i < $k - 1; $i++)
$this->U[$i][$k] = 0.0;
} else {
for ($i = 0; $i < $this->m; $i++)
$this->U[$i][$k] = 0.0;
$this->U[$k][$k] = 1.0;
}
}
}
// If required, generate V. // Main iteration loop for the singular values.
if ($wantv) { $pp = $p - 1;
for ($k = $this->n - 1; $k >= 0; $k--) { $iter = 0;
if (($k < $nrt) AND ($e[$k] != 0.0)) { $eps = pow(2.0, -52.0);
for ($j = $k + 1; $j < $nu; $j++) {
$t = 0;
for ($i = $k + 1; $i < $this->n; $i++)
$t += $this->V[$i][$k]* $this->V[$i][$j];
$t = -$t / $this->V[$k+1][$k];
for ($i = $k + 1; $i < $this->n; $i++)
$this->V[$i][$j] += $t * $this->V[$i][$k];
}
}
for ($i = 0; $i < $this->n; $i++)
$this->V[$i][$k] = 0.0;
$this->V[$k][$k] = 1.0;
}
}
// Main iteration loop for the singular values. while ($p > 0) {
$pp = $p - 1; // Here is where a test for too many iterations would go.
$iter = 0; // This section of the program inspects for negligible
$eps = pow(2.0, -52.0); // elements in the s and e arrays. On completion the
while ($p > 0) { // variables kase and k are set as follows:
// kase = 1 if s(p) and e[k-1] are negligible and k<p
// kase = 2 if s(k) is negligible and k<p
// kase = 3 if e[k-1] is negligible, k<p, and
// s(k), ..., s(p) are not negligible (qr step).
// kase = 4 if e(p-1) is negligible (convergence).
for ($k = $p - 2; $k >= -1; --$k) {
if ($k == -1) {
break;
}
if (abs($e[$k]) <= $eps * (abs($this->s[$k]) + abs($this->s[$k+1]))) {
$e[$k] = 0.0;
break;
}
}
if ($k == $p - 2) {
$kase = 4;
} else {
for ($ks = $p - 1; $ks >= $k; --$ks) {
if ($ks == $k) {
break;
}
$t = ($ks != $p ? abs($e[$ks]) : 0.) + ($ks != $k + 1 ? abs($e[$ks-1]) : 0.);
if (abs($this->s[$ks]) <= $eps * $t) {
$this->s[$ks] = 0.0;
break;
}
}
if ($ks == $k) {
$kase = 3;
} else if ($ks == $p-1) {
$kase = 1;
} else {
$kase = 2;
$k = $ks;
}
}
++$k;
// Here is where a test for too many iterations would go. // Perform the task indicated by kase.
// This section of the program inspects for negligible switch ($kase) {
// elements in the s and e arrays. On completion the // Deflate negligible s(p).
// variables kase and k are set as follows: case 1:
// kase = 1 if s(p) and e[k-1] are negligible and k<p $f = $e[$p-2];
// kase = 2 if s(k) is negligible and k<p $e[$p-2] = 0.0;
// kase = 3 if e[k-1] is negligible, k<p, and for ($j = $p - 2; $j >= $k; --$j) {
// s(k), ..., s(p) are not negligible (qr step). $t = hypo($this->s[$j],$f);
// kase = 4 if e(p-1) is negligible (convergence). $cs = $this->s[$j] / $t;
$sn = $f / $t;
$this->s[$j] = $t;
if ($j != $k) {
$f = -$sn * $e[$j-1];
$e[$j-1] = $cs * $e[$j-1];
}
if ($wantv) {
for ($i = 0; $i < $this->n; ++$i) {
$t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$p-1];
$this->V[$i][$p-1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$p-1];
$this->V[$i][$j] = $t;
}
}
}
break;
// Split at negligible s(k).
case 2:
$f = $e[$k-1];
$e[$k-1] = 0.0;
for ($j = $k; $j < $p; ++$j) {
$t = hypo($this->s[$j], $f);
$cs = $this->s[$j] / $t;
$sn = $f / $t;
$this->s[$j] = $t;
$f = -$sn * $e[$j];
$e[$j] = $cs * $e[$j];
if ($wantu) {
for ($i = 0; $i < $this->m; ++$i) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$k-1];
$this->U[$i][$k-1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$k-1];
$this->U[$i][$j] = $t;
}
}
}
break;
// Perform one qr step.
case 3:
// Calculate the shift.
$scale = max(max(max(max(
abs($this->s[$p-1]),abs($this->s[$p-2])),abs($e[$p-2])),
abs($this->s[$k])), abs($e[$k]));
$sp = $this->s[$p-1] / $scale;
$spm1 = $this->s[$p-2] / $scale;
$epm1 = $e[$p-2] / $scale;
$sk = $this->s[$k] / $scale;
$ek = $e[$k] / $scale;
$b = (($spm1 + $sp) * ($spm1 - $sp) + $epm1 * $epm1) / 2.0;
$c = ($sp * $epm1) * ($sp * $epm1);
$shift = 0.0;
if (($b != 0.0) || ($c != 0.0)) {
$shift = sqrt($b * $b + $c);
if ($b < 0.0) {
$shift = -$shift;
}
$shift = $c / ($b + $shift);
}
$f = ($sk + $sp) * ($sk - $sp) + $shift;
$g = $sk * $ek;
// Chase zeros.
for ($j = $k; $j < $p-1; ++$j) {
$t = hypo($f,$g);
$cs = $f/$t;
$sn = $g/$t;
if ($j != $k) {
$e[$j-1] = $t;
}
$f = $cs * $this->s[$j] + $sn * $e[$j];
$e[$j] = $cs * $e[$j] - $sn * $this->s[$j];
$g = $sn * $this->s[$j+1];
$this->s[$j+1] = $cs * $this->s[$j+1];
if ($wantv) {
for ($i = 0; $i < $this->n; ++$i) {
$t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$j+1];
$this->V[$i][$j+1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$j+1];
$this->V[$i][$j] = $t;
}
}
$t = hypo($f,$g);
$cs = $f/$t;
$sn = $g/$t;
$this->s[$j] = $t;
$f = $cs * $e[$j] + $sn * $this->s[$j+1];
$this->s[$j+1] = -$sn * $e[$j] + $cs * $this->s[$j+1];
$g = $sn * $e[$j+1];
$e[$j+1] = $cs * $e[$j+1];
if ($wantu && ($j < $this->m - 1)) {
for ($i = 0; $i < $this->m; ++$i) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$j+1];
$this->U[$i][$j+1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$j+1];
$this->U[$i][$j] = $t;
}
}
}
$e[$p-2] = $f;
$iter = $iter + 1;
break;
// Convergence.
case 4:
// Make the singular values positive.
if ($this->s[$k] <= 0.0) {
$this->s[$k] = ($this->s[$k] < 0.0 ? -$this->s[$k] : 0.0);
if ($wantv) {
for ($i = 0; $i <= $pp; ++$i) {
$this->V[$i][$k] = -$this->V[$i][$k];
}
}
}
// Order the singular values.
while ($k < $pp) {
if ($this->s[$k] >= $this->s[$k+1]) {
break;
}
$t = $this->s[$k];
$this->s[$k] = $this->s[$k+1];
$this->s[$k+1] = $t;
if ($wantv AND ($k < $this->n - 1)) {
for ($i = 0; $i < $this->n; ++$i) {
$t = $this->V[$i][$k+1];
$this->V[$i][$k+1] = $this->V[$i][$k];
$this->V[$i][$k] = $t;
}
}
if ($wantu AND ($k < $this->m-1)) {
for ($i = 0; $i < $this->m; ++$i) {
$t = $this->U[$i][$k+1];
$this->U[$i][$k+1] = $this->U[$i][$k];
$this->U[$i][$k] = $t;
}
}
++$k;
}
$iter = 0;
--$p;
break;
} // end switch
} // end while
for ($k = $p - 2; $k >= -1; $k--) { } // end constructor
if ($k == -1)
break;
if (abs($e[$k]) <= $eps * (abs($this->s[$k]) + abs($this->s[$k+1]))) {
$e[$k] = 0.0;
break;
}
}
if ($k == $p - 2)
$kase = 4;
else {
for ($ks = $p - 1; $ks >= $k; $ks--) {
if ($ks == $k)
break;
$t = ($ks != $p ? abs($e[$ks]) : 0.) + ($ks != $k + 1 ? abs($e[$ks-1]) : 0.);
if (abs($this->s[$ks]) <= $eps * $t) {
$this->s[$ks] = 0.0;
break;
}
}
if ($ks == $k)
$kase = 3;
else if ($ks == $p-1)
$kase = 1;
else {
$kase = 2;
$k = $ks;
}
}
$k++;
// Perform the task indicated by kase.
switch ($kase) {
// Deflate negligible s(p).
case 1:
$f = $e[$p-2];
$e[$p-2] = 0.0;
for ($j = $p - 2; $j >= $k; $j--) {
$t = hypo($this->s[$j],$f);
$cs = $this->s[$j] / $t;
$sn = $f / $t;
$this->s[$j] = $t;
if ($j != $k) {
$f = -$sn * $e[$j-1];
$e[$j-1] = $cs * $e[$j-1];
}
if ($wantv) {
for ($i = 0; $i < $this->n; $i++) {
$t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$p-1];
$this->V[$i][$p-1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$p-1];
$this->V[$i][$j] = $t;
}
}
}
break;
// Split at negligible s(k).
case 2:
$f = $e[$k-1];
$e[$k-1] = 0.0;
for ($j = $k; $j < $p; $j++) {
$t = hypo($this->s[$j], $f);
$cs = $this->s[$j] / $t;
$sn = $f / $t;
$this->s[$j] = $t;
$f = -$sn * $e[$j];
$e[$j] = $cs * $e[$j];
if ($wantu) {
for ($i = 0; $i < $this->m; $i++) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$k-1];
$this->U[$i][$k-1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$k-1];
$this->U[$i][$j] = $t;
}
}
}
break;
// Perform one qr step.
case 3:
// Calculate the shift.
$scale = max(max(max(max(
abs($this->s[$p-1]),abs($this->s[$p-2])),abs($e[$p-2])),
abs($this->s[$k])), abs($e[$k]));
$sp = $this->s[$p-1] / $scale;
$spm1 = $this->s[$p-2] / $scale;
$epm1 = $e[$p-2] / $scale;
$sk = $this->s[$k] / $scale;
$ek = $e[$k] / $scale;
$b = (($spm1 + $sp) * ($spm1 - $sp) + $epm1 * $epm1) / 2.0;
$c = ($sp * $epm1) * ($sp * $epm1);
$shift = 0.0;
if (($b != 0.0) || ($c != 0.0)) {
$shift = sqrt($b * $b + $c);
if ($b < 0.0)
$shift = -$shift;
$shift = $c / ($b + $shift);
}
$f = ($sk + $sp) * ($sk - $sp) + $shift;
$g = $sk * $ek;
// Chase zeros.
for ($j = $k; $j < $p-1; $j++) {
$t = hypo($f,$g);
$cs = $f/$t;
$sn = $g/$t;
if ($j != $k)
$e[$j-1] = $t;
$f = $cs * $this->s[$j] + $sn * $e[$j];
$e[$j] = $cs * $e[$j] - $sn * $this->s[$j];
$g = $sn * $this->s[$j+1];
$this->s[$j+1] = $cs * $this->s[$j+1];
if ($wantv) {
for ($i = 0; $i < $this->n; $i++) {
$t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$j+1];
$this->V[$i][$j+1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$j+1];
$this->V[$i][$j] = $t;
}
}
$t = hypo($f,$g);
$cs = $f/$t;
$sn = $g/$t;
$this->s[$j] = $t;
$f = $cs * $e[$j] + $sn * $this->s[$j+1];
$this->s[$j+1] = -$sn * $e[$j] + $cs * $this->s[$j+1];
$g = $sn * $e[$j+1];
$e[$j+1] = $cs * $e[$j+1];
if ($wantu && ($j < $this->m - 1)) {
for ($i = 0; $i < $this->m; $i++) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$j+1];
$this->U[$i][$j+1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$j+1];
$this->U[$i][$j] = $t;
}
}
}
$e[$p-2] = $f;
$iter = $iter + 1;
break;
// Convergence.
case 4:
// Make the singular values positive.
if ($this->s[$k] <= 0.0) {
$this->s[$k] = ($this->s[$k] < 0.0 ? -$this->s[$k] : 0.0);
if ($wantv) {
for ($i = 0; $i <= $pp; $i++)
$this->V[$i][$k] = -$this->V[$i][$k];
}
}
// Order the singular values.
while ($k < $pp) {
if ($this->s[$k] >= $this->s[$k+1])
break;
$t = $this->s[$k];
$this->s[$k] = $this->s[$k+1];
$this->s[$k+1] = $t;
if ($wantv AND ($k < $this->n - 1)) {
for ($i = 0; $i < $this->n; $i++) {
$t = $this->V[$i][$k+1];
$this->V[$i][$k+1] = $this->V[$i][$k];
$this->V[$i][$k] = $t;
}
}
if ($wantu AND ($k < $this->m-1)) {
for ($i = 0; $i < $this->m; $i++) {
$t = $this->U[$i][$k+1];
$this->U[$i][$k+1] = $this->U[$i][$k];
$this->U[$i][$k] = $t;
}
}
$k++;
}
$iter = 0;
$p--;
break;
} // end switch
} // end while
/* /**
echo "<p>Output A</p>"; * Return the left singular vectors
$A = new Matrix($A); *
$A->toHTML(); * @access public
* @return U
*/
public function getU() {
return new Matrix($this->U, $this->m, min($this->m + 1, $this->n));
}
echo "<p>Matrix U</p>";
echo "<pre>";
print_r($this->U);
echo "</pre>";
echo "<p>Matrix V</p>"; /**
echo "<pre>"; * Return the right singular vectors
print_r($this->V); *
echo "</pre>"; * @access public
* @return V
*/
public function getV() {
return new Matrix($this->V);
}
echo "<p>Vector S</p>";
echo "<pre>";
print_r($this->s);
echo "</pre>";
exit;
*/
} // end constructor /**
* Return the one-dimensional array of singular values
*
* @access public
* @return diagonal of S.
*/
public function getSingularValues() {
return $this->s;
}
/**
* Return the left singular vectors
* @access public
* @return U
*/
function getU() {
return new Matrix($this->U, $this->m, min($this->m + 1, $this->n));
}
/** /**
* Return the right singular vectors * Return the diagonal matrix of singular values
* @access public *
* @return V * @access public
*/ * @return S
function getV() { */
return new Matrix($this->V); public function getS() {
} for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
$S[$i][$j] = 0.0;
}
$S[$i][$i] = $this->s[$i];
}
return new Matrix($S);
}
/**
* Return the one-dimensional array of singular values
* @access public
* @return diagonal of S.
*/
function getSingularValues() {
return $this->s;
}
/** /**
* Return the diagonal matrix of singular values * Two norm
* @access public *
* @return S * @access public
*/ * @return max(S)
function getS() { */
for ($i = 0; $i < $this->n; $i++) { public function norm2() {
for ($j = 0; $j < $this->n; $j++) return $this->s[0];
$S[$i][$j] = 0.0; }
$S[$i][$i] = $this->s[$i];
}
return new Matrix($S);
}
/**
* Two norm
* @access public
* @return max(S)
*/
function norm2() {
return $this->s[0];
}
/** /**
* Two norm condition number * Two norm condition number
* @access public *
* @return max(S)/min(S) * @access public
*/ * @return max(S)/min(S)
function cond() { */
return $this->s[0] / $this->s[min($this->m, $this->n) - 1]; public function cond() {
} return $this->s[0] / $this->s[min($this->m, $this->n) - 1];
}
/**
* Effective numerical matrix rank /**
* @access public * Effective numerical matrix rank
* @return Number of nonnegligible singular values. *
*/ * @access public
function rank() { * @return Number of nonnegligible singular values.
$eps = pow(2.0, -52.0); */
$tol = max($this->m, $this->n) * $this->s[0] * $eps; public function rank() {
$r = 0; $eps = pow(2.0, -52.0);
for ($i = 0; $i < count($this->s); $i++) { $tol = max($this->m, $this->n) * $this->s[0] * $eps;
if ($this->s[$i] > $tol) $r = 0;
$r++; for ($i = 0; $i < count($this->s); ++$i) {
} if ($this->s[$i] > $tol) {
return $r; ++$r;
} }
} }
return $r;
}
} // class SingularValueDecomposition

View File

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

View File

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

View File

@@ -19,19 +19,6 @@
// //
// $Id: OLE.php,v 1.13 2007/03/07 14:38:25 schmidt Exp $ // $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 * 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 used for separating numbers into 4 bytes parts
$factor = pow(2,32); $factor = pow(2,32);
$high_part = 0; list(, $high_part) = unpack('V', substr($string, 4, 4));
for ($i = 0; $i < 4; ++$i) { list(, $low_part) = unpack('V', substr($string, 0, 4));
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;
}
}
$big_date = ($high_part * $factor) + $low_part; $big_date = ($high_part * $factor) + $low_part;
// translate to seconds // translate to seconds
$big_date /= 10000000; $big_date /= 10000000;

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (C) 2006 - 2009 PHPExcel * Copyright (C) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -22,19 +22,9 @@
* @package PHPExcel_Shared_OLE * @package PHPExcel_Shared_OLE
* @copyright Copyright (c) 2006 - 2007 Christian Schmidt * @copyright Copyright (c) 2006 - 2007 Christian Schmidt
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @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 * PHPExcel_Shared_OLE_ChainedBlockStream
* *

View File

@@ -20,16 +20,6 @@
// $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $ // $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 * Class for creating PPS's for OLE containers
* *
@@ -162,13 +152,13 @@ class PHPExcel_Shared_OLE_PPS
if (!isset($this->_data)) { if (!isset($this->_data)) {
return 0; return 0;
} }
if (isset($this->_PPS_FILE)) { //if (isset($this->_PPS_FILE)) {
fseek($this->_PPS_FILE, 0); // fseek($this->_PPS_FILE, 0);
$stats = fstat($this->_PPS_FILE); // $stats = fstat($this->_PPS_FILE);
return $stats[7]; // return $stats[7];
} else { //} else {
return strlen($this->_data); return strlen($this->_data);
} //}
} }
/** /**

View File

@@ -20,16 +20,6 @@
// $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $ // $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 * 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 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 * The constructor
* *
@@ -54,7 +38,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/ */
public function __construct($name) public function __construct($name)
{ {
$this->_tmp_dir = '';
parent::__construct( parent::__construct(
null, null,
$name, $name,
@@ -68,22 +51,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
array()); 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(). * 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() 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; return true;
} }
@@ -112,11 +70,7 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/ */
public function append($data) public function append($data)
{ {
if ($this->_PPS_FILE) { $this->_data .= $data;
fwrite($this->_PPS_FILE, $data);
} else {
$this->_data .= $data;
}
} }
/** /**

View File

@@ -20,16 +20,6 @@
// $Id: Root.php,v 1.9 2005/04/23 21:53:49 dufuz Exp $ // $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 * 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 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_1st A timestamp
* @param integer $time_2nd A timestamp * @param integer $time_2nd A timestamp
*/ */
public function __construct($time_1st, $time_2nd, $raChild) public function __construct($time_1st, $time_2nd, $raChild)
{ {
$this->_tmp_dir = '';
parent::__construct( parent::__construct(
null, null,
PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'), PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'),
@@ -65,28 +48,14 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$raChild); $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). * Method for saving the whole OLE container (including files).
* In fact, if called with an empty argument (or '-'), it saves to a * In fact, if called with an empty argument (or '-'), it saves to a
* temporary file and then outputs it's contents to stdout. * 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 * @access public
* @return mixed true on success * @return mixed true on success
*/ */
@@ -98,8 +67,9 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$this->_SMALL_BLOCK_SIZE= pow(2, $this->_SMALL_BLOCK_SIZE= pow(2,
((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6)); ((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
// Open temp file if we are sending output to stdout if (is_resource($filename)) {
if ($filename == '-' || $filename == '') { $this->_FILEH_ = $filename;
} else if ($filename == '-' || $filename == '') {
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root"); $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b"); $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) { if ($this->_FILEH_ == false) {
@@ -107,9 +77,9 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
} }
} else { } else {
$this->_FILEH_ = fopen($filename, "wb"); $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) // Make an array of PPS's (for Save)
$aList = array(); $aList = array();
@@ -128,16 +98,10 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$this->_savePps($aList); $this->_savePps($aList);
// Write Big Block Depot and BDList and Adding Header informations // Write Big Block Depot and BDList and Adding Header informations
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt); $this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
// Close File, send it to stdout if necessary
if (($filename == '-') || ($filename == '')) { if (!is_resource($filename)) {
fseek($this->_FILEH_, 0); fclose($this->_FILEH_);
fpassthru($this->_FILEH_); }
fclose($this->_FILEH_);
// Delete the temporary file.
unlink($this->_tmp_filename);
} else {
fclose($this->_FILEH_);
}
return true; return true;
} }
@@ -248,7 +212,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
. pack("V", 0) . pack("V", 0)
. pack("V", 0x1000) . pack("V", 0x1000)
. pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot . pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot
. pack("V", 1) . pack("V", $iSBDcnt)
); );
// Extra BDList Start, Count // Extra BDList Start, Count
if ($iBdCnt < $i1stBdL) { 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))) (($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data)))
{ {
// Write Data // Write Data
if (isset($raList[$i]->_PPS_FILE)) { //if (isset($raList[$i]->_PPS_FILE)) {
$iLen = 0; // $iLen = 0;
fseek($raList[$i]->_PPS_FILE, 0); // To The Top // fseek($raList[$i]->_PPS_FILE, 0); // To The Top
while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) { // while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
$iLen += strlen($sBuff); // $iLen += strlen($sBuff);
fwrite($FILE, $sBuff); // fwrite($FILE, $sBuff);
} // }
} else { //} else {
fwrite($FILE, $raList[$i]->_data); fwrite($FILE, $raList[$i]->_data);
} //}
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) { if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); ++$j) { 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)); (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
} }
// Close file for each PPS, and unlink it // Close file for each PPS, and unlink it
if (isset($raList[$i]->_PPS_FILE)) { //if (isset($raList[$i]->_PPS_FILE)) {
fclose($raList[$i]->_PPS_FILE); // fclose($raList[$i]->_PPS_FILE);
$raList[$i]->_PPS_FILE = null; // $raList[$i]->_PPS_FILE = null;
unlink($raList[$i]->_tmp_filename); // 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)); fwrite($FILE, pack("V", -2));
// Add to Data String(this will be written for RootEntry) //// Add to Data String(this will be written for RootEntry)
if ($raList[$i]->_PPS_FILE) { //if ($raList[$i]->_PPS_FILE) {
fseek($raList[$i]->_PPS_FILE, 0); // To The Top // fseek($raList[$i]->_PPS_FILE, 0); // To The Top
while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) { // while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
$sRes .= $sBuff; // $sRes .= $sBuff;
} // }
} else { //} else {
$sRes .= $raList[$i]->_data; $sRes .= $raList[$i]->_data;
} //}
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) { if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) { for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) {
$sRes .= "\x00"; $sRes .= "\x00";

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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)); 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->entry = $this->_readData($block);
$this->_readPropertySets(); $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) * Read a standard stream (by joining sectors using information from SAT)
* *
@@ -271,7 +322,7 @@ class PHPExcel_Shared_OLERead {
'size' => $size); 'size' => $size);
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook) // 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; $this->wrkbook = count($this->props) - 1;
} }
@@ -280,6 +331,11 @@ class PHPExcel_Shared_OLERead {
$this->rootentry = count($this->props) - 1; $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; $offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared * @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 class PHPExcel_Shared_PasswordHasher
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared * @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 class PHPExcel_Shared_String
{ {
/** Constants */
/** Regular Expressions */
// Fraction
const STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)';
/** /**
* Control characters array * Control characters array
* *
@@ -42,6 +48,27 @@ class PHPExcel_Shared_String
*/ */
private static $_controlCharacters = array(); 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? * Is mbstring extension avalable?
* *
@@ -60,7 +87,7 @@ class PHPExcel_Shared_String
* Build control characters array * Build control characters array
*/ */
private static function _buildControlCharacters() { private static function _buildControlCharacters() {
for ($i = 0; $i <= 19; ++$i) { for ($i = 0; $i <= 31; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) { if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_'; $find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
$replace = chr($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 * Get whether mbstring extension is available
* *
@@ -97,14 +289,37 @@ class PHPExcel_Shared_String
return self::$_isIconvEnabled; return self::$_isIconvEnabled;
} }
// IBM AIX iconv() does not work // Fail if iconv doesn't exist
self::$_isIconvEnabled = function_exists('iconv') && if (!function_exists('iconv')) {
!(defined('PHP_OS') && @stristr(PHP_OS, 'AIX') && defined('ICONV_IMPL') self::$_isIconvEnabled = false;
&& (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && defined('ICONV_VERSION') return false;
&& (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) ? }
true : 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;
} }
/** /**
@@ -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 $value
* @param string $to Encoding to convert to, e.g. 'UTF-8' * @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); $value = mb_convert_encoding($value, $to, $from);
return $value; 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 // else, no conversion
return $value; 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 * Get character count. First try mbstring, then iconv, finally strlen
* *
@@ -322,4 +572,106 @@ class PHPExcel_Shared_String
return $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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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')) { if (!defined('DATE_W3C')) {
@@ -34,7 +34,7 @@ if (!defined('DATE_W3C')) {
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 { class PHPExcel_Shared_XMLWriter {
/** Temporary storage method */ /** Temporary storage method */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,22 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 * @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 * PHPExcel_Shared_ZipStreamWrapper
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @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 { 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.'); throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
} }
// Parse URL $pos = strrpos($path, '#');
$url = @parse_url($path); $url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
$url['fragment'] = substr($path, $pos + 1);
// 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']);
}
// Open archive // Open archive
$this->_archive = new ZipArchive(); $this->_archive = new ZipArchive();

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 * @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 * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 class PHPExcel_Best_Fit
{ {
@@ -239,7 +239,11 @@ class PHPExcel_Best_Fit
$this->_SSResiduals = $SSres; $this->_SSResiduals = $SSres;
$this->_DFResiduals = $this->_valueCount - 1 - $const; $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)) { if (($SStot == 0.0) || ($SSres == $SStot)) {
$this->_goodnessOfFit = 1; $this->_goodnessOfFit = 1;
} else { } else {
@@ -252,9 +256,17 @@ class PHPExcel_Best_Fit
$this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex); $this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
$this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2)); $this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2));
if ($this->_SSResiduals != 0.0) { 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 { } 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() } // function _calculateGoodnessOfFit()

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 * @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/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 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) { private function _exponential_regression($yValues, $xValues, $const) {
$mArray = $xValues; foreach($yValues as &$value) {
$yValues = array_map('log',$yValues); if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const); $this->_leastSquareFit($yValues, $xValues, $const);
} // function _exponential_regression() } // function _exponential_regression()

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 * @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/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 * @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/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 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) { private function _logarithmic_regression($yValues, $xValues, $const) {
$mArray = $xValues; foreach($xValues as &$value) {
$xValues = array_map('log',$xValues); if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const); $this->_leastSquareFit($yValues, $xValues, $const);
} // function _logarithmic_regression() } // function _logarithmic_regression()

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 * @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/trend/bestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.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 * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 * @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/trend/bestFitClass.php';
@@ -42,7 +34,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @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 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) { private function _power_regression($yValues, $xValues, $const) {
$mArray = $xValues; foreach($xValues as &$value) {
sort($mArray,SORT_NUMERIC); if ($value < 0.0) {
$xValues = array_map('log',$xValues); $value = 0 - log(abs($value));
$yValues = array_map('log',$yValues); } 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); $this->_leastSquareFit($yValues, $xValues, $const);
} // function _power_regression() } // function _power_regression()

View File

@@ -1,13 +1,5 @@
<?php <?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/linearBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.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