Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






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:

http://support.microsoft.com/kb/25189

 

Reference for operator precedence in PHP:

http://www.php.net/operators

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:

http://be.php.net/manual/en/language.types.string.php#language.types.string.conversion

Reading and writing to file

As you already know from part 3.3 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.

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.

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");

 

i Note that automatic type resolving mode is slightly slower than explicit mode.


Date: 2016-03-03; view: 845


<== previous page | next page ==>
Setting the default column width | Office 2003 compatibility pack
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.005 sec.)