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(';');
CSV files can only contain one worksheet. Therefore, you can specify which sheet to write to CSV:
$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_CSV($objPHPExcel); $objWriter->setPreCalculateFormulas(false);
$objWriter->save("05featuredemo.csv");
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");
Decimal and thousands separators
If the worksheet you are exporting contains numbers with decimal or thousands separators then you should think about what characters you want to use for those before doing the export.
By default PHPExcel looks up in the server’s locale settings to decide what characters to use. But to avoid problems it is recommended to set the characters explicitly as shown below.
English users will want to use this before doing the export:
Note that the above code sets decimal and thousand separators as global options. This also affects how HTML and PDF is exported.
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.
i HTML limitations Please note that HTML file format has some limits regarding to styling cells, number formatting, …
PHPExcel_Writer_HTML
i Please note that PHPExcel_Writer_HTML only outputs the first worksheet by default.
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
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
HTML files can contain one or more worksheets. Therefore, you can specify which sheet to write to HTML: