将文件添加并导入到SVN库中
+YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@33 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
@@ -0,0 +1,504 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?PHP
|
||||
require_once "Excel/class.writeexcel_workbook.inc.php";
|
||||
require_once "Excel/class.writeexcel_worksheet.inc.php";
|
||||
require_once "Excel/functions.writeexcel_utility.inc.php";
|
||||
|
||||
class Excel_Workbook extends writeexcel_workbook {
|
||||
/**
|
||||
* The constructor. It just creates a Workbook
|
||||
*
|
||||
* @param string $filename The optional filename for the Workbook.
|
||||
* @return Spreadsheet_Excel_Writer_Workbook The Workbook created
|
||||
*/
|
||||
|
||||
function Excel_Workbook($filename = '') {
|
||||
$this->_filename = $filename;
|
||||
$this->writeexcel_workbook($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send HTTP headers for the Excel file.
|
||||
*
|
||||
* @param string $filename The filename to use for HTTP headers
|
||||
* @access public
|
||||
*/
|
||||
function send($filename) { // attachment
|
||||
global $pref_lang;
|
||||
$this->_tmpfilename = $filename;
|
||||
/* if ($pref_lang == "ru") {
|
||||
header ('<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">');
|
||||
} else {
|
||||
header ('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
|
||||
}
|
||||
*/ header("Content-type: application/x-msexcel");
|
||||
header("Content-Disposition: inline; filename=$filename");
|
||||
header("Expires: 0");
|
||||
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
|
||||
header("Pragma: public");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
class writeexcel_biffwriter {
|
||||
var $byte_order;
|
||||
var $BIFF_version;
|
||||
var $_byte_order;
|
||||
var $_data;
|
||||
var $_datasize;
|
||||
var $_limit;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
function writeexcel_biffwriter() {
|
||||
|
||||
$this->byte_order = '';
|
||||
$this->BIFF_version = 0x0500;
|
||||
$this->_byte_order = '';
|
||||
$this->_data = false;
|
||||
$this->_datasize = 0;
|
||||
$this->_limit = 2080;
|
||||
|
||||
$this->_set_byte_order();
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the byte order and store it as class data to avoid
|
||||
* recalculating it for each call to new().
|
||||
*/
|
||||
function _set_byte_order() {
|
||||
$this->byteorder=0;
|
||||
// Check if "pack" gives the required IEEE 64bit float
|
||||
$teststr = pack("d", 1.2345);
|
||||
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
|
||||
|
||||
if ($number == $teststr) {
|
||||
$this->byte_order = 0; // Little Endian
|
||||
} elseif ($number == strrev($teststr)) {
|
||||
$this->byte_order = 1; // Big Endian
|
||||
} else {
|
||||
// Give up
|
||||
trigger_error("Required floating point format not supported ".
|
||||
"on this platform. See the portability section ".
|
||||
"of the documentation.", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$this->_byte_order = $this->byte_order;
|
||||
}
|
||||
|
||||
/*
|
||||
* General storage function
|
||||
*/
|
||||
function _prepend($data) {
|
||||
|
||||
if (func_num_args()>1) {
|
||||
trigger_error("writeexcel_biffwriter::_prepend() ".
|
||||
"called with more than one argument", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if ($this->_debug) {
|
||||
print "*** writeexcel_biffwriter::_prepend() called:";
|
||||
for ($c=0;$c<strlen($data);$c++) {
|
||||
if ($c%16==0) {
|
||||
print "\n";
|
||||
}
|
||||
printf("%02X ", ord($data[$c]));
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if (strlen($data) > $this->_limit) {
|
||||
$data = $this->_add_continue($data);
|
||||
}
|
||||
|
||||
$this->_data = $data . $this->_data;
|
||||
$this->_datasize += strlen($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* General storage function
|
||||
*/
|
||||
function _append($data) {
|
||||
|
||||
if (func_num_args()>1) {
|
||||
trigger_error("writeexcel_biffwriter::_append() ".
|
||||
"called with more than one argument", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if ($this->_debug) {
|
||||
print "*** writeexcel_biffwriter::_append() called:";
|
||||
for ($c=0;$c<strlen($data);$c++) {
|
||||
if ($c%16==0) {
|
||||
print "\n";
|
||||
}
|
||||
printf("%02X ", ord($data[$c]));
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if (strlen($data) > $this->_limit) {
|
||||
$data = $this->_add_continue($data);
|
||||
}
|
||||
|
||||
$this->_data = $this->_data . $data;
|
||||
$this->_datasize += strlen($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes Excel BOF record to indicate the beginning of a stream or
|
||||
* sub-stream in the BIFF file.
|
||||
*
|
||||
* $type = 0x0005, Workbook
|
||||
* $type = 0x0010, Worksheet
|
||||
*/
|
||||
function _store_bof($type) {
|
||||
|
||||
$record = 0x0809; // Record identifier
|
||||
$length = 0x0008; // Number of bytes to follow
|
||||
|
||||
$version = $this->BIFF_version;
|
||||
|
||||
// According to the SDK $build and $year should be set to zero.
|
||||
// However, this throws a warning in Excel 5. So, use these
|
||||
// magic numbers.
|
||||
$build = 0x096C;
|
||||
$year = 0x07C9;
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvv", $version, $type, $build, $year);
|
||||
|
||||
$this->_prepend($header . $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes Excel EOF record to indicate the end of a BIFF stream.
|
||||
*/
|
||||
function _store_eof() {
|
||||
|
||||
$record = 0x000A; // Record identifier
|
||||
$length = 0x0000; // Number of bytes to follow
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
|
||||
$this->_append($header);
|
||||
}
|
||||
|
||||
/*
|
||||
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084
|
||||
* bytes. In Excel 97 the limit is 8228 bytes. Records that are longer
|
||||
* than these limits must be split up into CONTINUE blocks.
|
||||
*
|
||||
* This function take a long BIFF record and inserts CONTINUE records as
|
||||
* necessary.
|
||||
*/
|
||||
function _add_continue($data) {
|
||||
|
||||
$limit = $this->_limit;
|
||||
$record = 0x003C; // Record identifier
|
||||
|
||||
// The first 2080/8224 bytes remain intact. However, we have to change
|
||||
// the length field of the record.
|
||||
$tmp = substr($data, 0, $limit);
|
||||
$data = substr($data, $limit);
|
||||
$tmp = substr($tmp, 0, 2) . pack ("v", $limit-4) . substr($tmp, 4);
|
||||
|
||||
// Strip out chunks of 2080/8224 bytes +4 for the header.
|
||||
while (strlen($data) > $limit) {
|
||||
$header = pack("vv", $record, $limit);
|
||||
$tmp .= $header;
|
||||
$tmp .= substr($data, 0, $limit);
|
||||
$data = substr($data, $limit);
|
||||
}
|
||||
|
||||
// Mop up the last of the data
|
||||
$header = pack("vv", $record, strlen($data));
|
||||
$tmp .= $header;
|
||||
$tmp .= $data;
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,694 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
class writeexcel_format {
|
||||
|
||||
var $_xf_index;
|
||||
var $_font_index;
|
||||
var $_font;
|
||||
var $_size;
|
||||
var $_bold;
|
||||
var $_italic;
|
||||
var $_color;
|
||||
var $_underline;
|
||||
var $_font_strikeout;
|
||||
var $_font_outline;
|
||||
var $_font_shadow;
|
||||
var $_font_script;
|
||||
var $_font_family;
|
||||
var $_font_charset;
|
||||
var $_num_format;
|
||||
var $_hidden;
|
||||
var $_locked;
|
||||
var $_text_h_align;
|
||||
var $_text_wrap;
|
||||
var $_text_v_align;
|
||||
var $_text_justlast;
|
||||
var $_rotation;
|
||||
var $_fg_color;
|
||||
var $_bg_color;
|
||||
var $_pattern;
|
||||
var $_bottom;
|
||||
var $_top;
|
||||
var $_left;
|
||||
var $_right;
|
||||
var $_bottom_color;
|
||||
var $_top_color;
|
||||
var $_left_color;
|
||||
var $_right_color;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
function writeexcel_format() {
|
||||
$_=func_get_args();
|
||||
|
||||
$this->_xf_index = (sizeof($_)>0) ? array_shift($_) : 0;
|
||||
|
||||
$this->_font_index = 0;
|
||||
$this->_font = 'Arial';
|
||||
$this->_size = 10;
|
||||
$this->_bold = 0x0190;
|
||||
$this->_italic = 0;
|
||||
$this->_color = 0x7FFF;
|
||||
$this->_underline = 0;
|
||||
$this->_font_strikeout = 0;
|
||||
$this->_font_outline = 0;
|
||||
$this->_font_shadow = 0;
|
||||
$this->_font_script = 0;
|
||||
$this->_font_family = 0;
|
||||
$this->_font_charset = 0;
|
||||
|
||||
$this->_num_format = 0;
|
||||
|
||||
$this->_hidden = 0;
|
||||
$this->_locked = 1;
|
||||
|
||||
$this->_text_h_align = 0;
|
||||
$this->_text_wrap = 0;
|
||||
$this->_text_v_align = 2;
|
||||
$this->_text_justlast = 0;
|
||||
$this->_rotation = 0;
|
||||
|
||||
$this->_fg_color = 0x40;
|
||||
$this->_bg_color = 0x41;
|
||||
|
||||
$this->_pattern = 0;
|
||||
|
||||
$this->_bottom = 0;
|
||||
$this->_top = 0;
|
||||
$this->_left = 0;
|
||||
$this->_right = 0;
|
||||
|
||||
$this->_bottom_color = 0x40;
|
||||
$this->_top_color = 0x40;
|
||||
$this->_left_color = 0x40;
|
||||
$this->_right_color = 0x40;
|
||||
|
||||
// Set properties passed to writeexcel_workbook::addformat()
|
||||
if (sizeof($_)>0) {
|
||||
call_user_method_array('set_properties', $this, $_);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the attributes of another writeexcel_format object.
|
||||
*/
|
||||
function copy($other) {
|
||||
$xf = $this->_xf_index; // Backup XF index
|
||||
//Changes done for supporting PHP5 compatibility
|
||||
$this[] = clone($other); // Copy properties
|
||||
$this->_xf_index = $xf; // Restore XF index
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate an Excel BIFF XF record.
|
||||
*/
|
||||
function get_xf() {
|
||||
|
||||
$_=func_get_args();
|
||||
|
||||
// $record Record identifier
|
||||
// $length Number of bytes to follow
|
||||
|
||||
// $ifnt Index to FONT record
|
||||
// $ifmt Index to FORMAT record
|
||||
// $style Style and other options
|
||||
// $align Alignment
|
||||
// $icv fg and bg pattern colors
|
||||
// $fill Fill and border line style
|
||||
// $border1 Border line style and color
|
||||
// $border2 Border color
|
||||
|
||||
// Set the type of the XF record and some of the attributes.
|
||||
if ($_[0] == "style") {
|
||||
$style = 0xFFF5;
|
||||
} else {
|
||||
$style = $this->_locked;
|
||||
$style |= $this->_hidden << 1;
|
||||
}
|
||||
|
||||
// Flags to indicate if attributes have been set.
|
||||
$atr_num = ($this->_num_format != 0) ? 1 : 0;
|
||||
$atr_fnt = ($this->_font_index != 0) ? 1 : 0;
|
||||
$atr_alc = $this->_text_wrap ? 1 : 0;
|
||||
$atr_bdr = ($this->_bottom ||
|
||||
$this->_top ||
|
||||
$this->_left ||
|
||||
$this->_right) ? 1 : 0;
|
||||
$atr_pat = ($this->_fg_color != 0x41 ||
|
||||
$this->_bg_color != 0x41 ||
|
||||
$this->_pattern != 0x00) ? 1 : 0;
|
||||
$atr_prot = 0;
|
||||
|
||||
// Reset the default colors for the non-font properties
|
||||
if ($this->_fg_color == 0x7FFF) $this->_fg_color = 0x40;
|
||||
if ($this->_bg_color == 0x7FFF) $this->_bg_color = 0x41;
|
||||
if ($this->_bottom_color == 0x7FFF) $this->_bottom_color = 0x41;
|
||||
if ($this->_top_color == 0x7FFF) $this->_top_color = 0x41;
|
||||
if ($this->_left_color == 0x7FFF) $this->_left_color = 0x41;
|
||||
if ($this->_right_color == 0x7FFF) $this->_right_color = 0x41;
|
||||
|
||||
// Zero the default border colour if the border has not been set.
|
||||
if ($this->_bottom == 0) {
|
||||
$this->_bottom_color = 0;
|
||||
}
|
||||
if ($this->_top == 0) {
|
||||
$this->_top_color = 0;
|
||||
}
|
||||
if ($this->_right == 0) {
|
||||
$this->_right_color = 0;
|
||||
}
|
||||
if ($this->_left == 0) {
|
||||
$this->_left_color = 0;
|
||||
}
|
||||
|
||||
// The following 2 logical statements take care of special cases in
|
||||
// relation to cell colors and patterns:
|
||||
// 1. For a solid fill (_pattern == 1) Excel reverses the role of
|
||||
// foreground and background colors
|
||||
// 2. If the user specifies a foreground or background color
|
||||
// without a pattern they probably wanted a solid fill, so we
|
||||
// fill in the defaults.
|
||||
if ($this->_pattern <= 0x01 &&
|
||||
$this->_bg_color != 0x41 &&
|
||||
$this->_fg_color == 0x40 )
|
||||
{
|
||||
$this->_fg_color = $this->_bg_color;
|
||||
$this->_bg_color = 0x40;
|
||||
$this->_pattern = 1;
|
||||
}
|
||||
|
||||
if ($this->_pattern <= 0x01 &&
|
||||
$this->_bg_color == 0x41 &&
|
||||
$this->_fg_color != 0x40 )
|
||||
{
|
||||
$this->_bg_color = 0x40;
|
||||
$this->_pattern = 1;
|
||||
}
|
||||
|
||||
$record = 0x00E0;
|
||||
$length = 0x0010;
|
||||
|
||||
$ifnt = $this->_font_index;
|
||||
$ifmt = $this->_num_format;
|
||||
|
||||
$align = $this->_text_h_align;
|
||||
$align |= $this->_text_wrap << 3;
|
||||
$align |= $this->_text_v_align << 4;
|
||||
$align |= $this->_text_justlast << 7;
|
||||
$align |= $this->_rotation << 8;
|
||||
$align |= $atr_num << 10;
|
||||
$align |= $atr_fnt << 11;
|
||||
$align |= $atr_alc << 12;
|
||||
$align |= $atr_bdr << 13;
|
||||
$align |= $atr_pat << 14;
|
||||
$align |= $atr_prot << 15;
|
||||
|
||||
$icv = $this->_fg_color;
|
||||
$icv |= $this->_bg_color << 7;
|
||||
|
||||
$fill = $this->_pattern;
|
||||
$fill |= $this->_bottom << 6;
|
||||
$fill |= $this->_bottom_color << 9;
|
||||
|
||||
$border1 = $this->_top;
|
||||
$border1 |= $this->_left << 3;
|
||||
$border1 |= $this->_right << 6;
|
||||
$border1 |= $this->_top_color << 9;
|
||||
|
||||
$border2 = $this->_left_color;
|
||||
$border2 |= $this->_right_color << 7;
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvvvvvv", $ifnt, $ifmt, $style, $align,
|
||||
$icv, $fill,
|
||||
$border1, $border2);
|
||||
|
||||
return($header . $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate an Excel BIFF FONT record.
|
||||
*/
|
||||
function get_font() {
|
||||
|
||||
// $record Record identifier
|
||||
// $length Record length
|
||||
|
||||
// $dyHeight Height of font (1/20 of a point)
|
||||
// $grbit Font attributes
|
||||
// $icv Index to color palette
|
||||
// $bls Bold style
|
||||
// $sss Superscript/subscript
|
||||
// $uls Underline
|
||||
// $bFamily Font family
|
||||
// $bCharSet Character set
|
||||
// $reserved Reserved
|
||||
// $cch Length of font name
|
||||
// $rgch Font name
|
||||
|
||||
$dyHeight = $this->_size * 20;
|
||||
$icv = $this->_color;
|
||||
$bls = $this->_bold;
|
||||
$sss = $this->_font_script;
|
||||
$uls = $this->_underline;
|
||||
$bFamily = $this->_font_family;
|
||||
$bCharSet = $this->_font_charset;
|
||||
$rgch = $this->_font;
|
||||
|
||||
$cch = strlen($rgch);
|
||||
$record = 0x31;
|
||||
$length = 0x0F + $cch;
|
||||
$reserved = 0x00;
|
||||
|
||||
$grbit = 0x00;
|
||||
|
||||
if ($this->_italic) {
|
||||
$grbit |= 0x02;
|
||||
}
|
||||
|
||||
if ($this->_font_strikeout) {
|
||||
$grbit |= 0x08;
|
||||
}
|
||||
|
||||
if ($this->_font_outline) {
|
||||
$grbit |= 0x10;
|
||||
}
|
||||
|
||||
if ($this->_font_shadow) {
|
||||
$grbit |= 0x20;
|
||||
}
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvvvCCCCC", $dyHeight, $grbit, $icv, $bls,
|
||||
$sss, $uls, $bFamily,
|
||||
$bCharSet, $reserved, $cch);
|
||||
|
||||
return($header . $data . $this->_font);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a unique hash key for a font.
|
||||
* Used by writeexcel_workbook::_store_all_fonts()
|
||||
*/
|
||||
function get_font_key() {
|
||||
|
||||
# The following elements are arranged to increase the probability of
|
||||
# generating a unique key. Elements that hold a large range of numbers
|
||||
# eg. _color are placed between two binary elements such as _italic
|
||||
#
|
||||
$key = $this->_font.$this->_size.
|
||||
$this->_font_script.$this->_underline.
|
||||
$this->_font_strikeout.$this->_bold.$this->_font_outline.
|
||||
$this->_font_family.$this->_font_charset.
|
||||
$this->_font_shadow.$this->_color.$this->_italic;
|
||||
|
||||
$key = preg_replace('/ /', '_', $key); # Convert the key to a single word
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the used by Worksheet->_XF()
|
||||
*/
|
||||
function get_xf_index() {
|
||||
return $this->_xf_index;
|
||||
}
|
||||
|
||||
/*
|
||||
* Used in conjunction with the set_xxx_color methods to convert a color
|
||||
* string into a number. Color range is 0..63 but we will restrict it
|
||||
* to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
|
||||
*/
|
||||
function _get_color($color=false) {
|
||||
|
||||
$colors = array(
|
||||
'aqua' => 0x0F,
|
||||
'cyan' => 0x0F,
|
||||
'black' => 0x08,
|
||||
'blue' => 0x0C,
|
||||
'brown' => 0x10,
|
||||
'magenta' => 0x0E,
|
||||
'fuchsia' => 0x0E,
|
||||
'gray' => 0x17,
|
||||
'grey' => 0x17,
|
||||
'green' => 0x11,
|
||||
'lime' => 0x0B,
|
||||
'navy' => 0x12,
|
||||
'orange' => 0x35,
|
||||
'purple' => 0x14,
|
||||
'red' => 0x0A,
|
||||
'silver' => 0x16,
|
||||
'white' => 0x09,
|
||||
'yellow' => 0x0D
|
||||
);
|
||||
|
||||
// Return the default color, 0x7FFF, if undef,
|
||||
if ($color===false) {
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
// or the color string converted to an integer,
|
||||
if (isset($colors[strtolower($color)])) {
|
||||
return $colors[strtolower($color)];
|
||||
}
|
||||
|
||||
// or the default color if string is unrecognised,
|
||||
if (preg_match('/\D/', $color)) {
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
// or an index < 8 mapped into the correct range,
|
||||
if ($color<8) {
|
||||
return $color + 8;
|
||||
}
|
||||
|
||||
// or the default color if arg is outside range,
|
||||
if ($color>63) {
|
||||
return 0x7FFF;
|
||||
}
|
||||
|
||||
// or an integer in the valid range
|
||||
return $color;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set cell alignment.
|
||||
*/
|
||||
function set_align($location) {
|
||||
|
||||
// Ignore numbers
|
||||
if (preg_match('/\d/', $location)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$location = strtolower($location);
|
||||
|
||||
switch ($location) {
|
||||
|
||||
case 'left':
|
||||
$this->set_text_h_align(1);
|
||||
break;
|
||||
|
||||
case 'centre':
|
||||
case 'center':
|
||||
$this->set_text_h_align(2);
|
||||
break;
|
||||
|
||||
case 'right':
|
||||
$this->set_text_h_align(3);
|
||||
break;
|
||||
|
||||
case 'fill':
|
||||
$this->set_text_h_align(4);
|
||||
break;
|
||||
|
||||
case 'justify':
|
||||
$this->set_text_h_align(5);
|
||||
break;
|
||||
|
||||
case 'merge':
|
||||
$this->set_text_h_align(6);
|
||||
break;
|
||||
|
||||
case 'equal_space':
|
||||
$this->set_text_h_align(7);
|
||||
break;
|
||||
|
||||
case 'top':
|
||||
$this->set_text_v_align(0);
|
||||
break;
|
||||
|
||||
case 'vcentre':
|
||||
case 'vcenter':
|
||||
$this->set_text_v_align(1);
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'bottom':
|
||||
$this->set_text_v_align(2);
|
||||
break;
|
||||
|
||||
case 'vjustify':
|
||||
$this->set_text_v_align(3);
|
||||
break;
|
||||
|
||||
case 'vequal_space':
|
||||
$this->set_text_v_align(4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set vertical cell alignment. This is required by the set_properties()
|
||||
* method to differentiate between the vertical and horizontal properties.
|
||||
*/
|
||||
function set_valign($location) {
|
||||
$this->set_align($location);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an alias for the unintuitive set_align('merge')
|
||||
*/
|
||||
function set_merge() {
|
||||
$this->set_text_h_align(6);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bold has a range 0x64..0x3E8.
|
||||
* 0x190 is normal. 0x2BC is bold.
|
||||
*/
|
||||
function set_bold($weight=1) {
|
||||
|
||||
if ($weight == 1) {
|
||||
// Bold text
|
||||
$weight = 0x2BC;
|
||||
}
|
||||
|
||||
if ($weight == 0) {
|
||||
// Normal text
|
||||
$weight = 0x190;
|
||||
}
|
||||
|
||||
if ($weight < 0x064) {
|
||||
// Lower bound
|
||||
$weight = 0x190;
|
||||
}
|
||||
|
||||
if ($weight > 0x3E8) {
|
||||
// Upper bound
|
||||
$weight = 0x190;
|
||||
}
|
||||
|
||||
$this->_bold = $weight;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set all cell borders (bottom, top, left, right) to the same style
|
||||
*/
|
||||
function set_border($style) {
|
||||
$this->set_bottom($style);
|
||||
$this->set_top($style);
|
||||
$this->set_left($style);
|
||||
$this->set_right($style);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set all cell borders (bottom, top, left, right) to the same color
|
||||
*/
|
||||
function set_border_color($color) {
|
||||
$this->set_bottom_color($color);
|
||||
$this->set_top_color($color);
|
||||
$this->set_left_color($color);
|
||||
$this->set_right_color($color);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert hashes of properties to method calls.
|
||||
*/
|
||||
function set_properties() {
|
||||
|
||||
$_=func_get_args();
|
||||
|
||||
$properties=array();
|
||||
foreach($_ as $props) {
|
||||
if (is_array($props)) {
|
||||
$properties=array_merge($properties, $props);
|
||||
} else {
|
||||
$properties[]=$props;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($properties as $key=>$value) {
|
||||
|
||||
// Strip leading "-" from Tk style properties eg. -color => 'red'.
|
||||
$key = preg_replace('/^-/', '', $key);
|
||||
|
||||
/* Make sure method names are alphanumeric characters only, in
|
||||
case tainted data is passed to the eval(). */
|
||||
if (preg_match('/\W/', $key)) {
|
||||
trigger_error("Unknown property: $key.",
|
||||
E_USER_ERROR);
|
||||
}
|
||||
|
||||
/* Evaling all $values as a strings gets around the problem of
|
||||
some numerical format strings being evaluated as numbers, for
|
||||
example "00000" for a zip code. */
|
||||
if (is_int($key)) {
|
||||
eval("\$this->set_$value();");
|
||||
} else {
|
||||
eval("\$this->set_$key('$value');");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function set_font($font) {
|
||||
$this->_font=$font;
|
||||
}
|
||||
|
||||
function set_size($size) {
|
||||
$this->_size=$size;
|
||||
}
|
||||
|
||||
function set_italic($italic=1) {
|
||||
$this->_italic=$italic;
|
||||
}
|
||||
|
||||
function set_color($color) {
|
||||
$this->_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_underline($underline=1) {
|
||||
$this->_underline=$underline;
|
||||
}
|
||||
|
||||
function set_font_strikeout($font_strikeout=1) {
|
||||
$this->_font_strikeout=$font_strikeout;
|
||||
}
|
||||
|
||||
function set_font_outline($font_outline=1) {
|
||||
$this->_font_outline=$font_outline;
|
||||
}
|
||||
|
||||
function set_font_shadow($font_shadow=1) {
|
||||
$this->_font_shadow=$font_shadow;
|
||||
}
|
||||
|
||||
function set_font_script($font_script=1) {
|
||||
$this->_font_script=$font_script;
|
||||
}
|
||||
|
||||
/* Undocumented */
|
||||
function set_font_family($font_family=1) {
|
||||
$this->_font_family=$font_family;
|
||||
}
|
||||
|
||||
/* Undocumented */
|
||||
function set_font_charset($font_charset=1) {
|
||||
$this->_font_charset=$font_charset;
|
||||
}
|
||||
|
||||
function set_num_format($num_format=1) {
|
||||
$this->_num_format=$num_format;
|
||||
}
|
||||
|
||||
function set_hidden($hidden=1) {
|
||||
$this->_hidden=$hidden;
|
||||
}
|
||||
|
||||
function set_locked($locked=1) {
|
||||
$this->_locked=$locked;
|
||||
}
|
||||
|
||||
function set_text_h_align($align) {
|
||||
$this->_text_h_align=$align;
|
||||
}
|
||||
|
||||
function set_text_wrap($wrap=1) {
|
||||
$this->_text_wrap=$wrap;
|
||||
}
|
||||
|
||||
function set_text_v_align($align) {
|
||||
$this->_text_v_align=$align;
|
||||
}
|
||||
|
||||
function set_text_justlast($text_justlast=1) {
|
||||
$this->_text_justlast=$text_justlast;
|
||||
}
|
||||
|
||||
function set_rotation($rotation=1) {
|
||||
$this->_rotation=$rotation;
|
||||
}
|
||||
|
||||
function set_fg_color($color) {
|
||||
$this->_fg_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_bg_color($color) {
|
||||
$this->_bg_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_pattern($pattern=1) {
|
||||
$this->_pattern=$pattern;
|
||||
}
|
||||
|
||||
function set_bottom($bottom=1) {
|
||||
$this->_bottom=$bottom;
|
||||
}
|
||||
|
||||
function set_top($top=1) {
|
||||
$this->_top=$top;
|
||||
}
|
||||
|
||||
function set_left($left=1) {
|
||||
$this->_left=$left;
|
||||
}
|
||||
|
||||
function set_right($right=1) {
|
||||
$this->_right=$right;
|
||||
}
|
||||
|
||||
function set_bottom_color($color) {
|
||||
$this->_bottom_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_top_color($color) {
|
||||
$this->_top_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_left_color($color) {
|
||||
$this->_left_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
function set_right_color($color) {
|
||||
$this->_right_color=$this->_get_color($color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
class writeexcel_olewriter {
|
||||
var $_OLEfilename;
|
||||
var $_OLEtmpfilename; /* ABR */
|
||||
var $_filehandle;
|
||||
var $_fileclosed;
|
||||
var $_internal_fh;
|
||||
var $_biff_only;
|
||||
var $_size_allowed;
|
||||
var $_biffsize;
|
||||
var $_booksize;
|
||||
var $_big_blocks;
|
||||
var $_list_blocks;
|
||||
var $_root_start;
|
||||
var $_block_count;
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
function writeexcel_olewriter($filename) {
|
||||
|
||||
$this->_OLEfilename = $filename;
|
||||
$this->_filehandle = false;
|
||||
$this->_fileclosed = 0;
|
||||
$this->_internal_fh = 0;
|
||||
$this->_biff_only = 0;
|
||||
$this->_size_allowed = 0;
|
||||
$this->_biffsize = 0;
|
||||
$this->_booksize = 0;
|
||||
$this->_big_blocks = 0;
|
||||
$this->_list_blocks = 0;
|
||||
$this->_root_start = 0;
|
||||
$this->_block_count = 4;
|
||||
|
||||
$this->_initialize();
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for a valid filename and store the filehandle.
|
||||
*/
|
||||
function _initialize() {
|
||||
$OLEfile = $this->_OLEfilename;
|
||||
|
||||
/* Check for a filename. Workbook.pm will catch this first. */
|
||||
if ($OLEfile == '') {
|
||||
trigger_error("Filename required", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the filename is a resource it is assumed that it is a valid
|
||||
* filehandle, if not we create a filehandle.
|
||||
*/
|
||||
if (is_resource($OLEfile)) {
|
||||
$fh = $OLEfile;
|
||||
} else {
|
||||
// Create a new file, open for writing
|
||||
$fh = fopen($OLEfile, "wb");
|
||||
// The workbook class also checks this but something may have
|
||||
// happened since then.
|
||||
if (!$fh) {
|
||||
trigger_error("Can't open $OLEfile. It may be in use or ".
|
||||
"protected", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$this->_internal_fh = 1;
|
||||
}
|
||||
|
||||
// Store filehandle
|
||||
$this->_filehandle = $fh;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the size of the data to be written to the OLE stream
|
||||
*
|
||||
* $big_blocks = (109 depot block x (128 -1 marker word)
|
||||
* - (1 x end words)) = 13842
|
||||
* $maxsize = $big_blocks * 512 bytes = 7087104
|
||||
*/
|
||||
function set_size($size) {
|
||||
$maxsize = 7087104;
|
||||
|
||||
if ($size > $maxsize) {
|
||||
trigger_error("Maximum file size, $maxsize, exceeded. To create ".
|
||||
"files bigger than this limit please use the ".
|
||||
"workbookbig class.", E_USER_ERROR);
|
||||
return ($this->_size_allowed = 0);
|
||||
}
|
||||
|
||||
$this->_biffsize = $size;
|
||||
|
||||
// Set the min file size to 4k to avoid having to use small blocks
|
||||
if ($size > 4096) {
|
||||
$this->_booksize = $size;
|
||||
} else {
|
||||
$this->_booksize = 4096;
|
||||
}
|
||||
|
||||
return ($this->_size_allowed = 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate various sizes needed for the OLE stream
|
||||
*/
|
||||
function _calculate_sizes() {
|
||||
$datasize = $this->_booksize;
|
||||
|
||||
if ($datasize % 512 == 0) {
|
||||
$this->_big_blocks = $datasize/512;
|
||||
} else {
|
||||
$this->_big_blocks = floor($datasize/512)+1;
|
||||
}
|
||||
// There are 127 list blocks and 1 marker blocks for each big block
|
||||
// depot + 1 end of chain block
|
||||
$this->_list_blocks = floor(($this->_big_blocks)/127)+1;
|
||||
$this->_root_start = $this->_big_blocks;
|
||||
|
||||
//print $this->_biffsize. "\n";
|
||||
//print $this->_big_blocks. "\n";
|
||||
//print $this->_list_blocks. "\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* Write root entry, big block list and close the filehandle.
|
||||
* This method must be called so that the file contents are
|
||||
* actually written.
|
||||
*/
|
||||
function close() {
|
||||
|
||||
if (!$this->_size_allowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->_biff_only) {
|
||||
$this->_write_padding();
|
||||
$this->_write_property_storage();
|
||||
$this->_write_big_block_depot();
|
||||
}
|
||||
|
||||
// Close the filehandle if it was created internally.
|
||||
if ($this->_internal_fh) {
|
||||
fclose($this->_filehandle);
|
||||
}
|
||||
/* ABR */
|
||||
if ($this->_OLEtmpfilename != '') {
|
||||
$fh = fopen($this->_OLEtmpfilename, "rb");
|
||||
if ($fh == false) {
|
||||
trigger_error("Can't read temporary file.", E_USER_ERROR);
|
||||
}
|
||||
fpassthru($fh);
|
||||
fclose($fh);
|
||||
unlink($this->_OLEtmpfilename);
|
||||
};
|
||||
|
||||
$this->_fileclosed = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write BIFF data to OLE file.
|
||||
*/
|
||||
function write($data) {
|
||||
fputs($this->_filehandle, $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write OLE header block.
|
||||
*/
|
||||
function write_header() {
|
||||
if ($this->_biff_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_calculate_sizes();
|
||||
|
||||
$root_start = $this->_root_start;
|
||||
$num_lists = $this->_list_blocks;
|
||||
|
||||
$id = pack("C8", 0xD0, 0xCF, 0x11, 0xE0,
|
||||
0xA1, 0xB1, 0x1A, 0xE1);
|
||||
$unknown1 = pack("VVVV", 0x00, 0x00, 0x00, 0x00);
|
||||
$unknown2 = pack("vv", 0x3E, 0x03);
|
||||
$unknown3 = pack("v", -2);
|
||||
$unknown4 = pack("v", 0x09);
|
||||
$unknown5 = pack("VVV", 0x06, 0x00, 0x00);
|
||||
$num_bbd_blocks = pack("V", $num_lists);
|
||||
$root_startblock = pack("V", $root_start);
|
||||
$unknown6 = pack("VV", 0x00, 0x1000);
|
||||
$sbd_startblock = pack("V", -2);
|
||||
$unknown7 = pack("VVV", 0x00, -2 ,0x00);
|
||||
$unused = pack("V", -1);
|
||||
|
||||
fputs($this->_filehandle, $id);
|
||||
fputs($this->_filehandle, $unknown1);
|
||||
fputs($this->_filehandle, $unknown2);
|
||||
fputs($this->_filehandle, $unknown3);
|
||||
fputs($this->_filehandle, $unknown4);
|
||||
fputs($this->_filehandle, $unknown5);
|
||||
fputs($this->_filehandle, $num_bbd_blocks);
|
||||
fputs($this->_filehandle, $root_startblock);
|
||||
fputs($this->_filehandle, $unknown6);
|
||||
fputs($this->_filehandle, $sbd_startblock);
|
||||
fputs($this->_filehandle, $unknown7);
|
||||
|
||||
for ($c=1;$c<=$num_lists;$c++) {
|
||||
$root_start++;
|
||||
fputs($this->_filehandle, pack("V", $root_start));
|
||||
}
|
||||
|
||||
for ($c=$num_lists;$c<=108;$c++) {
|
||||
fputs($this->_filehandle, $unused);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write big block depot.
|
||||
*/
|
||||
function _write_big_block_depot() {
|
||||
$num_blocks = $this->_big_blocks;
|
||||
$num_lists = $this->_list_blocks;
|
||||
$total_blocks = $num_lists * 128;
|
||||
$used_blocks = $num_blocks + $num_lists + 2;
|
||||
|
||||
$marker = pack("V", -3);
|
||||
$end_of_chain = pack("V", -2);
|
||||
$unused = pack("V", -1);
|
||||
|
||||
for ($i=1;$i<=($num_blocks-1);$i++) {
|
||||
fputs($this->_filehandle, pack("V", $i));
|
||||
}
|
||||
|
||||
fputs($this->_filehandle, $end_of_chain);
|
||||
fputs($this->_filehandle, $end_of_chain);
|
||||
|
||||
for ($c=1;$c<=$num_lists;$c++) {
|
||||
fputs($this->_filehandle, $marker);
|
||||
}
|
||||
|
||||
for ($c=$used_blocks;$c<=$total_blocks;$c++) {
|
||||
fputs($this->_filehandle, $unused);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write property storage. TODO: add summary sheets
|
||||
*/
|
||||
function _write_property_storage() {
|
||||
$rootsize = -2;
|
||||
$booksize = $this->_booksize;
|
||||
|
||||
// name type dir start size
|
||||
$this->_write_pps('Root Entry', 0x05, 1, -2, 0x00);
|
||||
$this->_write_pps('Book', 0x02, -1, 0x00, $booksize);
|
||||
$this->_write_pps('', 0x00, -1, 0x00, 0x0000);
|
||||
$this->_write_pps('', 0x00, -1, 0x00, 0x0000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write property sheet in property storage
|
||||
*/
|
||||
function _write_pps($name, $type, $dir, $start, $size) {
|
||||
$names = array();
|
||||
$length = 0;
|
||||
|
||||
if ($name != '') {
|
||||
$name = $name . "\0";
|
||||
// Simulate a Unicode string
|
||||
$chars=preg_split("''", $name, -1, PREG_SPLIT_NO_EMPTY);
|
||||
foreach ($chars as $char) {
|
||||
array_push($names, ord($char));
|
||||
}
|
||||
$length = strlen($name) * 2;
|
||||
}
|
||||
|
||||
$rawname = call_user_func_array('pack', array_merge(array("v*"), $names));
|
||||
$zero = pack("C", 0);
|
||||
|
||||
$pps_sizeofname = pack("v", $length); //0x40
|
||||
$pps_type = pack("v", $type); //0x42
|
||||
$pps_prev = pack("V", -1); //0x44
|
||||
$pps_next = pack("V", -1); //0x48
|
||||
$pps_dir = pack("V", $dir); //0x4c
|
||||
|
||||
$unknown1 = pack("V", 0);
|
||||
|
||||
$pps_ts1s = pack("V", 0); //0x64
|
||||
$pps_ts1d = pack("V", 0); //0x68
|
||||
$pps_ts2s = pack("V", 0); //0x6c
|
||||
$pps_ts2d = pack("V", 0); //0x70
|
||||
$pps_sb = pack("V", $start); //0x74
|
||||
$pps_size = pack("V", $size); //0x78
|
||||
|
||||
fputs($this->_filehandle, $rawname);
|
||||
fputs($this->_filehandle, str_repeat($zero, (64-$length)));
|
||||
fputs($this->_filehandle, $pps_sizeofname);
|
||||
fputs($this->_filehandle, $pps_type);
|
||||
fputs($this->_filehandle, $pps_prev);
|
||||
fputs($this->_filehandle, $pps_next);
|
||||
fputs($this->_filehandle, $pps_dir);
|
||||
fputs($this->_filehandle, str_repeat($unknown1, 5));
|
||||
fputs($this->_filehandle, $pps_ts1s);
|
||||
fputs($this->_filehandle, $pps_ts1d);
|
||||
fputs($this->_filehandle, $pps_ts2d);
|
||||
fputs($this->_filehandle, $pps_ts2d);
|
||||
fputs($this->_filehandle, $pps_sb);
|
||||
fputs($this->_filehandle, $pps_size);
|
||||
fputs($this->_filehandle, $unknown1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pad the end of the file
|
||||
*/
|
||||
function _write_padding() {
|
||||
$biffsize = $this->_biffsize;
|
||||
|
||||
if ($biffsize < 4096) {
|
||||
$min_size = 4096;
|
||||
} else {
|
||||
$min_size = 512;
|
||||
}
|
||||
|
||||
if ($biffsize % $min_size != 0) {
|
||||
$padding = $min_size - ($biffsize % $min_size);
|
||||
fputs($this->_filehandle, str_repeat("\0", $padding));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
require_once "class.writeexcel_workbook.inc.php";
|
||||
require_once "class.ole_pps_root.php";
|
||||
require_once "class.ole_pps_file.php";
|
||||
|
||||
class writeexcel_workbookbig extends writeexcel_workbook {
|
||||
|
||||
function writeexcel_workbookbig($filename) {
|
||||
$this->writeexcel_workbook($filename);
|
||||
}
|
||||
|
||||
function _store_OLE_file() {
|
||||
$file=new ole_pps_file(asc2ucs("Book"));
|
||||
$file->append($this->_data);
|
||||
|
||||
for ($c=0;$c<sizeof($this->_worksheets);$c++) {
|
||||
$worksheet=&$this->_worksheets[$c];
|
||||
while ($data=$worksheet->get_data()) {
|
||||
$file->append($data);
|
||||
}
|
||||
}
|
||||
|
||||
$ole=new ole_pps_root(false, false, array($file));
|
||||
$ole->save($this->_filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyleft 2002 Johann Hanne
|
||||
*
|
||||
* This is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place,
|
||||
* Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the Spreadsheet::WriteExcel Perl package ported to PHP
|
||||
* Spreadsheet::WriteExcel was written by John McNamara, jmcnamara@cpan.org
|
||||
*/
|
||||
|
||||
/*
|
||||
* Converts numeric $row/$col notation to an Excel cell reference string in
|
||||
* A1 notation.
|
||||
*/
|
||||
function xl_rowcol_to_cell($row, $col, $row_abs=false, $col_abs=false) {
|
||||
|
||||
$row_abs = $row_abs ? '$' : '';
|
||||
$col_abs = $col_abs ? '$' : '';
|
||||
|
||||
$int = floor($col / 26);
|
||||
$frac = $col % 26;
|
||||
|
||||
$chr1 = ''; // Most significant character in AA1
|
||||
|
||||
if ($int > 0) {
|
||||
$chr1 = chr(ord('A') + $int - 1);
|
||||
}
|
||||
|
||||
$chr2 = chr(ord('A') + $frac);
|
||||
|
||||
// Zero index to 1-index
|
||||
$row++;
|
||||
|
||||
return $col_abs.$chr1.$chr2.$row_abs.$row;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts an Excel cell reference string in A1 notation
|
||||
* to numeric $row/$col notation.
|
||||
*
|
||||
* Returns: array($row, $col, $row_absolute, $col_absolute)
|
||||
*
|
||||
* The $row_absolute and $col_absolute parameters aren't documented because
|
||||
* they are mainly used internally and aren't very useful to the user.
|
||||
*/
|
||||
function xl_cell_to_rowcol($cell) {
|
||||
|
||||
preg_match('/(\$?)([A-I]?[A-Z])(\$?)(\d+)/', $cell, $reg);
|
||||
|
||||
$col_abs = ($reg[1] == "") ? 0 : 1;
|
||||
$col = $reg[2];
|
||||
$row_abs = ($reg[3] == "") ? 0 : 1;
|
||||
$row = $reg[4];
|
||||
|
||||
// Convert base26 column string to number
|
||||
// All your Base are belong to us.
|
||||
$chars = preg_split('//', $col, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$expn = 0;
|
||||
$col = 0;
|
||||
|
||||
while (sizeof($chars)>0) {
|
||||
$char = array_pop($chars); // Least significant character first
|
||||
$col += (ord($char) - ord('A') + 1) * pow(26, $expn);
|
||||
$expn++;
|
||||
}
|
||||
|
||||
// Convert 1-index to zero-index
|
||||
$row--;
|
||||
$col--;
|
||||
|
||||
return array($row, $col, $row_abs, $col_abs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Increments the row number of an Excel cell reference string
|
||||
* in A1 notation.
|
||||
* For example C4 to C5
|
||||
*
|
||||
* Returns: a cell reference string in A1 notation.
|
||||
*/
|
||||
function xl_inc_row($cell) {
|
||||
list($row, $col, $row_abs, $col_abs) = xl_cell_to_rowcol($cell);
|
||||
return xl_rowcol_to_cell(++$row, $col, $row_abs, $col_abs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decrements the row number of an Excel cell reference string
|
||||
* in A1 notation.
|
||||
* For example C4 to C3
|
||||
*
|
||||
* Returns: a cell reference string in A1 notation.
|
||||
*/
|
||||
function xl_dec_row($cell) {
|
||||
list($row, $col, $row_abs, $col_abs) = xl_cell_to_rowcol($cell);
|
||||
return xl_rowcol_to_cell(--$row, $col, $row_abs, $col_abs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Increments the column number of an Excel cell reference string
|
||||
* in A1 notation.
|
||||
* For example C3 to D3
|
||||
*
|
||||
* Returns: a cell reference string in A1 notation.
|
||||
*/
|
||||
function xl_inc_col($cell) {
|
||||
list($row, $col, $row_abs, $col_abs) = xl_cell_to_rowcol($cell);
|
||||
return xl_rowcol_to_cell($row, ++$col, $row_abs, $col_abs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decrements the column number of an Excel cell reference string
|
||||
* in A1 notation.
|
||||
* For example C3 to B3
|
||||
*
|
||||
* Returns: a cell reference string in A1 notation.
|
||||
*/
|
||||
function xl_dec_col($cell) {
|
||||
list($row, $col, $row_abs, $col_abs) = xl_cell_to_rowcol($cell);
|
||||
return xl_rowcol_to_cell($row, --$col, $row_abs, $col_abs);
|
||||
}
|
||||
|
||||
function xl_date_list($year, $month=1, $day=1,
|
||||
$hour=0, $minute=0, $second=0) {
|
||||
|
||||
$monthdays=array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||
|
||||
// Leap years since 1900 (year is dividable by 4)
|
||||
$leapyears=floor(($year-1900)/4);
|
||||
|
||||
// Non-leap years since 1900 (year is dividable by 100)
|
||||
$nonleapyears=floor(($year-1900)/100);
|
||||
|
||||
// Non-non-leap years since 1900 (year is dividable by 400)
|
||||
// (Yes, it MUST be "1600", not "1900")
|
||||
$nonnonleapyears=floor(($year-1600)/400);
|
||||
|
||||
// Don't count the leap day of the specified year if it didn't
|
||||
// happen yet (i.e. before 1 March)
|
||||
//
|
||||
// Please note that $leapyears becomes -1 for dates before 1 March 1900;
|
||||
// this is not logical, but later we will add a day for Excel's
|
||||
// phantasie leap day in 1900 without checking if the date is actually
|
||||
// after 28 February 1900; so these two logic errors "neutralize"
|
||||
// each other
|
||||
if ($year%4==0 && $month<3) {
|
||||
$leapyears--;
|
||||
}
|
||||
|
||||
$days=365*($year-1900)+$leapyears-$nonleapyears+$nonnonleapyears;
|
||||
|
||||
for ($c=1;$c<$month;$c++) {
|
||||
$days+=$monthdays[$c-1];
|
||||
}
|
||||
|
||||
// Excel actually wants the days since 31 December 1899, not since
|
||||
// 1 January 1900; this will also add this extra day
|
||||
$days+=$day;
|
||||
|
||||
// Excel treats 1900 erroneously as a leap year, so we must
|
||||
// add one day
|
||||
//
|
||||
// Please note that we DON'T have to check if the date is after
|
||||
// 28 February 1900, because for such dates $leapyears is -1
|
||||
// (see above)
|
||||
$days++;
|
||||
|
||||
return (float)($days+($hour*3600+$minute*60+$second)/86400);
|
||||
}
|
||||
|
||||
function xl_parse_time($time) {
|
||||
|
||||
if (preg_match('/(\d{1,2}):(\d\d):?((?:\d\d)(?:\.\d+)?)?(?:\s+)?(am|pm)?/i', $time, $reg)) {
|
||||
|
||||
$hours = $reg[1];
|
||||
$minutes = $reg[2];
|
||||
$seconds = $reg[3] || 0;
|
||||
$meridian = strtolower($reg[4]) || '';
|
||||
|
||||
// Normalise midnight and midday
|
||||
if ($hours == 12 && $meridian != '') {
|
||||
$hours = 0;
|
||||
}
|
||||
|
||||
// Add 12 hours to the pm times. Note: 12.00 pm has been set to 0.00.
|
||||
if ($meridian == 'pm') {
|
||||
$hours += 12;
|
||||
}
|
||||
|
||||
// Calculate the time as a fraction of 24 hours in seconds
|
||||
return (float)(($hours*3600+$minutes*60+$seconds)/86400);
|
||||
|
||||
} else {
|
||||
return false; // Not a valid time string
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Automagically converts almost any date/time string to an Excel date.
|
||||
* This function will always only be as good as strtotime() is.
|
||||
*/
|
||||
function xl_parse_date($date) {
|
||||
|
||||
$unixtime=strtotime($date);
|
||||
|
||||
$year=date("Y", $unixtime);
|
||||
$month=date("m", $unixtime);
|
||||
$day=date("d", $unixtime);
|
||||
$hour=date("H", $unixtime);
|
||||
$minute=date("i", $unixtime);
|
||||
$second=date("s", $unixtime);
|
||||
|
||||
// Convert to Excel date
|
||||
return xl_date_list($year, $month, $day, $hour, $minute, $second);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dummy function to be "compatible" to Spreadsheet::WriteExcel
|
||||
*/
|
||||
function xl_parse_date_init() {
|
||||
// Erm... do nothing...
|
||||
// strtotime() doesn't require anything to be initialized
|
||||
// (do not ask me how to set the timezone...)
|
||||
}
|
||||
|
||||
/*
|
||||
* xl_decode_date_EU() and xl_decode_date_US() are mapped
|
||||
* to xl_parse_date(); there seems to be no PHP function that
|
||||
* differentiates between EU and US dates; I've never seen
|
||||
* somebody using dd/mm/yyyy anyway, it always should be one of:
|
||||
* - yyyy-mm-dd (international)
|
||||
* - dd.mm.yyyy (european)
|
||||
* - mm/dd/yyyy (english/US/british?)
|
||||
*/
|
||||
|
||||
function xl_decode_date_EU($date) {
|
||||
return xl_parse_date($date);
|
||||
}
|
||||
|
||||
function xl_decode_date_US($date) {
|
||||
return xl_parse_date($date);
|
||||
}
|
||||
|
||||
function xl_date_1904($exceldate) {
|
||||
|
||||
if ($exceldate < 1462) {
|
||||
// date is before 1904
|
||||
$exceldate = 0;
|
||||
} else {
|
||||
$exceldate -= 1462;
|
||||
}
|
||||
|
||||
return $exceldate;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user