.. You may want to use the usual include line. Uncomment and adjust the path. .. include:: ../Includes.txt .. role:: underline ================================ PHPExcel developer documentation ================================ :Created: 2009-10-02T14:37:50.820000000 :Changed: 2009-10-02T14:39:05.640000000 |img-1| |img-2| .. _1-Ext-PHPExcel-Library: 1. Ext: PHPExcel Library ======================== Extension Key: **phpexcel\_library** Ext. Developer Sebastian Winterhalder PHPExcel Library `www.codeplex.com/PHPExcel `_ Maarten Balliauw, Project manager / Developer and others: `http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Cre dits&referringTitle=Home `_ This document is published under the LGPL software license available from http://www.gnu.org/licenses/lgpl.html The content of this document is related to TYPO3 a GNU/GPL CMS/Framework available from `www.typo3.com `_ .. _2-Contents: 2.Contents ========== :underline:``PHPExcel Developer Documentation <#_Toc237519881>`_` `1 <#_Toc237519881>`_ :underline:``1. <#_Toc237519882>`_` :underline:``Contents <#_Toc237519882>`_` `2 <#_Toc237519882>`_ :underline:``2. <#_Toc237519883>`_` :underline:``Prerequisites <#_Toc237519883>`_` `4 <#_Toc237519883>`_ :underline:``2.1. <#_Toc237519884>`_` :underline:``Software requirements <#_Toc237519884>`_` `4 <#_Toc237519884>`_ :underline:``2.2. <#_Toc237519885>`_` :underline:``Installation instructions <#_Toc237519885>`_` `4 <#_Toc237519885>`_ :underline:``2.3. <#_Toc237519886>`_` :underline:``Useful links and tools <#_Toc237519886>`_` `4 <#_Toc237519886>`_ :underline:``2.3.1. <#_Toc237519887>`_` :underline:``OpenXML / SpreadsheetML <#_Toc237519887>`_` `4 <#_Toc237519887>`_ :underline:``2.3.2. <#_Toc237519888>`_` :underline:``Frequently asked questions <#_Toc237519888>`_` `4 <#_Toc237519888>`_ :underline:``2.3.3. <#_Toc237519889>`_` :underline:``Tutorials <#_Toc237519889>`_` `5 <#_Toc237519889>`_ :underline:``3. <#_Toc237519890>`_` :underline:``Architecture <#_Toc237519890>`_` `6 <#_Toc237519890>`_ :underline:``3.1. <#_Toc237519891>`_` :underline:``Schematical <#_Toc237519891>`_` `6 <#_Toc237519891>`_ :underline:``3.2. <#_Toc237519892>`_` :underline:``Spreadsheet in memory <#_Toc237519892>`_` `6 <#_Toc237519892>`_ :underline:``3.3. <#_Toc237519893>`_` :underline:``Readers and writers <#_Toc237519893>`_` `6 <#_Toc237519893>`_ :underline:``3.4. <#_Toc237519894>`_` :underline:``Fluent interfaces <#_Toc237519894>`_` `7 <#_Toc237519894>`_ :underline:``4. <#_Toc237519895>`_` :underline:``Creating a spreadsheet <#_Toc237519895>`_` `9 <#_Toc237519895>`_ :underline:``4.1. <#_Toc237519896>`_` :underline:``The PHPExcel class <#_Toc237519896>`_` `9 <#_Toc237519896>`_ :underline:``4.2. <#_Toc237519897>`_` :underline:``Worksheets <#_Toc237519897>`_` `9 <#_Toc237519897>`_ :underline:``4.3. <#_Toc237519898>`_` :underline:``Accessing cells <#_Toc237519898>`_` `9 <#_Toc237519898>`_ :underline:``4.3.1. <#_Toc237519899>`_` :underline:``Setting a cell value by coordinate <#_Toc237519899>`_` `9 <#_Toc237519899>`_ :underline:``4.3.2. <#_Toc237519900>`_` :underline:``Retrieving a cell by coordinate <#_Toc237519900>`_` `9 <#_Toc237519900>`_ :underline:``4.3.3. <#_Toc237519901>`_` :underline:``Setting a cell value by column and row <#_Toc237519901>`_` `9 <#_Toc237519901>`_ :underline:``4.3.4. <#_Toc237519902>`_` :underline:``Retrieving a cell by column and row <#_Toc237519902>`_` `9 <#_Toc237519902>`_ :underline:``4.3.5. <#_Toc237519903>`_` :underline:``Looping cells <#_Toc237519903>`_` `9 <#_Toc237519903>`_ :underline:``4.3.6. <#_Toc237519904>`_` :underline:``Using value binders to facilitate data entry <#_Toc237519904>`_` `11 <#_Toc237519904>`_ :underline:``4.4. <#_Toc237519905>`_` :underline:``PHPExcel recipes <#_Toc237519905>`_` `11 <#_Toc237519905>`_ :underline:``4.4.1. <#_Toc237519906>`_` :underline:``Setting a spreadsheet’s metadata <#_Toc237519906>`_` `11 <#_Toc237519906>`_ :underline:``4.4.2. <#_Toc237519907>`_` :underline:``Setting a spreadsheet’s active sheet <#_Toc237519907>`_` `12 <#_Toc237519907>`_ :underline:``4.4.3. <#_Toc237519908>`_` :underline:``Write a date into a cell <#_Toc237519908>`_` `12 <#_Toc237519908>`_ :underline:``4.4.4. <#_Toc237519909>`_` :underline:``Write a formula into a cell <#_Toc237519909>`_` `13 <#_Toc237519909>`_ :underline:``4.4.5. <#_Toc237519910>`_` :underline:``Explicitly set a cell’s datatype <#_Toc237519910>`_` `13 <#_Toc237519910>`_ :underline:``4.4.6. <#_Toc237519911>`_` :underline:``Change a cell into a clickable URL <#_Toc237519911>`_` `13 <#_Toc237519911>`_ :underline:``4.4.7. <#_Toc237519912>`_` :underline:``Setting a worksheet’s page orientation and size <#_Toc237519912>`_` `13 <#_Toc237519912>`_ :underline:``4.4.8. <#_Toc237519913>`_` :underline:``Center a page horizontally/vertically <#_Toc237519913>`_` `13 <#_Toc237519913>`_ :underline:``4.4.9. <#_Toc237519914>`_` :underline:``Setting the print header and footer of a worksheet <#_Toc237519914>`_` `14 <#_Toc237519914>`_ :underline:``4.4.10. <#_Toc237519915>`_` :underline:``Setting printing breaks on a row or column <#_Toc237519915>`_` `15 <#_Toc237519915>`_ :underline:``4.4.11. <#_Toc237519916>`_` :underline:``Show/hide gridlines when printing <#_Toc237519916>`_` `15 <#_Toc237519916>`_ :underline:``4.4.12. <#_Toc237519917>`_` :underline:``Setting rows/columns to repeat at top/left <#_Toc237519917>`_` `15 <#_Toc237519917>`_ :underline:``4.4.13. <#_Toc237519918>`_` :underline:``Specify printing area <#_Toc237519918>`_` `15 <#_Toc237519918>`_ :underline:``4.4.14. <#_Toc237519919>`_` :underline:``Formatting cells <#_Toc237519919>`_` `15 <#_Toc237519919>`_ :underline:``4.4.15. <#_Toc237519920>`_` :underline:``Number formats <#_Toc237519920>`_` `17 <#_Toc237519920>`_ :underline:``4.4.16. <#_Toc237519921>`_` :underline:``Setting the default style of a workbook <#_Toc237519921>`_` `17 <#_Toc237519921>`_ :underline:``4.4.17. <#_Toc237519922>`_` :underline:``Styling cell borders <#_Toc237519922>`_` `17 <#_Toc237519922>`_ :underline:``4.4.18. <#_Toc237519923>`_` :underline:``Conditional formatting a cell <#_Toc237519923>`_` `19 <#_Toc237519923>`_ :underline:``4.4.19. <#_Toc237519924>`_` :underline:``Add a comment to a cell <#_Toc237519924>`_` `19 <#_Toc237519924>`_ :underline:``4.4.20. <#_Toc237519925>`_` :underline:``Apply autofilter to a range of cells <#_Toc237519925>`_` `20 <#_Toc237519925>`_ :underline:``4.4.21. <#_Toc237519926>`_` :underline:``Setting security on a spreadsheet <#_Toc237519926>`_` `20 <#_Toc237519926>`_ :underline:``4.4.22. <#_Toc237519927>`_` :underline:``Setting data validation on a cell <#_Toc237519927>`_` `20 <#_Toc237519927>`_ :underline:``4.4.23. <#_Toc237519928>`_` :underline:``Setting a column’s width <#_Toc237519928>`_` `21 <#_Toc237519928>`_ :underline:``4.4.24. <#_Toc237519929>`_` :underline:``Show/hide a column <#_Toc237519929>`_` `21 <#_Toc237519929>`_ :underline:``4.4.25. <#_Toc237519930>`_` :underline:``Group/outline a column <#_Toc237519930>`_` `21 <#_Toc237519930>`_ :underline:``4.4.26. <#_Toc237519931>`_` :underline:``Setting a row’s height <#_Toc237519931>`_` `21 <#_Toc237519931>`_ :underline:``4.4.27. <#_Toc237519932>`_` :underline:``Show/hide a row <#_Toc237519932>`_` `22 <#_Toc237519932>`_ :underline:``4.4.28. <#_Toc237519933>`_` :underline:``Group/outline a row <#_Toc237519933>`_` `22 <#_Toc237519933>`_ :underline:``4.4.29. <#_Toc237519934>`_` :underline:``Merge/unmerge cells <#_Toc237519934>`_` `22 <#_Toc237519934>`_ :underline:``4.4.30. <#_Toc237519935>`_` :underline:``Inserting rows/columns <#_Toc237519935>`_` `22 <#_Toc237519935>`_ :underline:``4.4.31. <#_Toc237519936>`_` :underline:``Add a drawing to a worksheet <#_Toc237519936>`_` `22 <#_Toc237519936>`_ :underline:``4.4.32. <#_Toc237519937>`_` :underline:``Add rich text to a cell <#_Toc237519937>`_` `23 <#_Toc237519937>`_ :underline:``4.4.33. <#_Toc237519938>`_` :underline:``Define a named range <#_Toc237519938>`_` `23 <#_Toc237519938>`_ :underline:``4.4.34. <#_Toc237519939>`_` :underline:``Redirect output to a client’s web browser <#_Toc237519939>`_` `23 <#_Toc237519939>`_ :underline:``4.4.35. <#_Toc237519940>`_` :underline:``Setting the default column width <#_Toc237519940>`_` `24 <#_Toc237519940>`_ :underline:``4.4.36. <#_Toc237519941>`_` :underline:``Setting the default row height <#_Toc237519941>`_` `24 <#_Toc237519941>`_ :underline:``4.4.37. <#_Toc237519942>`_` :underline:``Add a GD drawing to a worksheet <#_Toc237519942>`_` `24 <#_Toc237519942>`_ :underline:``4.4.38. <#_Toc237519943>`_` :underline:``Setting worksheet zoom level <#_Toc237519943>`_` `25 <#_Toc237519943>`_ :underline:``5. <#_Toc237519944>`_` :underline:``Performing formula calculations <#_Toc237519944>`_` `26 <#_Toc237519944>`_ :underline:``5.1. <#_Toc237519945>`_` :underline:``Using the PHPExcel calculation engine <#_Toc237519945>`_` `26 <#_Toc237519945>`_ :underline:``5.2. <#_Toc237519946>`_` :underline:``Known limitations <#_Toc237519946>`_` `27 <#_Toc237519946>`_ :underline:``5.2.1. <#_Toc237519947>`_` :underline:``Operator precedence <#_Toc237519947>`_` `27 <#_Toc237519947>`_ :underline:``5.2.2. <#_Toc237519948>`_` :underline:``X ^ N (Power) <#_Toc237519948>`_` `27 <#_Toc237519948>`_ :underline:``5.2.3. <#_Toc237519949>`_` :underline:``Formulas involving numbers and text <#_Toc237519949>`_` `27 <#_Toc237519949>`_ :underline:``6. <#_Toc237519950>`_` :underline:``Reading and writing to file <#_Toc237519950>`_` `28 <#_Toc237519950>`_ :underline:``6.1. <#_Toc237519951>`_` :underline:``PHPExcel\_IOFactory <#_Toc237519951>`_` `28 <#_Toc237519951>`_ :underline:``6.1.1. <#_Toc237519952>`_` :underline:``Creating PHPExcel\_Reader\_IReader using PHPExcel\_IOFactory <#_Toc237519952>`_` `28 <#_Toc237519952>`_ :underline:``6.1.2. <#_Toc237519953>`_` :underline:``Creating PHPExcel\_Writer\_IWriter using PHPExcel\_IOFactory <#_Toc237519953>`_` `28 <#_Toc237519953>`_ :underline:``6.2. <#_Toc237519954>`_` :underline:``Excel 2007 (SpreadsheetML) file format <#_Toc237519954>`_` `28 <#_Toc237519954>`_ :underline:``6.2.1. <#_Toc237519955>`_` :underline:``PHPExcel\_Reader\_Excel2007 <#_Toc237519955>`_` `29 <#_Toc237519955>`_ :underline:``6.2.2. <#_Toc237519956>`_` :underline:``PHPExcel\_Writer\_Excel2007 <#_Toc237519956>`_` `29 <#_Toc237519956>`_ :underline:``6.3. <#_Toc237519957>`_` :underline:``Serialized file format <#_Toc237519957>`_` `30 <#_Toc237519957>`_ :underline:``6.3.1. <#_Toc237519958>`_` :underline:``PHPExcel\_Reader\_Serialized <#_Toc237519958>`_` `30 <#_Toc237519958>`_ :underline:``6.3.2. <#_Toc237519959>`_` :underline:``PHPExcel\_Writer\_Serialized <#_Toc237519959>`_` `30 <#_Toc237519959>`_ :underline:``6.4. <#_Toc237519960>`_` :underline:``Excel 5 (BIFF) file format <#_Toc237519960>`_` `31 <#_Toc237519960>`_ :underline:``6.4.1. <#_Toc237519961>`_` :underline:``PHPExcel\_Reader\_Excel5 <#_Toc237519961>`_` `31 <#_Toc237519961>`_ :underline:``6.4.2. <#_Toc237519962>`_` :underline:``PHPExcel\_Writer\_Excel5 <#_Toc237519962>`_` `32 <#_Toc237519962>`_ :underline:``6.5. <#_Toc237519963>`_` :underline:``CSV (Comma Separated Values) <#_Toc237519963>`_` `32 <#_Toc237519963>`_ :underline:``6.5.1. <#_Toc237519964>`_` :underline:``PHPExcel\_Reader\_CSV <#_Toc237519964>`_` `32 <#_Toc237519964>`_ :underline:``6.5.2. <#_Toc237519965>`_` :underline:``PHPExcel\_Writer\_CSV <#_Toc237519965>`_` `33 <#_Toc237519965>`_ :underline:``6.6. <#_Toc237519966>`_` :underline:``HTML <#_Toc237519966>`_` `33 <#_Toc237519966>`_ :underline:``6.6.1. <#_Toc237519967>`_` :underline:``PHPExcel\_Writer\_HTML <#_Toc237519967>`_` `33 <#_Toc237519967>`_ :underline:``6.7. <#_Toc237519968>`_` :underline:``PDF <#_Toc237519968>`_` `35 <#_Toc237519968>`_ :underline:``6.7.1. <#_Toc237519969>`_` :underline:``PHPExcel\_Writer\_PDF <#_Toc237519969>`_` `35 <#_Toc237519969>`_ :underline:``7. <#_Toc237519970>`_` :underline:``Credits <#_Toc237519970>`_` `36 <#_Toc237519970>`_ :underline:``Appendix A: <#_Toc237519971>`_` :underline:``Valid array keys for style applyFromArray() <#_Toc237519971>`_` `37 <#_Toc237519971>`_ .. _3-Prerequisites: 3.Prerequisites =============== .. _3-1-Software-requirements: 3.1.Software requirements ------------------------- The following software is required to develop using PHPExcel: - PHP version 5.2 or newer - PHP extension php\_zip enabled .. _3-2-Installation-instructions: 3.2.Installation instructions ----------------------------- Installation is quite easy: copy the contents of the Classes folder to any location in your application required. .. _3-3-Useful-links-and-tools: 3.3.Useful links and tools -------------------------- There are some links and tools which are very useful when developing using PHPExcel. Please refer to the:underline:``PHPExcel CodePlex pages `_` for an update version of the list below. .. _3-3-1-OpenXML-SpreadsheetML: 3.3.1.OpenXML / SpreadsheetML ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - **File format documentation** :underline:``http://www.ecma- international.org/news/TC45\_current\_work/TC45\_available\_docs.htm `_` - **OpenXML Explained e-book** :underline:``http://openxmldeveloper.org/articles/1970.aspx `_` - **Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats** :underline:``http://www.microsoft.com/downloads/de tails.aspx?familyid=941b3470-3ae9-4aee- 8f43-c6bb74cd1466&displaylang=en `_` - **OpenXML Package Explorer** :underline:``http://www.codeplex.com/PackageExplorer/ `_` .. _3-3-2-Frequently-asked-questions: 3.3.2.Frequently asked questions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The up-to-date F.A.Q. page for PHPExcel can be found on:underline:``ht tp://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=FAQ&referringTitle =Requirements `_` . .. _There-seems-to-be-a-problem-with-character-encoding: There seems to be a problem with character encoding... """""""""""""""""""""""""""""""""""""""""""""""""""""" It is necessary to use UTF-8 encoding for all texts in PHPExcel. If the script uses different encoding then it is possible to convert the texts with PHP's iconv() function. .. _PHP-complains-about-ZipArchive-not-being-found: PHP complains about ZipArchive not being found """""""""""""""""""""""""""""""""""""""""""""" Make sure you meet all Requirements, especially php\_zip extension should be enabled. .. _Excel-2007-cannot-open-the-file-generated-by-PHPExcel-Writer-2007-on-Windows: Excel 2007 cannot open the file generated by PHPExcel\_Writer\_2007 on Windows """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" “ *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.”* Some versions of the php\_zip extension on Windows contain an error when creating ZIP files. The version that can be found on:underline:``http://snaps.php.net/win32/php5.2-win32-latest.zip `_` should work at all times. .. _Protection-on-my-worksheet-is-not-working: Protection on my worksheet is not working? """""""""""""""""""""""""""""""""""""""""" 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: $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); .. _Feature-X-is-not-working-with-PHPExcel-Writer-Y: Feature X is not working with PHPExcel\_Writer\_Y """"""""""""""""""""""""""""""""""""""""""""""""" Not all features of PHPExcel are implemented in the Reader / Writer classes. This is mostly due to underlying libraries not supporting a specific feature or not having implemented a specific feature. For example autofilter is not implemented in PEAR Spreadsheet\_Excel\_writer, which is the base of our Excel5 writer. .. _Formulas-dont-seem-to-be-calculated-in-Excel2003-using-compatibility-pack: Formulas don’t seem to be calculated in Excel2003 using compatibility pack? """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 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. .. _Setting-column-width-is-not-100-accurate: Setting column width is not 100% accurate """"""""""""""""""""""""""""""""""""""""" Trying to set column width, I experience one problem. When I open the file in Excel, the actual width is 0.71 points less than it should be. Looks like using Calibri as the default font leads to this problem::underline:``http://support.microsoft.com/kb/214394 `_` This can be fixed (when needed) by using another default font: $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName( 'Arial Cyr'); .. _3-3-3-Tutorials: 3.3.3.Tutorials ^^^^^^^^^^^^^^^ **French PHPExcel tutorial** :underline:``http://g-ernaelsten.developpez.com/tutoriels/excel2007/ `_` .. _4-Architecture: 4.Architecture ============== .. _4-1-Schematical: 4.1.Schematical --------------- |img-3| .. _4-2-Spreadsheet-in-memory: 4.2.Spreadsheet in memory ------------------------- PHPExcel’s architecture is built in a way that it can serve as an in- memory spreadsheet. This means that, if one would want to create a web based view of a spreadsheet which communicates with PHPExcel’s object model, he would only have to write the front-end code. Just like desktop spreadsheet software, PHPExcel represents a spreadsheet containing one or more worksheets, which contain cells with data, formulas, images, … .. _4-3-Readers-and-writers: 4.3.Readers and writers ----------------------- On its own, PHPExcel does not provide the functionality to read from or write to a persisted spreadsheet (on disk or in a database). To provide that functionality, readers and writers can be used. By default, the PHPExcel package provides some readers and writers, including one for the Open XML spreadsheet format (a.k.a. Excel 2007 file format). You are not limited to the default readers and writers, as you are free to implement the PHPExcel\_Writer\_IReader and PHPExcel\_Writer\_IWriter interface in a custom class. |img-4| .. _4-4-Fluent-interfaces: 4.4.Fluent interfaces --------------------- PHPExcel supports fluent interfaces in most locations. This means that you can easily “chain” calls to specific methods without requiring a new PHP statement. For example, take the following code: $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw"); $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php"); $objPHPExcel->getProperties()->setCategory("Test result file"); This can be rewritten as: $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("Test result file"); **Using fluent interfaces is not required** Fluent interfaces have been implemented to provide a convenient programming API. Use of them is not required, but can make your code easier to read and maintain. .. _5-Creating-a-spreadsheet: 5.Creating a spreadsheet ======================== .. _5-1-The-PHPExcel-class: 5.1.The PHPExcel class ---------------------- The PHPExcel class is the core of PHPExcel. It contains references to the contained worksheets, document security settings and document meta data. To simplify the PHPExcel concept: the PHPExcel class represents your workbook. .. _5-2-Worksheets: 5.2.Worksheets -------------- A worksheet is a collection of cells, formula’s, images, graphs, … It holds all data you want to represent as a spreadsheet worksheet. .. _5-3-Accessing-cells: 5.3.Accessing cells ------------------- Accessing cells in a PHPExcel worksheet should be pretty straightforward. This topic lists some of the options to access a cell. .. _5-3-1-Setting-a-cell-value-by-coordinate: 5.3.1.Setting a cell value by coordinate ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Setting a cell value by coordinate can be done using the worksheet’ssetCellValuemethod. $objPHPExcel->getActiveSheet()->setCellValue('B8', 'Some value'); .. _5-3-2-Retrieving-a-cell-by-coordinate: 5.3.2.Retrieving a cell by coordinate ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To retrieve the value of a cell, the cell should first be retrieved from the worksheet using thegetCellmethod. A cell’s value can be read again using the following line of code: $objPHPExcel->getActiveSheet()->getCell('B8')->getValue(); If you need the calculated value of a cell, use the following code. This is further explained in Setting the default column width. $objPHPExcel->getActiveSheet()->getCell('B8')->getCalculatedValue(); .. _5-3-3-Setting-a-cell-value-by-column-and-row: 5.3.3.Setting a cell value by column and row ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Setting a cell value by coordinate can be done using the worksheet’ssetCellValueByColumnAndRowmethod. // Set cell B8$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 8, 'Some value'); .. _5-3-4-Retrieving-a-cell-by-column-and-row: 5.3.4.Retrieving a cell by column and row ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To retrieve the value of a cell, the cell should first be retrieved from the worksheet using thegetCellByColumnAndRowmethod. A cell’s value can be read again using the following line of code: // Get cell B8$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1, 8)->getValue(); If you need the calculated value of a cell, use the following code. This is further explained in Setting the default column width // Get cell B8$objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1, 8)->getCalculatedValue(); .. _5-3-5-Looping-cells: 5.3.5.Looping cells ^^^^^^^^^^^^^^^^^^^ .. _Looping-cells-using-iterators: Looping cells using iterators """"""""""""""""""""""""""""" The easiest way to loop cells is by using iterators. Using iterators, one can use foreach to loop worksheets, rows and cells. Below is an example where we read all the values in a worksheet and display them in a table. setReadDataOnly(true); $objPHPExcel = $objReader->load("test.xlsx"); $objWorksheet = $objPHPExcel->getActiveSheet(); echo '' . "\n"; foreach ($objWorksheet->getRowIterator() as $row) { echo '' . "\n"; $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,// even if it is not set.// By default, only cells// that are set will be// iterated. foreach ($cellIterator as $cell) { echo '' . "\n"; } echo '' . "\n"; } echo '
' . $cell->getValue() . '
' . "\n";?> Note that we have set the cell iterator’ssetIterateOnlyExistingCells()to false. This makes the iterator loop all cells, even if they were not set before. **The cell iterator will return** **null** **as the cell if it is not set in the worksheet.** Setting the cell iterator’s setIterateOnlyExistingCells()to falsewill loop all cells in the worksheet that can be available at that moment. This will create new cells if required and increase memory usage! Only use it if it is intended to loop all cells that are possibly available. .. _Looping-cells-using-indexes: Looping cells using indexes """"""""""""""""""""""""""" One can use the possibility to access cell values by column and row index like (0,1) instead of 'A1' for reading and writing cell values in loops. Note: In PHPExcel column index is 0-based while row index is 1-based. That means 'A1' ~ (0,1) Below is an example where we read all the values in a worksheet and display them in a table. setReadDataOnly(true); $objPHPExcel = $objReader->load("test.xlsx"); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = PHPExcel\_Cell::columnIndexFromString($highestColumn); // e.g. 5 echo '' . "\n"; for ($row = 1; $row <= $highestRow; ++$row) { echo '' . "\n"; for ($col = 0; $col <= $highestColumnIndex; ++$col) { echo '' . "\n"; } echo '' . "\n"; } echo '
' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '
' . "\n"; ?> .. _5-3-6-Using-value-binders-to-facilitate-data-entry: 5.3.6.Using value binders to facilitate data entry ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Internally, PHPExcel uses a defaultPHPExcel\_Cell\_IValueBinderimplementation (PHPExcel\_Cell\_DefaultValueBinder) to determine data types of entered data using a cell’ssetValue()method. Optionally, the default behaviour of PHPExcel can be modified, allowing easier data entry. For example, aPHPExcel\_Cell\_AdvancedValueBinderclass is present. It automatically converts percentages and dates entered as strings to the correct format, also setting the cell’s style information. The following example demonstrates how to set the value binder in PHPExcel: /\*\* PHPExcel \*/ require\_once 'PHPExcel.php'; /\*\* PHPExcel\_Cell\_AdvancedValueBinder \*/ require\_once 'PHPExcel/Cell/AdvancedValueBinder.php'; /\*\* PHPExcel\_IOFactory \*/ require\_once 'PHPExcel/IOFactory.php'; // Set value binder PHPExcel\_Cell::setValueBinder( new PHPExcel\_Cell\_AdvancedValueBinder() ); // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // ... // Add some data, resembling some different data types $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Percentage value:'); $objPHPExcel->getActiveSheet()->setCellValue('B4', '10%');// Converts to 0.1 and sets percentage cell style $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Date/time value:'); $objPHPExcel->getActiveSheet()->setCellValue('B5', '21 December 1983');// Converts to date and sets date format cell style **Creating your own value binder is easy.** When advanced value binding is required, you can implement the PHPExcel\_Cell\_IValueBinderinterface or extend the PHPExcel\_Cell\_DefaultValueBinderor PHPExcel\_Cell\_AdvancedValueBinderclasses. .. _5-4-PHPExcel-recipes: 5.4.PHPExcel recipes -------------------- The following pages offer you some widely-used PHPExcel recipes. Please note that these do NOT offer complete documentation on specific PHPExcel API functions, but just a bump to get you started. If you need specific API functions, please refer to the API documentation. For example, Setting a worksheet’s page orientation and size Setting a worksheet’s page orientation and size covers setting a page orientation to A4. Other paper formats, like US Letter, are not covered in this document, but in the PHPExcel API documentation. .. _5-4-1-Setting-a-spreadsheets-metadata: 5.4.1.Setting a spreadsheet’s metadata ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PHPExcel allows an easy way to set a spreadsheet’s metadata, using document property accessors. Spreadsheet metadata can be useful for finding a specific document in a file repository or a document management system. For example Microsoft Sharepoint uses document metadata to search for a specific document in its document lists. Setting spreadsheet metadata is done as follows: $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw"); $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php"); $objPHPExcel->getProperties()->setCategory("Test result file"); .. _5-4-2-Setting-a-spreadsheets-active-sheet: 5.4.2.Setting a spreadsheet’s active sheet ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following line of code sets the active sheet index to the first sheet: $objPHPExcel->setActiveSheetIndex(0); .. _5-4-3-Write-a-date-into-a-cell: 5.4.3.Write a date into a cell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In Excel, dates are stored as numeric values counting the number of days elapsed since 1900-01-01. For example, the date '2008-12-31' is represented as 39813. You can verify this in Microsoft Office Excel by entering that date in a cell and afterwards changing the number format to 'General' so the true numeric value is revealed. Writing a date value in a cell consists of 2 lines of code. Select the method that suits you the best. Here are some examples: /\* PHPExcel\_Cell\_AdvanceValueBinder required for this sample \*/ require\_once 'PHPExcel/Cell/AdvancedValueBinder.php';// MySQL-like timestamp '2008-12-31' PHPExcel\_Cell::setValueBinder( new PHPExcel\_Cell\_AdvancedValueBinder() ); $objPHPExcel->getActiveSheet()->setCellValue('D1', '2008-12-31') $objPHPExcel->getActiveSheet()->getStyle('D1')->getNumberFormat()->set FormatCode(PHPExcel\_Style\_NumberFormat::FORMAT\_DATE\_YYYYMMDDSLASH) // PHP-time (Unix time) $time = gmmktime(0,0,0,12,31,2008); // int(1230681600) $objPHPExcel->getActiveSheet()->setCellValue('D1', PHPExcel\_Shared\_Date::PHPToExcel($time)) $objPHPExcel->getActiveSheet()->getStyle('D1')->getNumberFormat()->set FormatCode(PHPExcel\_Style\_NumberFormat::FORMAT\_DATE\_YYYYMMDDSLASH) // Excel-time $objPHPExcel->getActiveSheet()->setCellValue('D1', 39813) $objPHPExcel->getActiveSheet()->getStyle('D1')->getNumberFormat()->set FormatCode(PHPExcel\_Style\_NumberFormat::FORMAT\_DATE\_YYYYMMDDSLASH) The above methods for entering a date all yield the same result. PHPExcel\_Style\_NumberFormat provides a lot of pre-defined date formats. **Notes:** See section "Using value binders to facilitate data entry" to learn more about the AdvancedValueBinder used in the first example. In previous versions of PHPExcel up to and including 1.6.6, when a cell had a date-like number format code, it was possible to enter a date directly using an integer PHP-time without converting to Excel date format. Starting with PHPExcel 1.6.7 this is no longer supported. Excel can also operate in a 1904-based calendar (default for workbooks saved on Mac). Normally, you do not have to worry about this when using PHPExcel. .. _5-4-4-Write-a-formula-into-a-cell: 5.4.4.Write a formula into a cell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Inside the Excel file, formulas are always stored as they would appear in an English version of Microsoft Office Excel. This is regardless of which language version of Microsoft Office Excel you may have used to create the Excel file. Therefore, when you write formulas with PHPExcel, you must always use English formulas. The following rules hold: - Decimal separator is '.' (period) - Function argument separator is ',' (comma) - Matrix row separator is ';' (semicolon) - Always use English function names When the final workbook is opened by the user, Microsoft Office Excel will take care of displaying the formula according the applications language. Translation is taken care of by the application! The following line of code writes the formula “=MIN(B2:C5)” into the cell B8. Note that the formula must start with “=“ to make PHPExcel recognise this as a formula. $objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C5)'); A cell’s formula can be read again using the following line of code: $objPHPExcel->getActiveSheet()->getCell('B8')->getValue(); If you need the calculated value of a cell, use the following code. This is further explained in Setting the default column width. $objPHPExcel->getActiveSheet()->getCell('B8')->getCalculatedValue(); .. _5-4-5-Explicitly-set-a-cells-datatype: 5.4.5.Explicitly set a cell’s datatype ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can set a cell’s datatype explicitly by using the cell’ssetValueExplicitmethod, or thesetCellValueExplicitmethod of a worksheet. Here’s an example: $objPHPExcel->getActiveSheet()->getCell('A1')->setValueExplicit('25', PHPExcel\_Cell\_DataType::TYPE\_NUMERIC); .. _5-4-6-Change-a-cell-into-a-clickable-URL: 5.4.6.Change a cell into a clickable URL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can make a cell a clickable URL by setting its hyperlink property: $objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net'); $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl ('http://www.phpexcel.net'); If you want to make a hyperlink to another worksheet/cell, use the following code: $objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net'); $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl (“sheet://'Sheetname'!A1”); .. _5-4-7-Setting-a-worksheets-page-orientation-and-size: 5.4.7.Setting a worksheet’s page orientation and size ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Setting a worksheet’s page orientation and size can be done using the following lines of code: $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExce l\_Worksheet\_PageSetup::ORIENTATION\_LANDSCAPE); $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel\ _Worksheet\_PageSetup::PAPERSIZE\_A4); Note that there are additional page settings available. Please refer to the API documentation for all possible options. .. _5-4-8-Center-a-page-horizontally-vertically: 5.4.8.Center a page horizontally/vertically ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To center a page horizontally/vertically, you can use the following code: $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered( true);$objPHPExcel->getActiveSheet()->getPageSetup()->setVerticalCente red(false); .. _5-4-9-Setting-the-print-header-and-footer-of-a-worksheet: 5.4.9.Setting the print header and footer of a worksheet ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Setting a worksheet’s print header and footer can be done using the following lines of code: $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&HP lease treat this document as confidential!'); $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N'); Substitution and formatting codes (starting with &) can be used inside headers and footers. There is no required order in which these codes must appear. The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again: - Strikethrough - Superscript - Subscript Superscript and subscript cannot both be ON at same time. Whichever comes first wins and the other is ignored, while the first is ON. The following codes are supported by Excel2007: .. ### BEGIN~OF~TABLE ### .. _L: **&L** """""" .. container:: table-row a **&L** b Code for "left section" (there are three header / footer locations, "left", "center", and "right"). When two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the order of appearance, and placed into the left section. .. _P: **&P** """""" .. container:: table-row a **&P** b Code for "current page #" .. _N: **&N** """""" .. container:: table-row a **&N** b Code for "total pages" .. _font-size: **&font size** """""""""""""" .. container:: table-row a **&font size** b Code for "text font size", where font size is a font size in points. .. _K: **&K** """""" .. container:: table-row a **&K** b Code for "text font color" - RGB Color is specified as RRGGBB - Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade value, NN is the tint/shade value. .. _S: **&S** """""" .. container:: table-row a **&S** b Code for "text strikethrough" on / off .. _X: **&X** """""" .. container:: table-row a **&X** b Code for "text super script" on / off .. _Y: **&Y** """""" .. container:: table-row a **&Y** b Code for "text subscript" on / off .. _C: **&C** """""" .. container:: table-row a **&C** b Code for "center section". When two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the order of appearance, and placed into the center section. .. _D: **&D** """""" .. container:: table-row a **&D** b Code for "date" .. _T: **&T** """""" .. container:: table-row a **&T** b Code for "time" .. _G: **&G** """""" .. container:: table-row a **&G** b Code for "picture as background" Please make sure to add the image to the header/footer: $objDrawing = new PHPExcel\_Worksheet\_HeaderFooterDrawing(); $objDrawing->setName('PHPExcel logo'); $objDrawing->setPath('./images/phpexcel\_logo.gif'); $objDrawing->setHeight(36); $objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawin g, PHPExcel\_Worksheet\_HeaderFooter::IMAGE\_HEADER\_LEFT); .. _U: **&U** """""" .. container:: table-row a **&U** b Code for "text single underline" .. _E: **&E** """""" .. container:: table-row a **&E** b Code for "double underline" .. _R: **&R** """""" .. container:: table-row a **&R** b Code for "right section". When two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the order of appearance, and placed into the right section. .. _Z: **&Z** """""" .. container:: table-row a **&Z** b Code for "this workbook's file path" .. _F: **&F** """""" .. container:: table-row a **&F** b Code for "this workbook's file name" .. _A: **&A** """""" .. container:: table-row a **&A** b Code for "sheet tab name" .. _: **&+** """""" .. container:: table-row a **&+** b Code for add to page # .. _: **&-** """""" .. container:: table-row a **&-** b Code for subtract from page # .. _font-name-font-type: **&"font name,font type"** """""""""""""""""""""""""" .. container:: table-row a **&"font name,font type"** b Code for "text font name" and "text font type", where font name and font type are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font name, it means "none specified". Both of font name and font type can be localized values. .. _Bold: **&"-,Bold"** """"""""""""" .. container:: table-row a **&"-,Bold"** b Code for "bold font style" .. _B: **&B** """""" .. container:: table-row a **&B** b Code for "bold font style" .. _Regular: **&"-,Regular"** """""""""""""""" .. container:: table-row a **&"-,Regular"** b Code for "regular font style" .. _Italic: **&"-,Italic"** """"""""""""""" .. container:: table-row a **&"-,Italic"** b Code for "italic font style" .. _I: **&I** """""" .. container:: table-row a **&I** b Code for "italic font style" .. _Bold-Italic: **&"-,Bold Italic"** """""""""""""""""""" .. container:: table-row a **&"-,Bold Italic"** b Code for "bold italic font style" .. _O: **&O** """""" .. container:: table-row a **&O** b Code for "outline style" .. _H: **&H** """""" .. container:: table-row a **&H** b Code for "shadow style" .. ###### END~OF~TABLE ###### .. _5-4-10-Setting-printing-breaks-on-a-row-or-column: 5.4.10.Setting printing breaks on a row or column ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To set a print break, use the following code, which sets a row break on row 10. $objPHPExcel->getActiveSheet()->setBreak( 'A10' , PHPExcel\_Worksheet::BREAK\_ROW ); The following line of code sets a print break on column D: $objPHPExcel->getActiveSheet()->setBreak( 'D10' , PHPExcel\_Worksheet::BREAK\_COLUMN ); .. _5-4-11-Show-hide-gridlines-when-printing: 5.4.11.Show/hide gridlines when printing ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To show/hide gridlines when printing, use the following code: $objPHPExcel->getActiveSheet()->setShowGridlines(true); .. _5-4-12-Setting-rows-columns-to-repeat-at-top-left: 5.4.12.Setting rows/columns to repeat at top/left ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PHPExcel can repeat specific rows/cells at top/left of a page. The following code is an example of how to repeat row 1 to 5 on each printed page of a specific worksheet: $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopBy StartAndEnd(1, 5); .. _5-4-13-Specify-printing-area: 5.4.13.Specify printing area ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To specify a worksheet’s printing area, use the following code: $objPHPExcel->getActiveSheet()->getPageSetup()->setPrintArea('A1:E5'); .. _5-4-14-Formatting-cells: 5.4.14.Formatting cells ^^^^^^^^^^^^^^^^^^^^^^^ A cell can be formatted with font, border, fill, … style information. For example, one can set the foreground colour of a cell to red, aligned to the right, and the border to black and thick border style. Let’s do that on cell B2: $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()- >setARGB(PHPExcel\_Style\_Color::COLOR\_RED); $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHor izontal(PHPExcel\_Style\_Alignment::HORIZONTAL\_RIGHT); $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop() ->setBorderStyle(PHPExcel\_Style\_Border::BORDER\_THICK); $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getBotto m()->setBorderStyle(PHPExcel\_Style\_Border::BORDER\_THICK); $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getLeft( )->setBorderStyle(PHPExcel\_Style\_Border::BORDER\_THICK); $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getRight ()->setBorderStyle(PHPExcel\_Style\_Border::BORDER\_THICK); $objPHPExcel->getActiveSheet()->getStyle('B2')->getFill()->setFillType (PHPExcel\_Style\_Fill::FILL\_SOLID); $objPHPExcel->getActiveSheet()->getStyle('B2')->getFill()->getStartCol or()->setARGB('FFFF0000'); Starting with PHPExcel 1.7.0 getStyle() also accepts a cell range as a parameter. For example, you can set a red background color on a range of cells: $objPHPExcel->getActiveSheet()->getStyle('B3:B7')->getFill() ->setFillType(PHPExcel\_Style\_Fill::FILL\_SOLID) ->getStartColor()->setARGB('FFFF0000'); **Tip** It is recommended to style many cells at once, using e.g. getStyle('A1:M500'), rather than styling the cells individually in a loop. This is much faster compared to looping through cells and styling them individually. There is also an alternative manner to set styles. The following code sets a cell’s style to font bold, alignment right, top border thin and a gradient fill: $styleArray = array( 'font' => array( 'bold' => true, ), 'alignment' => array( 'horizontal' => PHPExcel\_Style\_Alignment::HORIZONTAL\_RIGHT, ), 'borders' => array( 'top' => array( 'style' => PHPExcel\_Style\_Border::BORDER\_THIN, ), ), 'fill' => array( 'type' => PHPExcel\_Style\_Fill::FILL\_GRADIENT\_LINEAR, 'rotation' => 90, 'startcolor' => array( 'argb' => 'FFA0A0A0', ), 'endcolor' => array( 'argb' => 'FFFFFFFF', ), ), ); $objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray($styleA rray); Or with a range of cells: $objPHPExcel->getActiveSheet()->getStyle('B3:B7')->applyFromArray($sty leArray); This alternative method using arrays should be faster in terms of execution whenever you are setting more than one style property. But the difference may barely be measurable unless you have many different styles in your workbook. Prior to PHPExcel 1.7.0 duplicateStyleArray() was the recommended method for styling a cell range, but this method has now been deprecated since getStyle() has started to accept a cell range. .. _5-4-15-Number-formats: 5.4.15.Number formats ^^^^^^^^^^^^^^^^^^^^^ You often want to format numbers in Excel. For example you may want a thousands separator plus a fixed number of decimals after the decimal separator. Or perhaps you want some numbers to be zero-padded. In Microsoft Office Excel you may be familiar with selecting a number format from the "Format Cells" dialog. Here there are some predefined number formats available including some for dates. The dialog is designed in a way so you don't have to interact with the underlying raw number format code unless you need a custom number format. In PHPExcel, you can also apply various predefined number formats. Example: $objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat() ->setFormatCode(PHPExcel\_Style\_NumberFormat::FORMAT\_NUMBER\_COMMA\_ SEPARATED1); This will format a number e.g. 1587.2 so it shows up as 1,587.20 when you open the workbook in MS Office Excel. (Depending on settings for decimal and thousands separators in Microsoft Office Excel it may show up as 1.587,20) You can achieve exactly the same as the above by using this: $objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat() ->setFormatCode('#,##0.00'); In Microsoft Office Excel, as well as in PHPExcel, you will have to interact with raw number format codes whenever you need some special custom number format. Example: $objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat() ->setFormatCode('[Blue][>=3000]$#,##0;[Red][<0]$#,##0;$#,##0'); **Tip** The rules for composing a number format code in Excel can be rather complicated. Sometimes you know how to create some number format in Microsoft Office Excel, but don't know what the underlying number format code looks like. How do you find it?The readers shipped with PHPExcel come to the rescue. Load your template workbook using e.g. Excel2007 reader to reveal the number format code. Example how read a number format code for cell A1: $objReader = PHPExcel\_IOFactory::createReader('Excel2007');$objPHPExcel = $objRead er->load('template.xlsx');var\_dump($objPHPExcel->getActiveSheet()->ge tStyle('A1')->getNumberFormat()->getFormatCode()); Advanced users may find it faster to inspect the number format code directly by renaming template.xlsx to template.zip, unzipping, and looking for the relevant piece of XML code holding the number format code in *xl/styles.xml* . .. _5-4-16-Setting-the-default-style-of-a-workbook: 5.4.16.Setting the default style of a workbook ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It is possible to set the default style of a workbook. Let’s set the default font to Arial size 8: $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');$objPHPEx cel->getDefaultStyle()->getFont()->setSize(8); .. _5-4-17-Styling-cell-borders: 5.4.17.Styling cell borders ^^^^^^^^^^^^^^^^^^^^^^^^^^^ In PHPExcel it is easy to apply various borders on a rectangular selection. Here is how to apply a thick red border outline around cells B2:G8. $styleArray = array( 'borders' => array( 'outline' => array( 'style' => PHPExcel\_Style\_Border::BORDER\_THICK, 'color' => array('argb' => 'FFFF0000'), ), ), ); $objWorksheet->getStyle('B2:G8')->applyFromArray($styleArray); In Microsoft Office Excel, the above operation would correspond to selecting the cells B2:G8, launching the style dialog, choosing a thick red border, and clicking on the "Outline" border component. Note that the border outline is applied to the rectangular selection B2:G8 as a whole, not on each cell individually. You can achieve any border effect by using just the 5 basic borders and operating on a single cell at a time: .. ### BEGIN~OF~TABLE ### .. _Array-key: **Array key** """"""""""""" .. container:: table-row a **Array key** b **Maps to property** .. _left: left """" .. container:: table-row a left right top bottom diagonal b getLeft()getRight()getTop()getBottom()getDiagonal() .. ###### END~OF~TABLE ###### Additional shortcut borders come in handy like in the example above. These are the shortcut borders available: .. ### BEGIN~OF~TABLE ### .. _Array-key: **Array key** """"""""""""" .. container:: table-row a **Array key** b **Maps to property** .. _allbordersoutline: allbordersoutline """"""""""""""""" .. container:: table-row a allbordersoutline insidevertical horizontal b getAllBorders() getOutline() getInside() getVertical() getHorizontal() .. ###### END~OF~TABLE ###### An overview of all border shortcuts can be seen in the following image: |img-5| If you simultaneously set e.g. allborders and vertical, then we have "overlapping" borders, and one of the components has to win over the other where there is border overlap. In PHPExcel, from weakest to strongest borders, the list is as follows: allborders, outline/inside, vertical/horizontal, left/right/top/bottom/diagonal.This border hierarchy can be utilized to achieve various effects in an easy manner. .. _5-4-18-Conditional-formatting-a-cell: 5.4.18.Conditional formatting a cell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A cell can be formatted conditionally, based on a specific rule. For example, one can set the foreground colour of a cell to red if its value is below zero, and to green if its value is zero or more. One can set a conditional style ruleset to a cell using the following code: $objConditional1 = new PHPExcel\_Style\_Conditional(); $objConditional1->setConditionType(PHPExcel\_Style\_Conditional::CONDI TION\_CELLIS); $objConditional1->setOperatorType(PHPExcel\_Style\_Conditional::OPERAT OR\_LESSTHAN); $objConditional1->addCondition('0'); $objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel\ _Style\_Color::COLOR\_RED); $objConditional1->getStyle()->getFont()->setBold(true); $objConditional2 = new PHPExcel\_Style\_Conditional(); $objConditional2->setConditionType(PHPExcel\_Style\_Conditional::CONDI TION\_CELLIS); $objConditional2->setOperatorType(PHPExcel\_Style\_Conditional::OPERAT OR\_GREATERTHANOREQUAL); $objConditional2->addCondition('0'); $objConditional2->getStyle()->getFont()->getColor()->setARGB(PHPExcel\ _Style\_Color::COLOR\_GREEN); $objConditional2->getStyle()->getFont()->setBold(true); $conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->g etConditionalStyles(); array\_push($conditionalStyles, $objConditional1); array\_push($conditionalStyles, $objConditional2); $objPHPExcel->getActiveSheet()->getStyle('B2')->setConditionalStyles($ conditionalStyles); If you want to copy the ruleset to other cells, you can duplicate the style object: $objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('B2'), 'B3:B7' ); .. _5-4-19-Add-a-comment-to-a-cell: 5.4.19.Add a comment to a cell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To add a comment to a cell, use the following code. The example below adds a comment to cell E11: $objPHPExcel->getActiveSheet()->getComment('E11')->setAuthor('PHPExcel '); $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E11' )->getText()->createTextRun('PHPExcel:'); $objCommentRichText->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTe xtRun("\r\n"); $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTe xtRun('Total amount on the current invoice, excluding VAT.'); |img-6| .. _5-4-20-Apply-autofilter-to-a-range-of-cells: 5.4.20.Apply autofilter to a range of cells ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To apply an autofilter to a range of cells, use the following code: $objPHPExcel->getActiveSheet()->setAutoFilter('A1:C9'); **Make sure that you always include the complete filter range!** Excel does support setting only the caption row, but that's :underline:`**not**` a best practice... .. _5-4-21-Setting-security-on-a-spreadsheet: 5.4.21.Setting security on a spreadsheet ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Excel offers 3 levels of “protection”: document security, sheet security and cell security. - Document security allows you to set a password on a complete spreadsheet, allowing changes to be made only when that password is entered. - Worksheet security offers other security options: you can disallow inserting rows on a specific sheet, disallow sorting, … - Cell security offers the option to lock/unlock a cell as well as show/hide the internal formula An example on setting document security: $objPHPExcel->getSecurity()->setLockWindows(true); $objPHPExcel->getSecurity()->setLockStructure(true); $objPHPExcel->getSecurity()->setWorkbookPassword("PHPExcel"); An example on setting worksheet security: $objPHPExcel->getActiveSheet()->getProtection()->setPassword('PHPExcel '); $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); $objPHPExcel->getActiveSheet()->getProtection()->setSort(true); $objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true); $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true); An example on setting cell security: $objPHPExcel->getActiveSheet()->getStyle('B1')->getProtection()->setLo cked( PHPExcel\_Style\_Protection::PROTECTION\_UNPROTECTED ); **Make sure you enable worksheet protection if you need any of the worksheet protection features!** This can be done using the following code: $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); .. _5-4-22-Setting-data-validation-on-a-cell: 5.4.22.Setting data validation on a cell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data validation is a powerful feature of Excel2007. It allows to specify an input filter on the data that can be inserted in a specific cell. This filter can be a range (i.e. value must be between 0 and 10), a list (i.e. value must be picked from a list), … The following piece of code only allows numbers between 10 and 20 to be entered in cell B3: $objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation(); $objValidation->setType( PHPExcel\_Cell\_DataValidation::TYPE\_WHOLE ); $objValidation->setErrorStyle( PHPExcel\_Cell\_DataValidation::STYLE\_STOP ); $objValidation->setAllowBlank(true); $objValidation->setShowInputMessage(true); $objValidation->setShowErrorMessage(true); $objValidation->setErrorTitle('Input error'); $objValidation->setError('Number is not allowed!'); $objValidation->setPromptTitle('Allowed input'); $objValidation->setPrompt('Only numbers between 10 and 20 are allowed.'); $objValidation->setFormula1(10); $objValidation->setFormula2(20); $objPHPExcel->getActiveSheet()->getCell('B3')->setDataValidation($objV alidation); The following piece of code only allows an item picked from a list of data to be entered in cell B3: $objValidation = $objPHPExcel->getActiveSheet()->getCell('B5')->getDataValidation(); $objValidation->setType( PHPExcel\_Cell\_DataValidation::TYPE\_LIST ); $objValidation->setErrorStyle( PHPExcel\_Cell\_DataValidation::STYLE\_INFORMATION ); $objValidation->setAllowBlank(false); $objValidation->setShowInputMessage(true); $objValidation->setShowErrorMessage(true); $objValidation->setShowDropDown(true); $objValidation->setErrorTitle('Input error'); $objValidation->setError('Value is not in list.'); $objValidation->setPromptTitle('Pick from list'); $objValidation->setPrompt('Please pick a value from the drop-down list.'); $objValidation->setFormula1('"Item A,Item B,Item C"'); $objPHPExcel->getActiveSheet()->getCell('B5')->setDataValidation($objV alidation); When using a data validation list, make sure you put the list between “ and “ and that you split the items with a comma (,). If you need data validation on multiple cells, one can clone the ruleset: $objPHPExcel->getActiveSheet()->getCell('B8')->setDataValidation(clone $objValidation); .. _5-4-23-Setting-a-columns-width: 5.4.23.Setting a column’s width ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A column’s width can be set using the following code: $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12); If you want PHPExcel to perform an automatic width calculation, use the following code. PHPExcel will approximate the column with to the width of the widest column value. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(t rue); .. _5-4-24-Show-hide-a-column: 5.4.24.Show/hide a column ^^^^^^^^^^^^^^^^^^^^^^^^^ To set a worksheet’s column visibility, you can use the following code. The first line explicitly shows the column C, the second line hides column D. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(tr ue); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(fa lse); .. _5-4-25-Group-outline-a-column: 5.4.25.Group/outline a column ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To group/outline a column, you can use the following code: $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLev el(1); You can also collapse the column. Note that you should also set the column invisible, otherwise the collapse will not be visible in Excel 2007. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setCollapsed( true); $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setVisible(fa lse); Please refer to the part “group/outline a row” for a complete example on collapsing. You can instruct PHPExcel to add a summary to the right (default), or to the left. The following code adds the summary to the left: $objPHPExcel->getActiveSheet()->setShowSummaryRight(false); .. _5-4-26-Setting-a-rows-height: 5.4.26.Setting a row’s height ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A row’s height can be set using the following code: $objPHPExcel->getActiveSheet()->getRowDimension('10')->setRowHeight(10 0); .. _5-4-27-Show-hide-a-row: 5.4.27.Show/hide a row ^^^^^^^^^^^^^^^^^^^^^^ To set a worksheet’s row visibility, you can use the following code. The following example hides row number 10. $objPHPExcel->getActiveSheet()->getRowDimension('10')->setVisible(fals e); .. _5-4-28-Group-outline-a-row: 5.4.28.Group/outline a row ^^^^^^^^^^^^^^^^^^^^^^^^^^ To group/outline a row, you can use the following code: $objPHPExcel->getActiveSheet()->getRowDimension('5')->setOutlineLevel( 1); You can also collapse the row. Note that you should also set the row invisible, otherwise the collapse will not be visible in Excel 2007. $objPHPExcel->getActiveSheet()->getRowDimension('5')->setCollapsed(tru e); $objPHPExcel->getActiveSheet()->getRowDimension('5')->setVisible(false ); Here’s an example which collapses rows 50 to 80: for ($i = 51; $i <= 80; $i++) { $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i"); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, "LName $i"); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, "PhoneNo $i"); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, "FaxNo $i"); $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, true); $objPHPExcel->getActiveSheet()->getRowDimension($i)->setOutlineLevel(1 ); .. _objPHPExcel-getActiveSheet-getRowDimension-i-setVisible-false: $objPHPExcel->getActiveSheet()->getRowDimension($i)->setVisible(false) ; } $objPHPExcel->getActiveSheet()->getRowDimension(81)->setCollapsed(true ); You can instruct PHPExcel to add a summary below the collapsible rows (default), or above. The following code adds the summary above: $objPHPExcel->getActiveSheet()->setShowSummaryBelow(false); .. _5-4-29-Merge-unmerge-cells: 5.4.29.Merge/unmerge cells ^^^^^^^^^^^^^^^^^^^^^^^^^^ If you have a big piece of data you want to display in a worksheet, you can merge two or more cells together, to become one cell. This can be done using the following code: $objPHPExcel->getActiveSheet()->mergeCells('A18:E22'); Removing a merge can be done using theunmergeCellsmethod: $objPHPExcel->getActiveSheet()->unmergeCells('A18:E22'); .. _5-4-30-Inserting-rows-columns: 5.4.30.Inserting rows/columns ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can insert/remove rows/columns at a specific position. The following code inserts 2 new rows, right before row 7: $objPHPExcel->getActiveSheet()->insertNewRowBefore(7, 2); .. _5-4-31-Add-a-drawing-to-a-worksheet: 5.4.31.Add a drawing to a worksheet ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A drawing is always represented as a separate object, which can be added to a worksheet. Therefore, you must first instantiate a newPHPExcel\_Worksheet\_Drawing, and assign its properties a meaningful value: $objDrawing = new PHPExcel\_Worksheet\_Drawing(); $objDrawing->setName('Logo'); $objDrawing->setDescription('Logo'); $objDrawing->setPath('./images/officelogo.jpg'); $objDrawing->setHeight(36); To add the above drawing to the worksheet, use the following snippet of code. PHPExcel creates the link between the drawing and the worksheet: $objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); You can set numerous properties on a drawing, here are some examples: $objDrawing->setName('Paid'); $objDrawing->setDescription('Paid'); $objDrawing->setPath('./images/paid.png'); $objDrawing->setCoordinates('B15'); $objDrawing->setOffsetX(110); $objDrawing->setRotation(25); $objDrawing->getShadow()->setVisible(true); $objDrawing->getShadow()->setDirection(45); .. _5-4-32-Add-rich-text-to-a-cell: 5.4.32.Add rich text to a cell ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Adding rich text to a cell can be done usingPHPExcel\_RichTextinstances. Here’s an example, which creates the following rich text string: This invoice is ***payable within thirty days after the end of the month*** unless specified otherwise on the invoice. $objRichText = new PHPExcel\_RichText( $objPHPExcel->getActiveSheet()->getCell('A18') ); $objRichText->createText('This invoice is '); $objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month'); $objPayable->getFont()->setBold(true); $objPayable->getFont()->setItalic(true); $objPayable->getFont()->setColor( new PHPExcel\_Style\_Color( PHPExcel\_Style\_Color::COLOR\_DARKGREEN ) ); $objRichText->createText(', unless specified otherwise on the invoice.'); .. _5-4-33-Define-a-named-range: 5.4.33.Define a named range ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PHPExcel supports the definition of named ranges. These can be defined using the following code: // Add some data $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:'); $objPHPExcel->getActiveSheet()->setCellValue('A2', 'Lastname:'); $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Maarten'); $objPHPExcel->getActiveSheet()->setCellValue('B2', 'Balliauw'); // Define named ranges $objPHPExcel->addNamedRange( new PHPExcel\_NamedRange('PersonFN', $objPHPExcel->getActiveSheet(), 'B1') ); $objPHPExcel->addNamedRange( new PHPExcel\_NamedRange('PersonLN', $objPHPExcel->getActiveSheet(), 'B2') ); Optionally, a fourth parameter can be passed defining the named range local (i.e. only usable on the current worksheet). Named ranges are global by default. .. _5-4-34-Redirect-output-to-a-clients-web-browser: 5.4.34.Redirect output to a client’s web browser ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sometimes, one really wants to output a file to a client’s browser, especially when creating spreadsheets on-the-fly. There are some easy steps that can be followed to do this: Create your PHPExcel spreadsheet Output HTTP headers for the type of document you wish to output Use the PHPExcel\_Writer\_\* of your choice, and save to “php://output” PHPExcel\_Writer\_Excel2007 uses temporary storage when writing to php://output. By default, temporary files are stored in the script’s working directory. When there is no access, it falls back to the operating system’s temporary files location. **This may not be safe for unauthorized viewing!** Depending on the configuration of your operating system, temporary storage can be read by anyone using the same temporary storage folder. When confidentiality of your document is needed, it is recommended not to use php://output. .. _HTTP-headers: HTTP headers """""""""""" Example of a script redirecting an Excel 2007 file to the client's browser: save('php://output'); ?> Example of a script redirecting an Excel5 file to the client's browser: save('php://output'); ?> Caution: - Make sure not to include any echo statements or output any other contents than the Excel file. There should be no whitespace before the opening tag (which can also be omitted to avoid problems). - Make sure that your script is saved without a BOM (Byte-order mark). (Because this counts as echoing output) - Same things apply to all included files Failing to follow the above guidelines may result in corrupt Excel files arriving at the client browser, and/or that headers cannot be set by PHP (resulting in warning messages). .. _5-4-35-Setting-the-default-column-width: 5.4.35.Setting the default column width ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Default column width can be set using the following code: $objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth( 12); .. _5-4-36-Setting-the-default-row-height: 5.4.36.Setting the default row height ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Default row height can be set using the following code: $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight (15); .. _5-4-37-Add-a-GD-drawing-to-a-worksheet: 5.4.37.Add a GD drawing to a worksheet ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ There might be a situation where you want to generate an in-memory image using GD and add it to a PHPExcel worksheet without first having to save this file to a temporary location. Here’s an example which generates an image in memory and adds it to the active worksheet: // Generate an image $gdImage = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream'); $textColor = imagecolorallocate($gdImage, 255, 255, 255); imagestring($gdImage, 1, 5, 5, 'Created with PHPExcel', $textColor); // Add a drawing to the worksheet $objDrawing = new PHPExcel\_Worksheet\_MemoryDrawing(); $objDrawing->setName('Sample image'); $objDrawing->setDescription('Sample image'); $objDrawing->setImageResource($gdImage); $objDrawing->setRenderingFunction(PHPExcel\_Worksheet\_MemoryDrawing:: RENDERING\_JPEG); $objDrawing->setMimeType(PHPExcel\_Worksheet\_MemoryDrawing::MIMETYPE\ _DEFAULT); $objDrawing->setHeight(36); $objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); .. _5-4-38-Setting-worksheet-zoom-level: 5.4.38.Setting worksheet zoom level ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To set a worksheet’s zoom level, the following code can be used: $objPHPExcel->getActiveSheet()->getSheetView()->setZoomScale(75); Note that zoom level should be in range 10 – 400. .. _6-Performing-formula-calculations: 6.Performing formula calculations ================================= .. _6-1-Using-the-PHPExcel-calculation-engine: 6.1.Using the PHPExcel calculation engine ----------------------------------------- As PHPExcel represents an in-memory spreadsheet, it also offers formula calculation capabilities. A cell can be of a value type (containing a number or text), or a formula type (containing a formula which can be evaluated). For example, the formula "=SUM(A1:A10)" evaluates to the sum of values in A1, A2, ..., A10. To calculate a formula, you can call the cell containing the formula’s methodgetCalculatedValue(), for example: $objPHPExcel->getActiveSheet()->getCell('E11')->getCalculatedValue(); If you write the following line of code in the invoice demo included with PHPExcel, it evaluates to the value "64": |img-7| Another nice feature of PHPExcel's formula parser, is that it can automatically adjust a formula when inserting/removing rows/columns. Here's an example: |img-8| You see that the formula contained in cell E11 is "SUM(E4:E9)". Now, when I write the following line of code, two new product lines are added: $objPHPExcel->getActiveSheet()->insertNewRowBefore(7, 2); |img-9| Did you notice? The formula in the former cell E11 (now E13, as I inserted 2 new rows), changed to "SUM(E4:E11)". Also, the inserted cells duplicate style information of the previous cell, just like Excel's behaviour. Note that you can both insert rows and columns. .. _6-2-Known-limitations: 6.2.Known limitations --------------------- There are some known limitations to the PHPExcel calculation engine. Most of them are due to the fact that an Excel formula is converted into PHP code before being executed. This means that Excel formula calculation is subject to PHP’s language characteristics. .. _6-2-1-Operator-precedence: 6.2.1.Operator precedence ^^^^^^^^^^^^^^^^^^^^^^^^^ In Excel '+' wins over '&', just like '\*' wins over '+' in ordinary algebra. The former rule is not what one finds using the calculation engine shipped with PHPExcel. Reference for operator precedence in Excel: :underline:``http://support.microsoft.com/kb/25189 `_` Reference for operator precedence in PHP: :underline:``http://www.php.net/operators `_` .. _6-2-2-X-N-Power: 6.2.2.X ^ N (Power) ^^^^^^^^^^^^^^^^^^^ Powers in a formula entered like '2 ^ 3' don't work. Using the POWER() function does work: '=POWER(2; 3)'. This is due to the fact that PHP treats ^ as bitwise XOR instead of power. Reference for formulas in Excel: :underline:``http://office.microsoft.com/en- us/excel/HP030561391033.aspx `_` Reference for operators in PHP: :underline:``http://www.php.net/operators `_` .. _6-2-3-Formulas-involving-numbers-and-text: 6.2.3.Formulas involving numbers and text ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulas involving numbers and text may produce unexpected results or even unreadable file contents. For example, the formula '=3+"Hello"' is expected to produce an error in Excel (#VALUE!). Due to the fact that PHP converts “Hello” to a numeric value (zero), the result of this formula is evaluated as 3 instead of evaluating as an error. This also causes the Excel document being generated as containing unreadable content. Reference for this behaviour in PHP: :underline:``http://be.php.net/manual/en/language.types.string.php#lan guage.types.string.conversion `_` .. _7-Reading-and-writing-to-file: 7.Reading and writing to file ============================= As you already know from part Readers and writers Readers and writers, reading and writing to a persisted storage is not possible using the base PHPExcel classes. For this purpose, PHPExcel provides readers and writers, which are implementations of PHPExcel\_Writer\_IReader and PHPExcel\_Writer\_IWriter. .. _7-1-PHPExcel-IOFactory: 7.1.PHPExcel\_IOFactory ----------------------- The PHPExcel API offers multiple methods to create a PHPExcel\_Writer\_IReader or PHPExcel\_Writer\_IWriter instance: - Direct creation - Via PHPExcel\_IOFactory All examples underneath demonstrate the direct creation method. Note that you can also use the PHPExcel\_IOFactory class to do this. .. _7-1-1-Creating-PHPExcel-Reader-IReader-using-PHPExcel-IOFactory: 7.1.1.Creating PHPExcel\_Reader\_IReader using PHPExcel\_IOFactory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ There are 2 methods for reading in a file into PHPExcel: using automatic file type resolving or explicitly. Automatic file type resolving checks the different PHPExcel\_Reader\_IReader distributed with PHPExcel. If one of them can load the specified file name, the file is loaded using that PHPExcel\_Reader\_IReader. Explicit mode requires you to specify which PHPExcel\_Reader\_IReader should be used. You can create a PHPExcel\_Reader\_IReader instance using PHPExcel\_IOFactory in automatic file type resolving mode using the following code sample: $objPHPExcel = PHPExcel\_IOFactory->load("05featuredemo.xlsx"); A typical use of this feature is when you need to read files uploaded by your users, and you don’t know whether they are uploading xls or xlsx files. If you need to set some properties on the reader, (e.g. to only read data, see more about this later), then you may instead want to use this variant: $objReader = PHPExcel\_IOFactory::createReaderForFile("05featuredemo.xlsx"); $objReader->setReadDataOnly(true); $objReader->load("05featuredemo.xlsx"); You can create a PHPExcel\_Reader\_IReader instance using PHPExcel\_IOFactory in explicit mode using the following code sample: $objReader = PHPExcel\_IOFactory::createReader("Excel2007");$objPHPExcel = $objReader->load("05featuredemo.xlsx"); Note that automatic type resolving mode is slightly slower than explicit mode. .. _7-1-2-Creating-PHPExcel-Writer-IWriter-using-PHPExcel-IOFactory: 7.1.2.Creating PHPExcel\_Writer\_IWriter using PHPExcel\_IOFactory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can create a PHPExcel\_Writer\_Iwriter instance using PHPExcel\_IOFactory: $objWriter = PHPExcel\_IOFactory::createWriter($objPHPExcel, "Excel2007");$objWriter->save("05featuredemo.xlsx"); .. _7-2-Excel-2007-SpreadsheetML-file-format: 7.2.Excel 2007 (SpreadsheetML) file format ------------------------------------------ Excel2007 file format is the main file format of PHPExcel. It allows outputting the in-memory spreadsheet to a .xlsx file. .. _7-2-1-PHPExcel-Reader-Excel2007: 7.2.1.PHPExcel\_Reader\_Excel2007 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Reading-a-spreadsheet: Reading a spreadsheet """"""""""""""""""""" You can read an .xlsx file using the following code: $objReader = new PHPExcel\_Reader\_Excel2007(); $objPHPExcel = $objReader->load("05featuredemo.xlsx"); .. _Read-data-only: Read data only """""""""""""" You can set the option setReadDataOnly on the reader, to instruct the reader to ignore styling, data validation, … and just read cell data: $objReader = new PHPExcel\_Reader\_Excel2007(); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load("05featuredemo.xlsx"); .. _Read-specific-sheets-only: Read specific sheets only """"""""""""""""""""""""" You can set the option setLoadSheetsOnly on the reader, to instruct the reader to only load the sheets with a given name: $objReader = new PHPExcel\_Reader\_Excel2007(); $objReader->setLoadSheetsOnly( array("Sheet 1", "My special sheet") ); $objPHPExcel = $objReader->load("05featuredemo.xlsx"); .. _Read-specific-cells-only: Read specific cells only """""""""""""""""""""""" You can set the option setReadFilter on the reader, to instruct the reader to only load the cells which match a given rule. A read filter can be any class which implements PHPExcel\_Reader\_IReadFilter. By default, all cells are read using the PHPExcel\_Reader\_DefaultReadFilter. The following code will only read row 1 and rows 20 – 30 of any sheet in the Excel file: class MyReadFilter implements PHPExcel\_Reader\_IReadFilter { public function readCell($column, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 \|\| ($row >= 20 && $row <= 30)) { return true; } return false; } }$objReader = new PHPExcel\_Reader\_Excel2007(); $objReader->setReadFilter( new MyReadFilter() );$objPHPExcel = $objReader->load("06largescale.xlsx"); .. _7-2-2-PHPExcel-Writer-Excel2007: 7.2.2.PHPExcel\_Writer\_Excel2007 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Writing-a-spreadsheet: Writing a spreadsheet """"""""""""""""""""" You can write an .xlsx file using the following code: $objWriter = new PHPExcel\_Writer\_Excel2007($objPHPExcel); $objWriter->save("05featuredemo.xlsx"); .. _Formula-pre-calculation: Formula pre-calculation """"""""""""""""""""""" By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation: $objWriter = new PHPExcel\_Writer\_Excel2007($objPHPExcel);$objWriter- >setPreCalculateFormulas(false); $objWriter->save("05featuredemo.xlsx"); .. _Office-2003-compatibility-pack: Office 2003 compatibility pack """""""""""""""""""""""""""""" Because of a bug in the Office2003 compatibility pack, there can be some small issues when opening Excel2007 spreadsheets (mostly related to formula calculation). You can enable Office2003 compatibility with the following code: $objWriter = new PHPExcel\_Writer\_Excel2007($objPHPExcel);$objWriter- >setOffice2003Compatibility(true); $objWriter->save("05featuredemo.xlsx"); **Office2003 compatibility should only be used when needed** Office2003 compatibility option should only be used when needed. This option disables several Office2007 file format options, resulting in a lower-featured Office2007 spreadsheet when this option is used. .. _Temporary-storage: Temporary storage """"""""""""""""" When working with large spreadsheets, a useful feature is disk caching. When disk caching is enabled, this writer uses file based temporary storage instead of memory based temporary storage wherever possible. By default, temporary files are stored in the script’s working directory. When there is no access, it falls back to the operating system’s temporary files location. Note that disk caching does not speed up writing, it only lowers memory usage when needed. **Temporary storage may not be safe for unauthorized viewing!** Depending on the configuration of your operating system, temporary storage can be read by anyone using the same temporary storage folder. When confidentiality of your document is needed, it is recommended not to use disk caching. You can enable disk caching using the following code: $objWriter = new PHPExcel\_Writer\_Excel2007($objPHPExcel);$objWriter- >setUseDiskCaching(true); $objWriter->save("05featuredemo.xlsx"); Optionally, the location of the disk cache folder can be specified using the following code: $objWriter = new PHPExcel\_Writer\_Excel2007($objPHPExcel);$objWriter- >setUseDiskCaching(true, "/home/phpexcel/diskcache"); $objWriter->save("05featuredemo.xlsx"); .. _7-3-Serialized-file-format: 7.3.Serialized file format -------------------------- Serialized file format is a manner of storing a PHPExcel spreadsheet to disk, creating a file containing a serialized PHPExcel instance. It offers a fast and easy way to store and read a spreadsheet. **Serialized file format should not be used as a persistent storage method!** Since serialized files may not be compatible trough different PHPExcel versions, it is not a good idea to use this as a persistent storage method. Think of the serialized file format as a temporary storage, for example between 2 batch scripts that depend on each other’s output. .. _7-3-1-PHPExcel-Reader-Serialized: 7.3.1.PHPExcel\_Reader\_Serialized ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Reading-a-spreadsheet: Reading a spreadsheet """"""""""""""""""""" You can read a .phpxl file using the following code: $objReader = new PHPExcel\_Reader\_Serialized(); $objPHPExcel = $objReader->load("05featuredemo.phpxl"); .. _7-3-2-PHPExcel-Writer-Serialized: 7.3.2.PHPExcel\_Writer\_Serialized ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Writing-a-spreadsheet: Writing a spreadsheet """"""""""""""""""""" You can write a .phpxl file using the following code: $objWriter = new PHPExcel\_Writer\_Serialized($objPHPExcel); $objWriter->save("05featuredemo.phpxl"); .. _7-4-Excel-5-BIFF-file-format: 7.4.Excel 5 (BIFF) file format ------------------------------ Excel5 file format is the old Excel file format, implemented in PHPExcel to provide a uniform manner to create both .xlsx and .xls files. It is basically a modified version of:underline:``PEAR Spreadsheet\_Excel\_Writer `_` , and has the same limitations and features as the PEAR library. Excel5 file format will not be developed any further, it just provides an additional file format for PHPExcel. **Excel5 (BIFF) limitations** Please note that BIFF file format has some limits regarding to styling cells and handling large spreadsheets via PHP. .. _7-4-1-PHPExcel-Reader-Excel5: 7.4.1.PHPExcel\_Reader\_Excel5 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Reading-a-spreadsheet: Reading a spreadsheet """"""""""""""""""""" You can read an .xls file using the following code: $objReader = new PHPExcel\_Reader\_Excel5(); $objPHPExcel = $objReader->load("05featuredemo.xls"); .. _Read-data-only: Read data only """""""""""""" You can set the option setReadDataOnly on the reader, to instruct the reader to ignore styling, data validation, … and just read cell data: $objReader = new PHPExcel\_Reader\_Excel5(); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load("05featuredemo.xls"); .. _Read-specific-sheets-only: Read specific sheets only """"""""""""""""""""""""" You can set the option setLoadSheetsOnly on the reader, to instruct the reader to only load the sheets with a given name: $objReader = new PHPExcel\_Reader\_Excel5(); $objReader->setLoadSheetsOnly( array("Sheet 1", "My special sheet") ); $objPHPExcel = $objReader->load("05featuredemo.xls"); .. _Read-specific-cells-only: Read specific cells only """""""""""""""""""""""" You can set the option setReadFilter on the reader, to instruct the reader to only load the cells which match a given rule. A read filter can be any class which implements PHPExcel\_Reader\_IReadFilter. By default, all cells are read using the PHPExcel\_Reader\_DefaultReadFilter. The following code will only read row 1 and rows 20 – 30 of any sheet in the Excel file: class MyReadFilter implements PHPExcel\_Reader\_IReadFilter { public function readCell($column, $row, $worksheetName = '') { // Read title row and rows 20 - 30 if ($row == 1 \|\| ($row >= 20 && $row <= 30)) { return true; } return false; } }$objReader = new PHPExcel\_Reader\_Excel5(); $objReader->setReadFilter( new MyReadFilter() );$objPHPExcel = $objReader->load("06largescale.xls"); .. _7-4-2-PHPExcel-Writer-Excel5: 7.4.2.PHPExcel\_Writer\_Excel5 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Writing-a-spreadsheet: Writing a spreadsheet """"""""""""""""""""" You can write an .xls file using the following code: $objWriter = new PHPExcel\_Writer\_Excel5($objPHPExcel); $objWriter->save("05featuredemo.xls"); .. _Temporary-storage: Temporary storage """"""""""""""""" Internally, Excel5 writer stores temporary files on disk. When your server administrator disabled file access on the operating system’s temporary directory, you can override the default by using the following code: $objWriter = new PHPExcel\_Writer\_Excel5($objPHPExcel);$objWriter->se tTempDir("C:/temp/"); $objWriter->save("05featuredemo.xls"); .. _7-5-CSV-Comma-Separated-Values: 7.5.CSV (Comma Separated Values) -------------------------------- CSV (Comma Separated Values) are often used as an import/export file format with other systems. PHPExcel allows reading and writing to CSV files. **CSV limitations** Please note that CSV file format has some limits regarding to styling cells, number formatting, … .. _7-5-1-PHPExcel-Reader-CSV: 7.5.1.PHPExcel\_Reader\_CSV ^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Reading-a-CSV-file: Reading a CSV file """""""""""""""""" You can read a .csv file using the following code: $objReader = new PHPExcel\_Reader\_CSV(); $objPHPExcel = $objReader->load("05featuredemo.csv"); .. _Setting-CSV-options: Setting CSV options """"""""""""""""""" Often, CSV files are not really “comma separated”, or use semicolon (;) as a separator. You can instruct PHPExcel\_Reader\_CSV some options before reading a CSV file: $objReader = new PHPExcel\_Reader\_CSV();$objReader->setDelimiter(';'); $objReader->setEnclosure(''); $objReader->setLineEnding("\r\n");$objReader->setSheetIndex(0); $objPHPExcel = $objReader->load("05featuredemo.csv"); .. _Read-a-specific-worksheet: Read a specific worksheet """"""""""""""""""""""""" CSV files can only contain one worksheet. Therefore, you can specify which sheet to read from CSV: $objReader->setSheetIndex(0); .. _Read-into-existing-spreadsheet: Read into existing spreadsheet """""""""""""""""""""""""""""" When working with CSV files, it might occur that you want to import CSV data into an existing PHPExcel object. The following code loads a CSV file into an existing $objPHPExcel containing some sheets, and imports onto the 6 :sup:`th` sheet: $objReader = new PHPExcel\_Reader\_CSV();$objReader->setDelimiter(';'); $objReader->setEnclosure(''); $objReader->setLineEnding("\r\n");$objReader->setSheetIndex(5);$objRea der->loadIntoExisting("05featuredemo.csv", $objPHPExcel); .. _7-5-2-PHPExcel-Writer-CSV: 7.5.2.PHPExcel\_Writer\_CSV ^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. _Writing-a-CSV-file: Writing a CSV file """""""""""""""""" You can write a .csv file using the following code: $objWriter = new PHPExcel\_Writer\_CSV($objPHPExcel); $objWriter->save("05featuredemo.csv"); .. _Setting-CSV-options: Setting CSV options """"""""""""""""""" Often, CSV files are not really “comma separated”, or use semicolon (;) as a separator. You can instruct PHPExcel\_Writer\_CSV some options before writing a CSV file: $objWriter = new PHPExcel\_Writer\_CSV($objPHPExcel);$objWriter->setDelimiter(';'); $objWriter->setEnclosure(''); $objWriter->setLineEnding("\r\n");$objWriter->setSheetIndex(0); $objWriter->save("05featuredemo.csv"); .. _Write-a-specific-worksheet: Write a specific worksheet """""""""""""""""""""""""" CSV files can only contain one worksheet. Therefore, you can specify which sheet to write to CSV: $objWriter->setSheetIndex(0); .. _Formula-pre-calculation: Formula pre-calculation """"""""""""""""""""""" By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation: $objWriter = new PHPExcel\_Writer\_CSV($objPHPExcel);$objWriter->setPr eCalculateFormulas(false); $objWriter->save("05featuredemo.csv"); .. _Writing-UTF-8-CSV-files: Writing UTF-8 CSV files """"""""""""""""""""""" A CSV file can be marked as UTF-8 by writing a BOM file header. This can be enabled by using the following code: $objWriter = new PHPExcel\_Writer\_CSV($objPHPExcel);$objWriter->setUseBOM(true); $objWriter->save("05featuredemo.csv"); .. _7-6-HTML: 7.6.HTML -------- PHPExcel allows you to write a spreadsheet into HTML format, for quick representation of the data in it to anyone who does not have a spreadsheet application on their PC. **HTML limitations** Please note that HTML file format has some limits regarding to styling cells, number formatting, … .. _7-6-1-PHPExcel-Writer-HTML: 7.6.1.PHPExcel\_Writer\_HTML ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please note that PHPExcel\_Writer\_HTML only outputs the first worksheet by default. .. _Writing-a-spreadsheet: Writing a spreadsheet """"""""""""""""""""" You can write a .htm file using the following code: $objWriter = new PHPExcel\_Writer\_HTML($objPHPExcel); $objWriter->save("05featuredemo.htm"); .. _Write-all-worksheets: Write all worksheets """""""""""""""""""" HTML files can contain one or more worksheets. If you want to write all sheets into a single HTML file, use the following code: $objWriter->writeAllSheets(); .. _Write-a-specific-worksheet: Write a specific worksheet """""""""""""""""""""""""" HTML files can contain one or more worksheets. Therefore, you can specify which sheet to write to HTML: $objWriter->setSheetIndex(0); .. _Setting-the-images-root-of-the-HTML-file: Setting the images root of the HTML file """""""""""""""""""""""""""""""""""""""" There might be situations where you want to explicitly set the included images root. For example, one might want to seeinstead of. You can use the following code to achieve this result: $objWriter->setImagesRoot('http://www.example.com'); .. _Formula-pre-calculation: Formula pre-calculation """"""""""""""""""""""" By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation: $objWriter = new PHPExcel\_Writer\_HTML($objPHPExcel);$objWriter->setP reCalculateFormulas(false); $objWriter->save("05featuredemo.htm"); .. _Embedding-generated-HTML-in-a-web-page: Embedding generated HTML in a web page """""""""""""""""""""""""""""""""""""" There might be a situation where you want to embed the generated HTML in an existing website. PHPExcel\_Writer\_HTML provides support to generate only specific parts of the HTML code, which allows you to use these parts in your website. Supported methods: - generateHTMLHeader() - generateStyles() - generateSheetData() - generateHTMLFooter() Here’s an example which retrieves all parts independently and merges them into a resulting HTML page: generateHTMLHeader();?>?>--> generateSheetData();echo $objWriter->generateHTMLFooter();?> .. _Writing-UTF-8-HTML-files: Writing UTF-8 HTML files """""""""""""""""""""""" A HTML file can be marked as UTF-8 by writing a BOM file header. This can be enabled by using the following code: $objWriter = new PHPExcel\_Writer\_HTML($objPHPExcel);$objWriter->setUseBOM(true); $objWriter->save("05featuredemo.htm"); .. _7-7-PDF: 7.7.PDF ------- PHPExcel allows you to write a spreadsheet into PDF format, for fast distribution of represented data. **PDF limitations** Please note that PDF file format has some limits regarding to styling cells, number formatting, … .. _7-7-1-PHPExcel-Writer-PDF: 7.7.1.PHPExcel\_Writer\_PDF ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please note that PHPExcel\_Writer\_PDF only outputs the first worksheet by default. .. _Writing-a-spreadsheet: Writing a spreadsheet """"""""""""""""""""" You can write a .pdf file using the following code: $objWriter = new PHPExcel\_Writer\_PDF($objPHPExcel); $objWriter->save("05featuredemo.pdf"); .. _Write-all-worksheets: Write all worksheets """""""""""""""""""" PDF files can contain one or more worksheets. If you want to write all sheets into a single PDF file, use the following code: $objWriter->writeAllSheets(); .. _Write-a-specific-worksheet: Write a specific worksheet """""""""""""""""""""""""" PDF files can contain one or more worksheets. Therefore, you can specify which sheet to write to PDF: $objWriter->setSheetIndex(0); .. _Formula-pre-calculation: Formula pre-calculation """"""""""""""""""""""" By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation: $objWriter = new PHPExcel\_Writer\_PDF($objPHPExcel);$objWriter->setPr eCalculateFormulas(false); $objWriter->save("05featuredemo.pdf"); .. _Temporary-storage: Temporary storage """"""""""""""""" Internally, PDF writer stores temporary files on disk. When your server administrator disabled file access on the operating system’s temporary directory, you can override the default by using the following code: $objWriter = new PHPExcel\_Writer\_PDF($objPHPExcel);$objWriter->setTe mpDir("C:/temp/"); $objWriter->save("05featuredemo.pdf"); .. _8-Credits: 8.Credits ========= Please refer to the internet page:underline:``http://www.codeplex.com/ PHPExcel/Wiki/View.aspx?title=Credits&referringTitle=Home `_` for up-to-date credits. .. _Valid-array-keys-for-style-applyFromArray: Valid array keys for style applyFromArray() =========================================== The following table lists the valid array keys for PHPExcel\_Style applyFromArray() classes. If the “Maps to property” column maps a key to a setter, the value provided for that key will be applied directly. If the “Maps to property” column maps a key to a getter, the value provided for that key will be applied as another style array. .. ### BEGIN~OF~TABLE ### .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _fill: fill ---- .. container:: table-row a fill font borders alignment numberformat protection b getFill()getFont()getBorders()getAlignment()getNumberFormat()getProtec tion() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _typerotationstartcolorendcolorcolor: typerotationstartcolorendcolorcolor ----------------------------------- .. container:: table-row a typerotationstartcolorendcolorcolor b setFillType()setRotation()getStartColor()getEndColor()getStartColor() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _namebolditalicunderlinestrikecolorsizesuperScriptsubScript: namebolditalicunderlinestrikecolorsizesuperScriptsubScript ---------------------------------------------------------- .. container:: table-row a namebolditalicunderlinestrikecolorsizesuperScriptsubScript b setName()setBold()setItalic()setUnderline()setStrikethrough()getColor( )setSize()setSuperScript()setSubScript() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _allbordersleftrighttopbottomdiagonalverticalhorizontaldiagonaldirectio: allbordersleftrighttopbottomdiagonalverticalhorizontaldiagonaldirectio ---------------------------------------------------------------------- .. container:: table-row a allbordersleftrighttopbottomdiagonalverticalhorizontaldiagonaldirectio noutline b getLeft(); getRight(); getTop(); getBottom()getLeft()getRight()getTop()getBottom() getDiagonal()getVertical()getHorizontal()setDiagonalDirection()setOutl ine() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _stylecolor: stylecolor ---------- .. container:: table-row a stylecolor b setBorderStyle()getColor() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _horizontalverticalrotationwrapshrinkToFitindent: horizontalverticalrotationwrapshrinkToFitindent ----------------------------------------------- .. container:: table-row a horizontalverticalrotationwrapshrinkToFitindent b setHorizontal()setVertical()setTextRotation()setWrapText()setShrinkToF it()setIndent() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _code: code ---- .. container:: table-row a code b setFormatCode() .. _Array-key: Array key: ---------- .. container:: table-row a Array key: b Maps to property: .. _lockedhidden: lockedhidden ------------ .. container:: table-row a lockedhidden b setLocked()setHidden() .. ###### END~OF~TABLE ###### .. ### BEGIN~OF~TABLE ### .. _Author: **Author:** ----------- .. container:: table-row a **Author:** b Maarten Balliauw .. _Version: **Version:** ------------ .. container:: table-row a **Version:** b 1.7.0 .. _Date: **Date:** --------- .. container:: table-row a **Date:** b 15 November 2017 .. ###### END~OF~TABLE ###### .. ######CUTTER_MARK_IMAGES###### .. |img-1| image:: img-1.png .. :align: left .. :border: 0 .. :name: Picture 1 .. |img-2| image:: img-2.png .. :align: left .. :border: 0 .. :name: Picture 5 .. |img-3| image:: img-3.png .. :border: 0 .. :name: Picture 11 .. |img-4| image:: img-4.png .. :border: 0 .. :name: Picture 2 .. |img-5| image:: img-5.png .. :border: 0 .. :name: Picture 31 .. |img-6| image:: img-6.png .. :border: 0 .. :name: Picture 4 .. |img-7| image:: img-7.png .. :border: 0 .. :name: Picture 51 .. |img-8| image:: img-8.png .. :border: 0 .. :name: Picture 61 .. |img-9| image:: img-9.png .. :border: 0 .. :name: Picture 7