Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






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

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:

require_once 'PHPExcel/Shared/String.php'

PHPExcel_Shared_String::setDecimalSeparator('.');

PHPExcel_Shared_String::setThousandsSeparator(',');

 

German users will want to use the opposite values.

require_once 'PHPExcel/Shared/String.php'

PHPExcel_Shared_String::setDecimalSeparator(',');

PHPExcel_Shared_String::setThousandsSeparator('.');

 

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:

$objWriter->setSheetIndex(0);


Date: 2016-03-03; view: 925


<== previous page | next page ==>
Office 2003 compatibility pack | Setting the images root of the HTML file
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.008 sec.)