| ' . $cell->getValue() . ' | ' . "\n"; } echo '
| ' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . ' | ' . "\n"; } echo '
instead of
.
You can use the following code to achieve this result:
$objWriter->setImagesRoot('http://www.example.com');
#### 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->setPreCalculateFormulas(false);
$objWriter->save("05featuredemo.htm");
#### 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
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");
#### Decimal and thousands separators
See section PHPExcel_Writer_CSV how to control the appearance of these.
## 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, âŚ
### PHPExcel_Writer_PDF
PHPExcelâs PDF Writer is a wrapper for a 3rd-Party PDF Rendering library such as tcPDF, mPDF or DomPDF. Prior to version 1.7.8 of PHPExcel, the tcPDF library was bundled with PHPExcel; but from version 1.7.8 this was removed. Instead, you must now install a PDF Rendering library yourself; but PHPExcel will work with a number of different libraries.
Currently, the following libraries are supported:
__Library__
__Version used for testing__
__Downloadable from__
__PHPExcel Internal Constant__
tcPDF
5.9
http://www.tcpdf.org/
PDF_RENDERER_TCPDF
mPDF
5.4
http://www.mpdf1.com/mpdf/
PDF_RENDERER_MPDF
domPDF
0.6.0 beta 3
http://code.google.com/p/dompdf/
PDF_RENDERER_DOMPDF
The different libraries have different strengths and weaknesses. Some generate better formatted output than others, some are faster or use less memory than others, while some generate smaller .pdf files. It is the developers choice which one they wish to use, appropriate to their own circumstances.
Before instantiating a Writer to generate PDF output, you will need to indicate which Rendering library you are using, and where it is located.
$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererLibrary = 'mPDF5.4';
$rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary;
if (!PHPExcel_Settings::setPdfRenderer(
$rendererName,
$rendererLibraryPath
)) {
die(
'Please set the $rendererName and $rendererLibraryPath values' .
PHP_EOL .
' as appropriate for your directory structure'
);
}
#### Writing a spreadsheet
Once you have identified the Renderer that you wish to use for PDF generation, you can write a .pdf file using the following code:
$objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
$objWriter->save("05featuredemo.pdf");
Please note that PHPExcel_Writer_PDF only outputs the first worksheet by default.
#### 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
PDF files can contain one or more worksheets. Therefore, you can specify which sheet to write to PDF:
$objWriter->setSheetIndex(0);
#### 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->setPreCalculateFormulas(false);
$objWriter->save("05featuredemo.pdf");
#### Decimal and thousands separators
See section PHPExcel_Writer_CSV how to control the appearance of these.
## Generating Excel files from templates (read, modify, write)
Readers and writers are the tools that allow you to generate Excel files from templates. This requires less coding effort than generating the Excel file from scratch, especially if your template has many styles, page setup properties, headers etc.
Here is an example how to open a template file, fill in a couple of fields and save it again:
$objPHPexcel = PHPExcel_IOFactory::load('template.xlsx');
$objWorksheet = $objPHPexcel->getActiveSheet();
$objWorksheet->getCell('A1')->setValue('John');
$objWorksheet->getCell('A2')->setValue('Smith');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
$objWriter->save('write.xls');
Notice that it is ok to load an xlsx file and generate an xls file.
# Credits
Please refer to the internet page [http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Credits&referringTitle=Home][22] for up-to-date credits.
# 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.
__PHPExcel_Style__
Array key:
Maps to property:
fill
font
borders
alignment
numberformat
protection
getFill()
getFont()
getBorders()
getAlignment()
getNumberFormat()
getProtection()
__PHPExcel_Style_Fill__
Array key:
Maps to property:
type
rotation
startcolor
endcolor
color
setFillType()
setRotation()
getStartColor()
getEndColor()
getStartColor()
__PHPExcel_Style_Font__
Array key:
Maps to property:
name
bold
italic
underline
strike
color
size
superScript
subScript
setName()
setBold()
setItalic()
setUnderline()
setStrikethrough()
getColor()
setSize()
setSuperScript()
setSubScript()
__PHPExcel_Style_Borders__
Array key:
Maps to property:
allborders
left
right
top
bottom
diagonal
vertical
horizontal
diagonaldirection
outline
getLeft(); getRight(); getTop(); getBottom()
getLeft()
getRight()
getTop()
getBottom()
getDiagonal()
getVertical()
getHorizontal()
setDiagonalDirection()
setOutline()
__PHPExcel_Style_Border__
Array key:
Maps to property:
style
color
setBorderStyle()
getColor()
__PHPExcel_Style_Alignment__
Array key:
Maps to property:
horizontal
vertical
rotation
wrap
shrinkToFit
indent
setHorizontal()
setVertical()
setTextRotation()
setWrapText()
setShrinkToFit()
setIndent()
__PHPExcel_Style_NumberFormat__
Array key:
Maps to property:
code
setFormatCode()
__PHPExcel_Style_Protection__
Array key:
Maps to property:
locked
hidden
setLocked()
setHidden()
[2]: http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Documents&referringTitle=Home
[3]: http://www.ecma-international.org/news/TC45_current_work/TC45_available_docs.htm
[4]: http://openxmldeveloper.org/articles/1970.aspx
[5]: http://www.microsoft.com/downloads/details.aspx?familyid=941b3470-3ae9-4aee-8f43-c6bb74cd1466&displaylang=en
[6]: http://www.codeplex.com/PackageExplorer/
[7]: http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=FAQ&referringTitle=Requirements
[8]: http://snaps.php.net/win32/php5.2-win32-latest.zip
[9]: http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=234150
[10]: http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=242712
[11]: http://http:/forum.joomla.org/viewtopic.php?f=304&t=433060
[12]: http://www.yiiframework.com/wiki/101/how-to-use-phpexcel-external-library-with-yii/
[13]: http://bakery.cakephp.org/articles/melgior/2010/01/26/simple-excel-spreadsheet-helper
[14]: http://www.flynsarmy.com/2010/07/phpexcel-module-for-kohana-3/
[15]: http://szpargalki.blogspot.com/2011/02/phpexcel-kohana-framework.html
[16]: http://typo3.org/documentation/document-library/extension-manuals/phpexcel_library/1.1.1/view/toc/0/
[17]: http://phpexcel.codeplex.com/discussions/211925
[18]: http://g-ernaelsten.developpez.com/tutoriels/excel2007/
[19]: http://journal.mycom.co.jp/articles/2009/03/06/phpexcel/index.html
[20]: http://be.php.net/manual/en/language.types.string.php#language.types.string.conversion
[21]: http://pear.php.net/package/Spreadsheet_Excel_Writer
[22]: http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Credits&referringTitle=Home