For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
9.3 KiB

  1. # PHPExcel Developer Documentation
  2. ## Prerequisites, Installation, FAQ and Links
  3. ### Software requirements
  4. The following software is required to develop using PHPExcel:
  5. - PHP version 5.2.0 or newer
  6. - PHP extension php_zip enabled [^phpzip_footnote]
  7. - PHP extension php_xml enabled
  8. - PHP extension php_gd2 enabled (if not compiled in)
  9. ### Installation instructions
  10. Installation is quite easy: copy the contents of the Classes folder to any location within your application source directories.
  11. *Example:*
  12. If your web root folder is /var/www/ you may want to create a subfolder called /var/www/Classes/ and copy the files into that folder so you end up with files:
  13. /var/www/Classes/PHPExcel.php
  14. /var/www/Classes/PHPExcel/Calculation.php
  15. /var/www/Classes/PHPExcel/Cell.php
  16. ...
  17. ### Getting started
  18. A good way to get started is to run some of the tests included in the download.
  19. Copy the "Examples" folder next to your "Classes" folder from above so you end up with:
  20. /var/www/Examples/01simple.php
  21. /var/www/Examples/02types.php
  22. ...
  23. Start running the tests by pointing your browser to the test scripts:
  24. http://example.com/Tests/01simple.php
  25. http://example.com/Tests/02types.php
  26. ...
  27. **Note:** It may be necessary to modify the include/require statements at the beginning of each of the test scripts if your "Classes" folder from above is named differently.
  28. ### Useful links and tools
  29. There are some links and tools which are very useful when developing using PHPExcel. Please refer to the [PHPExcel CodePlex pages][2] for an update version of the list below.
  30. #### OpenXML / SpreadsheetML
  31. - __File format documentation__
  32. [http://www.ecma-international.org/news/TC45_current_work/TC45_available_docs.htm][3]
  33. - __OpenXML Explained e-book__
  34. [http://openxmldeveloper.org/articles/1970.aspx][4]
  35. - __Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats__
  36. [http://www.microsoft.com/downloads/details.aspx?familyid=941b3470-3ae9-4aee-8f43-c6bb74cd1466&displaylang=en][5]
  37. - __OpenXML Package Explorer__
  38. [http://www.codeplex.com/PackageExplorer/][6]
  39. ### Frequently asked questions
  40. The up-to-date F.A.Q. page for PHPExcel can be found on [http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=FAQ&referringTitle=Requirements][7].
  41. ##### There seems to be a problem with character encoding...
  42. It is necessary to use UTF-8 encoding for all texts in PHPExcel. If the script uses different encoding then you can convert those texts with PHP's iconv() or mb_convert_encoding() functions.
  43. ##### PHP complains about ZipArchive not being found
  44. Make sure you meet all requirements, especially php_zip extension should be enabled.
  45. The ZipArchive class is only required when reading or writing formats that use Zip compression (Excel2007 and OOCalc). Since version 1.7.6 the PCLZip library has been bundled with PHPExcel as an alternative to the ZipArchive class.
  46. This can be enabled by calling:
  47. ```php
  48. PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
  49. ```
  50. *before* calling the save method of the Excel2007 Writer.
  51. You can revert to using ZipArchive by calling:
  52. ```php
  53. PHPExcel_Settings::setZipClass(PHPExcel_Settings::ZIPARCHIVE);
  54. ```
  55. At present, this only allows you to write Excel2007 files without the need for ZipArchive (not to read Excel2007 or OOCalc)
  56. ##### Excel 2007 cannot open the file generated by PHPExcel_Writer_2007 on Windows
  57. "Excel found unreadable content in '*.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."
  58. Some older versions of the 5.2.x php_zip extension on Windows contain an error when creating ZIP files. The version that can be found on [http://snaps.php.net/win32/php5.2-win32-latest.zip][8] should work at all times.
  59. Alternatively, upgrading to at least PHP 5.2.9 should solve the problem.
  60. If you can't locate a clean copy of ZipArchive, then you can use the PCLZip library as an alternative when writing Excel2007 files, as described above.
  61. ##### Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate yyy bytes) in zzz on line aaa
  62. PHPExcel holds an "in memory" representation of a spreadsheet, so it is susceptible to PHP's memory limitations. The memory made available to PHP can be increased by editing the value of the memory_limit directive in your php.ini file, or by using ini_set('memory_limit', '128M') within your code (ISP permitting).
  63. Some Readers and Writers are faster than others, and they also use differing amounts of memory. You can find some indication of the relative performance and memory usage for the different Readers and Writers, over the different versions of PHPExcel, on the [discussion board][9].
  64. If you've already increased memory to a maximum, or can't change your memory limit, then [this discussion][10] on the board describes some of the methods that can be applied to reduce the memory usage of your scripts using PHPExcel.
  65. ##### Protection on my worksheet is not working?
  66. When you make use of any of the worksheet protection features (e.g. cell range protection, prohibiting deleting rows, ...), make sure you enable worksheet security. This can for example be done like this:
  67. ```php
  68. $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
  69. ```
  70. ##### Feature X is not working with PHPExcel_Reader_Y / PHPExcel_Writer_Z
  71. Not all features of PHPExcel are implemented in all of the Reader / Writer classes. This is mostly due to underlying libraries not supporting a specific feature or not having implemented a specific feature.
  72. For example autofilter is not implemented in PEAR Spreadsheet_Excel_writer, which is the base of our Excel5 writer.
  73. We are slowly building up a list of features, together with the different readers and writers that support them, in the "Functionality Cross-Reference.xls" file in the /Documentation folder.
  74. ##### Formulas don't seem to be calculated in Excel2003 using compatibility pack?
  75. This is normal behaviour of the compatibility pack, Excel2007 displays this correctly. Use PHPExcel_Writer_Excel5 if you really need calculated values, or force recalculation in Excel2003.
  76. ##### Setting column width is not 100% accurate
  77. Trying to set column width, I experience one problem. When I open the file in Excel, the actual width is 0.71 less than it should be.
  78. The short answer is that PHPExcel uses a measure where padding is included. See section: "Setting a column's width" for more details.
  79. ##### How do I use PHPExcel with my framework
  80. - There are some instructions for using PHPExcel with Joomla on the [Joomla message board][11]
  81. - A page of advice on using [PHPExcel in the Yii framework][12]
  82. - [The Bakery][13] has some helper classes for reading and writing with PHPExcel within CakePHP
  83. - Integrating [PHPExcel into Kohana 3][14] and [?????????? PHPExcel ? Kohana Framework][15]
  84. - Using [PHPExcel with Typo3][16]
  85. ##### Joomla Autoloader interferes with PHPExcel Autoloader
  86. Thanks to peterrlynch for the following advice on resolving issues between the [PHPExcel autoloader and Joomla Autoloader][17]
  87. #### Tutorials
  88. - __English PHPExcel tutorial__
  89. [http://openxmldeveloper.org][18]
  90. - __French PHPExcel tutorial__
  91. [http://g-ernaelsten.developpez.com/tutoriels/excel2007/][19]
  92. - __A Japanese-language introduction to PHPExcel__
  93. [http://journal.mycom.co.jp/articles/2009/03/06/phpexcel/index.html][21]
  94. [2]: http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Documents&referringTitle=Home
  95. [3]: http://www.ecma-international.org/news/TC45_current_work/TC45_available_docs.htm
  96. [4]: http://openxmldeveloper.org/articles/1970.aspx
  97. [5]: http://www.microsoft.com/downloads/details.aspx?familyid=941b3470-3ae9-4aee-8f43-c6bb74cd1466&displaylang=en
  98. [6]: http://www.codeplex.com/PackageExplorer/
  99. [7]: http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=FAQ&referringTitle=Requirements
  100. [8]: http://snaps.php.net/win32/php5.2-win32-latest.zip
  101. [9]: http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=234150
  102. [10]: http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=242712
  103. [11]: http://http:/forum.joomla.org/viewtopic.php?f=304&t=433060
  104. [12]: http://www.yiiframework.com/wiki/101/how-to-use-phpexcel-external-library-with-yii/
  105. [13]: http://bakery.cakephp.org/articles/melgior/2010/01/26/simple-excel-spreadsheet-helper
  106. [14]: http://www.flynsarmy.com/2010/07/phpexcel-module-for-kohana-3/
  107. [15]: http://szpargalki.blogspot.com/2011/02/phpexcel-kohana-framework.html
  108. [16]: http://typo3.org/documentation/document-library/extension-manuals/phpexcel_library/1.1.1/view/toc/0/
  109. [17]: http://phpexcel.codeplex.com/discussions/211925
  110. [18]: http://openxmldeveloper.org
  111. [19]: http://g-ernaelsten.developpez.com/tutoriels/excel2007/
  112. [20]: http://www.web-junior.net/sozdanie-excel-fajjlov-s-pomoshhyu-phpexcel/
  113. [21]: http://journal.mycom.co.jp/articles/2009/03/06/phpexcel/index.html
  114. [^phpzip_footnote]: __php_zip__ is only needed by __PHPExcel_Reader_Excel2007__, __PHPExcel_Writer_Excel2007__ and __PHPExcel_Reader_OOCalc__. In other words, if you need PHPExcel to handle .xlsx or .ods files you will need the zip extension, but otherwise not.<br />You can remove this dependency for writing Excel2007 files (though not yet for reading) by using the PCLZip library that is bundled with PHPExcel. See the FAQ section of this document for details about this. PCLZip does have a dependency on PHP's zlib extension being enabled.