diff --git a/composer.json b/composer.json index 04a922c8..cd8de208 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "scripts": { "check": [ "php-cs-fixer fix --ansi --dry-run --diff", - "phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --standard=PSR2 -n", + "phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=samples/Header.php --standard=PSR2 -n", "phpunit --color=always" ] }, diff --git a/docs/Examples/Calculations/Database/DAVERAGE.php b/docs/Examples/Calculations/Database/DAVERAGE.php deleted file mode 100644 index be87d3ef..00000000 --- a/docs/Examples/Calculations/Database/DAVERAGE.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DAVERAGE

-

Returns the average of selected database entries.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The Average yield of Apple trees over 10\' in height'); - $worksheet->setCellValue('B12', '=DAVERAGE(A4:E10,"Yield",A1:B2)'); - - $worksheet->setCellValue('A13', 'The Average age of all Apple and Pear trees in the orchard'); - $worksheet->setCellValue('B13', '=DAVERAGE(A4:E10,3,A1:A3)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DAVERAGE() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DAVERAGE() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DCOUNT.php b/docs/Examples/Calculations/Database/DCOUNT.php deleted file mode 100644 index 4387d8fa..00000000 --- a/docs/Examples/Calculations/Database/DCOUNT.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DCOUNT

-

Counts the cells that contain numbers in a database.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height'); - $worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)'); - - $worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard'); - $worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DCOUNT() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DGET.php b/docs/Examples/Calculations/Database/DGET.php deleted file mode 100644 index 59dd9529..00000000 --- a/docs/Examples/Calculations/Database/DGET.php +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DGET

-

Extracts a single value from a column of a list or database that matches conditions that you specify.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The height of the Apple tree between 10\' and 16\' tall'); - $worksheet->setCellValue('B12', '=DGET(A4:E10,"Height",A1:F2)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - echo 'ALL' . '

'; - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DMAX.php b/docs/Examples/Calculations/Database/DMAX.php deleted file mode 100644 index bc0af306..00000000 --- a/docs/Examples/Calculations/Database/DMAX.php +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DMAX

-

Returns the maximum value from selected database entries.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The tallest tree in the orchard'); - $worksheet->setCellValue('B12', '=DMAX(A4:E10,"Height",A4:E10)'); - - $worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard'); - $worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - echo 'ALL' . '

'; - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DMIN.php b/docs/Examples/Calculations/Database/DMIN.php deleted file mode 100644 index 9f36786a..00000000 --- a/docs/Examples/Calculations/Database/DMIN.php +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DMIN

-

Returns the minimum value from selected database entries.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The shortest tree in the orchard'); - $worksheet->setCellValue('B12', '=DMIN(A4:E10,"Height",A4:E10)'); - - $worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard'); - $worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - echo 'ALL' . '

'; - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DMIN() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DMIN() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DPRODUCT.php b/docs/Examples/Calculations/Database/DPRODUCT.php deleted file mode 100644 index 92efcf08..00000000 --- a/docs/Examples/Calculations/Database/DPRODUCT.php +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DPRODUCT

-

Multiplies the values in a column of a list or database that match conditions that you specify.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The product of the yields of all Apple trees over 10\' in the orchard'); - $worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - echo 'ALL' . '

'; - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DSTDEV.php b/docs/Examples/Calculations/Database/DSTDEV.php deleted file mode 100644 index 8eaf133e..00000000 --- a/docs/Examples/Calculations/Database/DSTDEV.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DSTDEV

-

Estimates the standard deviation based on a sample of selected database entries.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees'); - $worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)'); - - $worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees'); - $worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DSTDEV() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DSTDEV() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DSTDEVP.php b/docs/Examples/Calculations/Database/DSTDEVP.php deleted file mode 100644 index ea9a5345..00000000 --- a/docs/Examples/Calculations/Database/DSTDEVP.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DSTDEVP

-

Calculates the standard deviation based on the entire population of selected database entries.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The standard deviation in the yield of Apple and Pear trees'); - $worksheet->setCellValue('B12', '=DSTDEVP(A4:E10,"Yield",A1:A3)'); - - $worksheet->setCellValue('A13', 'The standard deviation in height of Apple and Pear trees'); - $worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DSTDEVP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DSTDEVP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DVAR.php b/docs/Examples/Calculations/Database/DVAR.php deleted file mode 100644 index 2349845e..00000000 --- a/docs/Examples/Calculations/Database/DVAR.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DVAR

-

Estimates variance based on a sample from selected database entries.

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The estimated variance in the yield of Apple and Pear trees'); - $worksheet->setCellValue('B12', '=DVAR(A4:E10,"Yield",A1:A3)'); - - $worksheet->setCellValue('A13', 'The estimated variance in height of Apple and Pear trees'); - $worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DVAR() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DVAR() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/Database/DVARP.php b/docs/Examples/Calculations/Database/DVARP.php deleted file mode 100644 index a9b053a5..00000000 --- a/docs/Examples/Calculations/Database/DVARP.php +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DVARP

-

Calculates variance based on the entire population of selected database entries,

- getActiveSheet(); - - // Add some data - $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], - ['Apple', 18, 20, 14, 105.00], - ['Pear', 12, 12, 10, 96.00], - ['Cherry', 13, 14, 9, 105.00], - ['Apple', 14, 15, 10, 75.00], - ['Pear', 9, 8, 8, 76.80], - ['Apple', 8, 9, 6, 45.00], - ]; - $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], - ['="=Apple"', '>10', null, null, null, '<16'], - ['="=Pear"', null, null, null, null, null], - ]; - - $worksheet->fromArray($criteria, null, 'A1'); - $worksheet->fromArray($database, null, 'A4'); - - $worksheet->setCellValue('A12', 'The variance in the yield of Apple and Pear trees'); - $worksheet->setCellValue('B12', '=DVARP(A4:E10,"Yield",A1:A3)'); - - $worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees'); - $worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)'); - - echo '
'; - - echo '

Database

'; - - $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); - var_dump($databaseData); - - echo '
'; - - // Test the formulae - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A12')->getValue() . '
'; - echo 'DVARP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '

'; - - echo '

Criteria

'; - - $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); - var_dump($criteriaData); - - echo $worksheet->getCell('A13')->getValue() . '
'; - echo 'DVARP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue(); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Calculations/DateTime/DATE.php b/docs/Examples/Calculations/DateTime/DATE.php deleted file mode 100644 index 33330c97..00000000 --- a/docs/Examples/Calculations/DateTime/DATE.php +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DATE

-

Returns the serial number of a particular date.

- getActiveSheet(); - - // Add some data - $testDates = [[2012, 3, 26], [2012, 2, 29], [2012, 4, 1], [2012, 12, 25], - [2012, 10, 31], [2012, 11, 5], [2012, 1, 1], [2012, 3, 17], - [2011, 2, 29], [7, 5, 3], [2012, 13, 1], [2012, 11, 45], - [2012, 0, 0], [2012, 1, 0], [2012, 0, 1], - [2012, -2, 2], [2012, 2, -2], [2012, -2, -2], - ]; - $testDateCount = count($testDates); - - $worksheet->fromArray($testDates, null, 'A1', true); - - for ($row = 1; $row <= $testDateCount; ++$row) { - $worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')'); - $worksheet->setCellValue('E' . $row, '=D' . $row); - } - $worksheet->getStyle('E1:E' . $testDateCount) - ->getNumberFormat() - ->setFormatCode('yyyy-mmm-dd'); - - echo '
'; - - // Test the formulae - ?> - - - - - - - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - ?> -
Date ValueFormulaExcel DateStampFormatted DateStamp
YearMonthDay
', $worksheet->getCell('A' . $row)->getFormattedValue(), '', $worksheet->getCell('B' . $row)->getFormattedValue(), '', $worksheet->getCell('C' . $row)->getFormattedValue(), '', $worksheet->getCell('D' . $row)->getValue(), '', $worksheet->getCell('D' . $row)->getFormattedValue(), '', $worksheet->getCell('E' . $row)->getFormattedValue(), '
- - \ No newline at end of file diff --git a/docs/Examples/Calculations/DateTime/DATEVALUE.php b/docs/Examples/Calculations/DateTime/DATEVALUE.php deleted file mode 100644 index 535fdcce..00000000 --- a/docs/Examples/Calculations/DateTime/DATEVALUE.php +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

DATEVALUE

-

Converts a date in the form of text to a serial number.

- getActiveSheet(); - - // Add some data - $testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012', - '2012-Oct-31', '5th November', 'January 1st', 'April 2012', - '17-03', '03-2012', '29 Feb 2011', '03-05-07', - '03-MAY-07', '03-13-07', - ]; - $testDateCount = count($testDates); - - for ($row = 1; $row <= $testDateCount; ++$row) { - $worksheet->setCellValue('A' . $row, $testDates[$row - 1]); - $worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')'); - $worksheet->setCellValue('C' . $row, '=B' . $row); - } - - $worksheet->getStyle('C1:C' . $testDateCount) - ->getNumberFormat() - ->setFormatCode('yyyy-mmm-dd'); - - echo '
'; - - // Test the formulae - ?> -

Warning: The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel's DATEFORMAT() function.

- - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - ?> -
Date StringFormulaExcel DateStampFormatted DateStamp
', $worksheet->getCell('A' . $row)->getFormattedValue(), '', $worksheet->getCell('B' . $row)->getValue(), '', $worksheet->getCell('B' . $row)->getFormattedValue(), '', $worksheet->getCell('C' . $row)->getFormattedValue(), '
- - \ No newline at end of file diff --git a/docs/Examples/Calculations/DateTime/TIME.php b/docs/Examples/Calculations/DateTime/TIME.php deleted file mode 100644 index 09641074..00000000 --- a/docs/Examples/Calculations/DateTime/TIME.php +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

TIME

-

Returns the serial number of a particular time.

- getActiveSheet(); - - // Add some data - $testDates = [[3, 15], [13, 15], [15, 15, 15], [3, 15, 30], - [15, 15, 15], [5], [9, 15, 0], [9, 15, -1], - [13, -14, -15], [0, 0, -1], - ]; - $testDateCount = count($testDates); - - $worksheet->fromArray($testDates, null, 'A1', true); - - for ($row = 1; $row <= $testDateCount; ++$row) { - $worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')'); - $worksheet->setCellValue('E' . $row, '=D' . $row); - } - $worksheet->getStyle('E1:E' . $testDateCount) - ->getNumberFormat() - ->setFormatCode('hh:mm:ss'); - - echo '
'; - - // Test the formulae - ?> - - - - - - - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - ?> -
Date ValueFormulaExcel TimeStampFormatted TimeStamp
HourMinuteSecond
', $worksheet->getCell('A' . $row)->getFormattedValue(), '', $worksheet->getCell('B' . $row)->getFormattedValue(), '', $worksheet->getCell('C' . $row)->getFormattedValue(), '', $worksheet->getCell('D' . $row)->getValue(), '', $worksheet->getCell('D' . $row)->getFormattedValue(), '', $worksheet->getCell('E' . $row)->getFormattedValue(), '
- - \ No newline at end of file diff --git a/docs/Examples/Calculations/DateTime/TIMEVALUE.php b/docs/Examples/Calculations/DateTime/TIMEVALUE.php deleted file mode 100644 index 4cf27c81..00000000 --- a/docs/Examples/Calculations/DateTime/TIMEVALUE.php +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Examples - - - - -

TIMEVALUE

-

Converts a time in the form of text to a serial number.

- getActiveSheet(); - - // Add some data - $testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM', - ]; - $testDateCount = count($testDates); - - for ($row = 1; $row <= $testDateCount; ++$row) { - $worksheet->setCellValue('A' . $row, $testDates[$row - 1]); - $worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')'); - $worksheet->setCellValue('C' . $row, '=B' . $row); - } - - $worksheet->getStyle('C1:C' . $testDateCount) - ->getNumberFormat() - ->setFormatCode('hh:mm:ss'); - - echo '
'; - - // Test the formulae - ?> - - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - ?> -
Time StringFormulaExcel TimeStampFormatted TimeStamp
', $worksheet->getCell('A' . $row)->getFormattedValue(), '', $worksheet->getCell('B' . $row)->getValue(), '', $worksheet->getCell('B' . $row)->getFormattedValue(), '', $worksheet->getCell('C' . $row)->getFormattedValue(), '
- - \ No newline at end of file diff --git a/docs/Examples/Calculations/index.php b/docs/Examples/Calculations/index.php deleted file mode 100644 index ad03fe8e..00000000 --- a/docs/Examples/Calculations/index.php +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - PhpSpreadsheet Calculation Function Examples - - - - - PhpSpreadsheet Calculation Function Examples'; - - $exampleTypeList = glob('./*', GLOB_ONLYDIR); - - foreach ($exampleTypeList as $exampleType) { - echo '

' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Function Examples

'; - - $exampleList = glob('./' . $exampleType . '/*.php'); - - foreach ($exampleList as $exampleFile) { - $fileData = file_get_contents($exampleFile); - - $h1Pattern = '#

(.*?)

#'; - $h2Pattern = '#

(.*?)

#'; - - if (preg_match($h1Pattern, $fileData, $out)) { - $h1Text = $out[1]; - $h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : ''; - - echo '', $h1Text, '
'; - if ($h2Text > '') { - echo $h2Text, '
'; - } - } - } - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader01.php b/docs/Examples/Reader/exampleReader01.php deleted file mode 100644 index 1e343e5d..00000000 --- a/docs/Examples/Reader/exampleReader01.php +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #01 - - - - -

PhpSpreadsheet Reader Example #01

-

Simple File Reader using IOFactory::load()

- '; - $spreadsheet = IOFactory::load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader02.php b/docs/Examples/Reader/exampleReader02.php deleted file mode 100644 index c29e7993..00000000 --- a/docs/Examples/Reader/exampleReader02.php +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #02 - - - - -

PhpSpreadsheet Reader Example #02

-

Simple File Reader using a Specified Reader

- '; - $reader = new Xls(); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader03.php b/docs/Examples/Reader/exampleReader03.php deleted file mode 100644 index 750d52c2..00000000 --- a/docs/Examples/Reader/exampleReader03.php +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #03 - - - - -

PhpSpreadsheet Reader Example #03

-

Simple File Reader using the IOFactory to Return a Reader

- '; - $reader = IOFactory::createReader($inputFileType); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader04.php b/docs/Examples/Reader/exampleReader04.php deleted file mode 100644 index 7b8065d5..00000000 --- a/docs/Examples/Reader/exampleReader04.php +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #04 - - - - -

PhpSpreadsheet Reader Example #04

-

Simple File Reader using the IOFactory to Identify a Reader to Use

- '; - - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with the identified reader type
'; - $reader = IOFactory::createReader($inputFileType); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader05.php b/docs/Examples/Reader/exampleReader05.php deleted file mode 100644 index 2b06e8ac..00000000 --- a/docs/Examples/Reader/exampleReader05.php +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #05 - - - - -

PhpSpreadsheet Reader Example #05

-

Simple File Reader using the "Read Data Only" Option

- '; - $reader = IOFactory::createReader($inputFileType); - echo 'Turning Formatting off for Load
'; - $reader->setReadDataOnly(true); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader06.php b/docs/Examples/Reader/exampleReader06.php deleted file mode 100644 index 04e6b94e..00000000 --- a/docs/Examples/Reader/exampleReader06.php +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #06 - - - - -

PhpSpreadsheet Reader Example #06

-

Simple File Reader Loading All WorkSheets

- '; - $reader = IOFactory::createReader($inputFileType); - echo 'Loading all WorkSheets
'; - $reader->setLoadAllSheets(); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; - $loadedSheetNames = $spreadsheet->getSheetNames(); - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo $sheetIndex, ' -> ', $loadedSheetName, '
'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader07.php b/docs/Examples/Reader/exampleReader07.php deleted file mode 100644 index 7beabc82..00000000 --- a/docs/Examples/Reader/exampleReader07.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #07 - - - - -

PhpSpreadsheet Reader Example #07

-

Simple File Reader Loading a Single Named WorkSheet

- '; - $reader = IOFactory::createReader($inputFileType); - echo 'Loading Sheet "', $sheetname, '" only
'; - $reader->setLoadSheetsOnly($sheetname); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; - $loadedSheetNames = $spreadsheet->getSheetNames(); - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo $sheetIndex, ' -> ', $loadedSheetName, '
'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader08.php b/docs/Examples/Reader/exampleReader08.php deleted file mode 100644 index c9e574b9..00000000 --- a/docs/Examples/Reader/exampleReader08.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #08 - - - - -

PhpSpreadsheet Reader Example #08

-

Simple File Reader Loading Several Named WorkSheets

- '; - $reader = IOFactory::createReader($inputFileType); - echo 'Loading Sheet', ((count($sheetnames) == 1) ? '' : 's'), ' "', implode('" and "', $sheetnames), '" only
'; - $reader->setLoadSheetsOnly($sheetnames); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; - $loadedSheetNames = $spreadsheet->getSheetNames(); - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo $sheetIndex, ' -> ', $loadedSheetName, '
'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader09.php b/docs/Examples/Reader/exampleReader09.php deleted file mode 100644 index 1c5c4147..00000000 --- a/docs/Examples/Reader/exampleReader09.php +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #09 - - - - -

PhpSpreadsheet Reader Example #09

-

Simple File Reader Using a Read Filter

- = 1 && $row <= 7) { - if (in_array($column, range('A', 'E'))) { - return true; - } - } - - return false; - } - - } - - $filterSubset = new MyReadFilter(); - - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '
'; - $reader = IOFactory::createReader($inputFileType); - echo 'Loading Sheet "', $sheetname, '" only
'; - $reader->setLoadSheetsOnly($sheetname); - echo 'Loading Sheet using filter
'; - $reader->setReadFilter($filterSubset); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader10.php b/docs/Examples/Reader/exampleReader10.php deleted file mode 100644 index 6d4517eb..00000000 --- a/docs/Examples/Reader/exampleReader10.php +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #10 - - - - -

PhpSpreadsheet Reader Example #10

-

Simple File Reader Using a Configurable Read Filter

- _startRow = $startRow; - $this->_endRow = $endRow; - $this->_columns = $columns; - } - - public function readCell($column, $row, $worksheetName = '') - { - if ($row >= $this->_startRow && $row <= $this->_endRow) { - if (in_array($column, $this->_columns)) { - return true; - } - } - - return false; - } - - } - - $filterSubset = new MyReadFilter(9, 15, range('G', 'K')); - - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '
'; - $reader = IOFactory::createReader($inputFileType); - echo 'Loading Sheet "', $sheetname, '" only
'; - $reader->setLoadSheetsOnly($sheetname); - echo 'Loading Sheet using configurable filter
'; - $reader->setReadFilter($filterSubset); - $spreadsheet = $reader->load($inputFileName); - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader11.php b/docs/Examples/Reader/exampleReader11.php deleted file mode 100644 index 67c9ec4d..00000000 --- a/docs/Examples/Reader/exampleReader11.php +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #11 - - - - -

PhpSpreadsheet Reader Example #11

-

Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)

- _startRow = $startRow; - $this->_endRow = $startRow + $chunkSize; - } - - public function readCell($column, $row, $worksheetName = '') - { - // Only read the heading row, and the rows that were configured in the constructor - if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { - return true; - } - - return false; - } - - } - - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '
'; - /* Create a new Reader of the type defined in $inputFileType * */ - $reader = IOFactory::createReader($inputFileType); - - echo '
'; - - /* Define how many rows we want for each "chunk" * */ - $chunkSize = 20; - - /* Loop to read our worksheet in "chunk size" blocks * */ - for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { - echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '
'; - /* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read * */ - $chunkFilter = new chunkReadFilter($startRow, $chunkSize); - /* Tell the Reader that we want to use the new Read Filter that we've just Instantiated * */ - $reader->setReadFilter($chunkFilter); - /* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */ - $spreadsheet = $reader->load($inputFileName); - - // Do some processing here - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - echo '

'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader12.php b/docs/Examples/Reader/exampleReader12.php deleted file mode 100644 index f9055ae1..00000000 --- a/docs/Examples/Reader/exampleReader12.php +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #12 - - - - -

PhpSpreadsheet Reader Example #12

-

Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)

- _startRow = $startRow; - $this->_endRow = $startRow + $chunkSize; - } - - public function readCell($column, $row, $worksheetName = '') - { - // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow - if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { - return true; - } - - return false; - } - - } - - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '
'; - /* Create a new Reader of the type defined in $inputFileType * */ - $reader = IOFactory::createReader($inputFileType); - - echo '
'; - - /* Define how many rows we want to read for each "chunk" * */ - $chunkSize = 20; - /* Create a new Instance of our Read Filter * */ - $chunkFilter = new chunkReadFilter(); - - /* Tell the Reader that we want to use the Read Filter that we've Instantiated * */ - $reader->setReadFilter($chunkFilter); - - /* Loop to read our worksheet in "chunk size" blocks * */ - for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { - echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '
'; - /* Tell the Read Filter, the limits on which rows we want to read this iteration * */ - $chunkFilter->setRows($startRow, $chunkSize); - /* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */ - $spreadsheet = $reader->load($inputFileName); - - // Do some processing here - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - echo '

'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader13.php b/docs/Examples/Reader/exampleReader13.php deleted file mode 100644 index e13f1801..00000000 --- a/docs/Examples/Reader/exampleReader13.php +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #13 - - - - -

PhpSpreadsheet Reader Example #13

-

Simple File Reader for Multiple CSV Files

- '; - $spreadsheet = $reader->load($inputFileName); - $spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); - foreach ($inputFileNames as $sheet => $inputFileName) { - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' into WorkSheet #', ($sheet + 2), ' using IOFactory with a defined reader type of ', $inputFileType, '
'; - $reader->setSheetIndex($sheet + 1); - $reader->loadIntoExisting($inputFileName, $spreadsheet); - $spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); - } - - echo '
'; - - echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; - $loadedSheetNames = $spreadsheet->getSheetNames(); - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo 'Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '
'; - $spreadsheet->setActiveSheetIndexByName($loadedSheetName); - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - echo '

'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader14.php b/docs/Examples/Reader/exampleReader14.php deleted file mode 100644 index 98ab0b65..00000000 --- a/docs/Examples/Reader/exampleReader14.php +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #14 - - - - -

PhpSpreadsheet Reader Example #14

-

Reading a Large CSV file in "Chunks" to split across multiple Worksheets

- _startRow = $startRow; - $this->_endRow = $startRow + $chunkSize; - } - - public function readCell($column, $row, $worksheetName = '') - { - // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow - if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { - return true; - } - - return false; - } - - } - - echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '
'; - /* Create a new Reader of the type defined in $inputFileType * */ - $reader = IOFactory::createReader($inputFileType); - - echo '
'; - - /* Define how many rows we want to read for each "chunk" * */ - $chunkSize = 100; - /* Create a new Instance of our Read Filter * */ - $chunkFilter = new chunkReadFilter(); - - /* Tell the Reader that we want to use the Read Filter that we've Instantiated * */ - /* and that we want to store it in contiguous rows/columns * */ - $reader->setReadFilter($chunkFilter) - ->setContiguous(true); - - /* Instantiate a new PhpSpreadsheet object manually * */ - $spreadsheet = new Spreadsheet(); - - /* Set a sheet index * */ - $sheet = 0; - /* Loop to read our worksheet in "chunk size" blocks * */ - /** $startRow is set to 2 initially because we always read the headings in row #1 * */ - for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { - echo 'Loading WorkSheet #', ($sheet + 1), ' using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '
'; - /* Tell the Read Filter, the limits on which rows we want to read this iteration * */ - $chunkFilter->setRows($startRow, $chunkSize); - - /* Increment the worksheet index pointer for the Reader * */ - $reader->setSheetIndex($sheet); - /* Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object * */ - $reader->loadIntoExisting($inputFileName, $spreadsheet); - /* Set the worksheet title (to reference the "sheet" of data that we've loaded) * */ - /* and increment the sheet index as well * */ - $spreadsheet->getActiveSheet()->setTitle('Country Data #' . ( ++$sheet)); - } - - echo '
'; - - echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; - $loadedSheetNames = $spreadsheet->getSheetNames(); - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo 'Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '
'; - $spreadsheet->setActiveSheetIndexByName($loadedSheetName); - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true); - var_dump($sheetData); - echo '
'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader15.php b/docs/Examples/Reader/exampleReader15.php deleted file mode 100644 index be913444..00000000 --- a/docs/Examples/Reader/exampleReader15.php +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #15 - - - - -

PhpSpreadsheet Reader Example #15

-

Simple File Reader for Tab-Separated Value File using the Advanced Value Binder

- '; - $reader->setDelimiter("\t"); - $spreadsheet = $reader->load($inputFileName); - $spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); - - echo '
'; - - echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; - $loadedSheetNames = $spreadsheet->getSheetNames(); - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo 'Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Formatted)
'; - $spreadsheet->setActiveSheetIndexByName($loadedSheetName); - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - echo '
'; - } - - echo '
'; - - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo 'Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Unformatted)
'; - $spreadsheet->setActiveSheetIndexByName($loadedSheetName); - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, false, true); - var_dump($sheetData); - echo '
'; - } - - echo '
'; - - foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo 'Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Raw)
'; - $spreadsheet->setActiveSheetIndexByName($loadedSheetName); - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true); - var_dump($sheetData); - echo '
'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader16.php b/docs/Examples/Reader/exampleReader16.php deleted file mode 100644 index aa4bc469..00000000 --- a/docs/Examples/Reader/exampleReader16.php +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #16 - - - - -

PhpSpreadsheet Reader Example #16

-

Handling Loader Exceptions using Try/Catch

- '; - try { - $spreadsheet = IOFactory::load($inputFileName); - } catch (InvalidArgumentException $e) { - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); - } - - echo '
'; - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader17.php b/docs/Examples/Reader/exampleReader17.php deleted file mode 100644 index 3c6ebf30..00000000 --- a/docs/Examples/Reader/exampleReader17.php +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #17 - - - - -

PhpSpreadsheet Reader Example #17

-

Simple File Reader Loading Several Named WorkSheets

- '; - $reader = IOFactory::createReader($inputFileType); - - /* Read the list of Worksheet Names from the Workbook file * */ - echo 'Read the list of Worksheets in the WorkBook
'; - $worksheetNames = $reader->listWorksheetNames($inputFileName); - - echo 'There are ', count($worksheetNames), ' worksheet', ((count($worksheetNames) == 1) ? '' : 's'), ' in the workbook

'; - foreach ($worksheetNames as $worksheetName) { - echo $worksheetName, '
'; - } - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader18.php b/docs/Examples/Reader/exampleReader18.php deleted file mode 100644 index 68a478bb..00000000 --- a/docs/Examples/Reader/exampleReader18.php +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #18 - - - - -

PhpSpreadsheet Reader Example #18

-

Reading list of WorkSheets without loading entire file

- '; - - $reader = IOFactory::createReader($inputFileType); - $worksheetNames = $reader->listWorksheetNames($inputFileName); - - echo '

Worksheet Names

'; - echo '
    '; - foreach ($worksheetNames as $worksheetName) { - echo '
  1. ', $worksheetName, '
  2. '; - } - echo '
'; - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reader/exampleReader19.php b/docs/Examples/Reader/exampleReader19.php deleted file mode 100644 index dea2dd06..00000000 --- a/docs/Examples/Reader/exampleReader19.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - PhpSpreadsheet Reader Example #19 - - - - -

PhpSpreadsheet Reader Example #19

-

Reading WorkSheet information without loading entire file

- '; - - $reader = IOFactory::createReader($inputFileType); - $worksheetData = $reader->listWorksheetInfo($inputFileName); - - echo '

Worksheet Information

'; - echo '
    '; - foreach ($worksheetData as $worksheet) { - echo '
  1. ', $worksheet['worksheetName'], '
    '; - echo 'Rows: ', $worksheet['totalRows'], ' Columns: ', $worksheet['totalColumns'], '
    '; - echo 'Cell Range: A1:', $worksheet['lastColumnLetter'], $worksheet['totalRows']; - echo '
  2. '; - } - echo '
'; - ?> - - \ No newline at end of file diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php deleted file mode 100644 index 9085b394..00000000 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - PhpSpreadsheet Reading WorkBook Data Example #01 - - - - -

PhpSpreadsheet Reading WorkBook Data Example #01

-

Read the WorkBook Properties

- load($inputFileName); - - echo '
'; - - /* Read the document's creator property * */ - $creator = $spreadsheet->getProperties()->getCreator(); - echo 'Document Creator: ', $creator, '
'; - - /* Read the Date when the workbook was created (as a PHP timestamp value) * */ - $creationDatestamp = $spreadsheet->getProperties()->getCreated(); - /* Format the date and time using the standard PHP date() function * */ - $creationDate = date('l, d<\s\up>S F Y', $creationDatestamp); - $creationTime = date('g:i A', $creationDatestamp); - echo 'Created On: ', $creationDate, ' at ', $creationTime, '
'; - - /* Read the name of the last person to modify this workbook * */ - $modifiedBy = $spreadsheet->getProperties()->getLastModifiedBy(); - echo 'Last Modified By: ', $modifiedBy, '
'; - - /* Read the Date when the workbook was last modified (as a PHP timestamp value) * */ - $modifiedDatestamp = $spreadsheet->getProperties()->getModified(); - /* Format the date and time using the standard PHP date() function * */ - $modifiedDate = date('l, d<\s\up>S F Y', $modifiedDatestamp); - $modifiedTime = date('g:i A', $modifiedDatestamp); - echo 'Last Modified On: ', $modifiedDate, ' at ', $modifiedTime, '
'; - - /* Read the workbook title property * */ - $workbookTitle = $spreadsheet->getProperties()->getTitle(); - echo 'Title: ', $workbookTitle, '
'; - - /* Read the workbook description property * */ - $description = $spreadsheet->getProperties()->getDescription(); - echo 'Description: ', $description, '
'; - - /* Read the workbook subject property * */ - $subject = $spreadsheet->getProperties()->getSubject(); - echo 'Subject: ', $subject, '
'; - - /* Read the workbook keywords property * */ - $keywords = $spreadsheet->getProperties()->getKeywords(); - echo 'Keywords: ', $keywords, '
'; - - /* Read the workbook category property * */ - $category = $spreadsheet->getProperties()->getCategory(); - echo 'Category: ', $category, '
'; - - /* Read the workbook company property * */ - $company = $spreadsheet->getProperties()->getCompany(); - echo 'Company: ', $company, '
'; - - /* Read the workbook manager property * */ - $manager = $spreadsheet->getProperties()->getManager(); - echo 'Manager: ', $manager, '
'; - ?> - - diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php deleted file mode 100644 index b643f74b..00000000 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - PhpSpreadsheet Reading WorkBook Data Example #02 - - - - -

PhpSpreadsheet Reading WorkBook Data Example #02

-

Read a list of Custom Properties for a WorkBook

- load($inputFileName); - - echo '
'; - - /* Read an array list of any custom properties for this document * */ - $customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); - - echo 'Custom Property names:
'; - foreach ($customPropertyList as $customPropertyName) { - echo $customPropertyName, '
'; - } - ?> - - diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php deleted file mode 100644 index 432099aa..00000000 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - PhpSpreadsheet Reading WorkBook Data Example #03 - - - - -

PhpSpreadsheet Reading WorkBook Data Example #03

-

Read Custom Property Values for a WorkBook

- load($inputFileName); - - echo '
'; - - /* Read an array list of any custom properties for this document * */ - $customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); - - echo 'Custom Properties:
'; - /* Loop through the list of custom properties * */ - foreach ($customPropertyList as $customPropertyName) { - echo '', $customPropertyName, ': '; - /* Retrieve the property value * */ - $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName); - /* Retrieve the property type * */ - $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName); - - /* Manipulate properties as appropriate for display purposes * */ - switch ($propertyType) { - case 'i': // integer - $propertyType = 'integer number'; - break; - case 'f': // float - $propertyType = 'floating point number'; - break; - case 's': // string - $propertyType = 'string'; - break; - case 'd': // date - $propertyValue = date('l, d<\s\up>S F Y g:i A', $propertyValue); - $propertyType = 'date'; - break; - case 'b': // boolean - $propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE'; - $propertyType = 'boolean'; - break; - } - - echo $propertyValue, ' (', $propertyType, ')
'; - } - ?> - - diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php deleted file mode 100644 index 7299e783..00000000 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - PhpSpreadsheet Reading WorkBook Data Example #04 - - - - -

PhpSpreadsheet Reading WorkBook Data Example #04

-

Get a List of the Worksheets in a WorkBook

- load($inputFileName); - - echo '
'; - - echo 'Reading the number of Worksheets in the WorkBook
'; - /* Use the PhpSpreadsheet object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */ - $sheetCount = $spreadsheet->getSheetCount(); - echo 'There ', (($sheetCount == 1) ? 'is' : 'are'), ' ', $sheetCount, ' WorkSheet', (($sheetCount == 1) ? '' : 's'), ' in the WorkBook

'; - - echo 'Reading the names of Worksheets in the WorkBook
'; - /* Use the PhpSpreadsheet object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */ - $sheetNames = $spreadsheet->getSheetNames(); - foreach ($sheetNames as $sheetIndex => $sheetName) { - echo 'WorkSheet #', $sheetIndex, ' is named "', $sheetName, '"
'; - } - ?> - - diff --git a/docs/Examples/index.php b/docs/Examples/index.php deleted file mode 100644 index 9ff0929d..00000000 --- a/docs/Examples/index.php +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - PhpSpreadsheet Examples - - - - - PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples'; - - $exampleList = glob('./' . $exampleType . '/*.php'); - - foreach ($exampleList as $exampleFile) { - $fileData = file_get_contents($exampleFile); - - $h1Pattern = '#

(.*?)

#'; - $h2Pattern = '#

(.*?)

#'; - - if (preg_match($h1Pattern, $fileData, $out)) { - $h1Text = $out[1]; - $h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : ''; - - echo '', $h1Text, '
'; - if (($h2Text > '') && - (pathinfo($exampleType, PATHINFO_BASENAME) != 'Calculations')) { - echo $h2Text, '
'; - } - } - } - } - ?> - - \ No newline at end of file diff --git a/docs/topics/autofilters.md b/docs/topics/autofilters.md index f6b0c572..15be56f8 100644 --- a/docs/topics/autofilters.md +++ b/docs/topics/autofilters.md @@ -519,7 +519,7 @@ foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) { ->getCell( 'D'.$row->getRowIndex() )->getFormattedValue(), ' '; - echo EOL; + echo PHP_EOL; } } ``` diff --git a/docs/topics/reading-files.md b/docs/topics/reading-files.md index afd3db35..35ae7ed7 100644 --- a/docs/topics/reading-files.md +++ b/docs/topics/reading-files.md @@ -27,8 +27,8 @@ $inputFileName = './sampleData/example1.xls'; $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); ``` -> See Examples/Reader/exampleReader01.php for a working example of this -> code. +See `samples/Reader/01_Simple_file_reader_using_IOFactory.php` for a working +example of this code. The `load()` method will attempt to identify the file type, and instantiate a loader for that file type; using it to load the file and @@ -72,8 +72,8 @@ $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls(); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader02.php for a working example of this -> code. +See `samples/Reader/02_Simple_file_reader_using_a_specified_reader.php` +for a working example of this code. Alternatively, you can use the IO Factory's `createReader()` method to instantiate the reader object for you, simply telling it the file type @@ -95,8 +95,8 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader03.php for a working example of this -> code. +See `samples/Reader/03_Simple_file_reader_using_the_IOFactory_to_return_a_reader.php` +for a working example of this code. If you're uncertain of the filetype, you can use the IO Factory's identify() method to identify the reader that you need, before using the @@ -113,8 +113,8 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader04.php for a working example of this -> code. +See `samples/Reader/04_Simple_file_reader_using_the_IOFactory_to_identify_a_reader_to_use.php` +for a working example of this code. ## Spreadsheet Reader Options @@ -141,8 +141,8 @@ $reader->setReadDataOnly(true); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader05.php for a working example of this -> code. +See `samples/Reader/05_Simple_file_reader_using_the_read_data_only_option.php` +for a working example of this code. It is important to note that Workbooks (and PhpSpreadsheet) store dates and times as simple numeric values: they can only be distinguished from @@ -187,8 +187,8 @@ $reader->setLoadSheetsOnly($sheetname); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader07.php for a working example of this -> code. +See `samples/Reader/07_Simple_file_reader_loading_a_single_named_worksheet.php` +for a working example of this code. If you want to read more than just a single sheet, you can pass a list of sheet names as an array parameter to the `setLoadSheetsOnly()` method. @@ -206,8 +206,8 @@ $reader->setLoadSheetsOnly($sheetnames); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader08.php for a working example of this -> code. +See `samples/Reader/08_Simple_file_reader_loading_several_named_worksheets.php` +for a working example of this code. To reset this option to the default, you can call the `setLoadAllSheets()` method. @@ -224,8 +224,8 @@ $reader->setLoadAllSheets(); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader06.php for a working example of this -> code. +See `samples/Reader/06_Simple_file_reader_loading_all_worksheets.php` for a +working example of this code. Reading Only Named WorkSheets from a File applies to Readers: @@ -277,8 +277,8 @@ $reader->setReadFilter($filterSubset); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader09.php for a working example of this -> code. +See `samples/Reader/09_Simple_file_reader_using_a_read_filter.php` for a +working example of this code. This example is not particularly useful, because it can only be used in a very specific circumstance (when you only want cells in the range @@ -315,8 +315,8 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter $filterSubset = new MyReadFilter(9,15,range('G','K')); ``` -> See Examples/Reader/exampleReader10.php for a working example of this -> code. +See `samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php` +for a working example of this code. This can be particularly useful for conserving memory, by allowing you to read and process a large workbook in "chunks": an example of this @@ -329,7 +329,7 @@ $inputFileName = './sampleData/example2.xls'; /** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */ -class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter +class ChunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { private $_startRow = 0; private $_endRow = 0; @@ -357,7 +357,7 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); /** Define how many rows we want to read for each "chunk" **/ $chunkSize = 2048; /** Create a new Instance of our Read Filter **/ -$chunkFilter = new chunkReadFilter(); +$chunkFilter = new ChunkReadFilter(); /** Tell the Reader that we want to use the Read Filter **/ $reader->setReadFilter($chunkFilter); @@ -372,8 +372,8 @@ for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) { } ``` -> See Examples/Reader/exampleReader12.php for a working example of this -> code. +See `samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_` +for a working example of this code. Using Read Filters applies to: @@ -427,8 +427,8 @@ foreach($inputFileNames as $sheet => $inputFileName) { } ``` -> See Examples/Reader/exampleReader13.php for a working example of this -> code. +See `samples/Reader/13_Simple_file_reader_for_multiple_CSV_files.php` for a +working example of this code. Note that using the same sheet index for multiple sheets won't append files into the same sheet, but overwrite the results of the previous @@ -450,7 +450,7 @@ Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to by available disk space. This means that we wouldn’t ordinarily be able to read all the rows from a very large CSV file that exceeded those limits, and save it as an Xls or Xlsx file. However, by using Read -Filters to read the CSV file in "chunks" (using the chunkReadFilter +Filters to read the CSV file in "chunks" (using the ChunkReadFilter Class that we defined in [the above section](#reading-only-specific-columns-and-rows-from-a-file-read-filters), and the `setSheetIndex()` method of the `$reader`, we can split the CSV file across several individual worksheets. @@ -468,7 +468,7 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); /** Define how many rows we want to read for each "chunk" **/ $chunkSize = 65530; /** Create a new Instance of our Read Filter **/ -$chunkFilter = new chunkReadFilter(); +$chunkFilter = new ChunkReadFilter(); /** Tell the Reader that we want to use the Read Filter **/ /** and that we want to store it in contiguous rows/columns **/ @@ -497,8 +497,8 @@ for ($startRow = 2; $startRow <= 1000000; $startRow += $chunkSize) { } ``` -> See Examples/Reader/exampleReader14.php for a working example of this -> code. +See `samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php` +for a working example of this code. This code will read 65,530 rows at a time from the CSV file that we’re loading, and store each "chunk" in a new worksheet. @@ -542,8 +542,8 @@ $reader->setDelimiter("\t"); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader15.php for a working example of this -> code. +See `samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php` +for a working example of this code. In addition to the delimiter, you can also use the following methods to set other attributes for the data load: @@ -603,8 +603,8 @@ $reader->setDelimiter("\t"); $spreadsheet = $reader->load($inputFileName); ``` -> See Examples/Reader/exampleReader15.php for a working example of this -> code. +See `samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php` +for a working example of this code. Loading using a Value Binder applies to: @@ -636,8 +636,8 @@ try { } ``` -> See Examples/Reader/exampleReader16.php for a working example of this -> code. +See `samples/Reader/16_Handling_loader_exceptions_using_TryCatch.php` for a +working example of this code. ## Helper Methods @@ -665,8 +665,8 @@ foreach ($worksheetNames as $worksheetName) { echo ''; ``` -> See Examples/Reader/exampleReader18.php for a working example of this -> code. +See `samples/Reader/18_Reading_list_of_worksheets_without_loading_entire_file.php` +for a working example of this code. ### listWorksheetInfo @@ -691,5 +691,5 @@ foreach ($worksheetData as $worksheet) { echo ''; ``` -> See Examples/Reader/exampleReader19.php for a working example of this -> code. +See `samples/Reader/19_Reading_worksheet_information_without_loading_entire_file.php` +for a working example of this code. diff --git a/samples/05_Feature_demo.php b/samples/05_Feature_demo.php deleted file mode 100644 index 0fbb86a6..00000000 --- a/samples/05_Feature_demo.php +++ /dev/null @@ -1,7 +0,0 @@ -write($spreadsheet, __FILE__); diff --git a/samples/06_Largescale.php b/samples/06_Largescale.php deleted file mode 100644 index a5054c34..00000000 --- a/samples/06_Largescale.php +++ /dev/null @@ -1,8 +0,0 @@ -write($spreadsheet, __FILE__); diff --git a/samples/13_Calculation.php b/samples/13_Calculation.php deleted file mode 100644 index e143e9ab..00000000 --- a/samples/13_Calculation.php +++ /dev/null @@ -1,178 +0,0 @@ -log('List implemented functions'); -$calc = Calculation::getInstance(); -print_r($calc->getImplementedFunctionNames()); - -// Create new Spreadsheet object -$helper->log('Create new Spreadsheet object'); -$spreadsheet = new Spreadsheet(); - -// Add some data, we will use some formulas here -$helper->log('Add some data and formulas'); -$spreadsheet->getActiveSheet()->setCellValue('A14', 'Count:') - ->setCellValue('A15', 'Sum:') - ->setCellValue('A16', 'Max:') - ->setCellValue('A17', 'Min:') - ->setCellValue('A18', 'Average:') - ->setCellValue('A19', 'Median:') - ->setCellValue('A20', 'Mode:'); - -$spreadsheet->getActiveSheet()->setCellValue('A22', 'CountA:') - ->setCellValue('A23', 'MaxA:') - ->setCellValue('A24', 'MinA:'); - -$spreadsheet->getActiveSheet()->setCellValue('A26', 'StDev:') - ->setCellValue('A27', 'StDevA:') - ->setCellValue('A28', 'StDevP:') - ->setCellValue('A29', 'StDevPA:'); - -$spreadsheet->getActiveSheet()->setCellValue('A31', 'DevSq:') - ->setCellValue('A32', 'Var:') - ->setCellValue('A33', 'VarA:') - ->setCellValue('A34', 'VarP:') - ->setCellValue('A35', 'VarPA:'); - -$spreadsheet->getActiveSheet()->setCellValue('A37', 'Date:'); - -$spreadsheet->getActiveSheet()->setCellValue('B1', 'Range 1') - ->setCellValue('B2', 2) - ->setCellValue('B3', 8) - ->setCellValue('B4', 10) - ->setCellValue('B5', true) - ->setCellValue('B6', false) - ->setCellValue('B7', 'Text String') - ->setCellValue('B9', '22') - ->setCellValue('B10', 4) - ->setCellValue('B11', 6) - ->setCellValue('B12', 12); - -$spreadsheet->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)') - ->setCellValue('B15', '=SUM(B2:B12)') - ->setCellValue('B16', '=MAX(B2:B12)') - ->setCellValue('B17', '=MIN(B2:B12)') - ->setCellValue('B18', '=AVERAGE(B2:B12)') - ->setCellValue('B19', '=MEDIAN(B2:B12)') - ->setCellValue('B20', '=MODE(B2:B12)'); - -$spreadsheet->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)') - ->setCellValue('B23', '=MAXA(B2:B12)') - ->setCellValue('B24', '=MINA(B2:B12)'); - -$spreadsheet->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)') - ->setCellValue('B27', '=STDEVA(B2:B12)') - ->setCellValue('B28', '=STDEVP(B2:B12)') - ->setCellValue('B29', '=STDEVPA(B2:B12)'); - -$spreadsheet->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)') - ->setCellValue('B32', '=VAR(B2:B12)') - ->setCellValue('B33', '=VARA(B2:B12)') - ->setCellValue('B34', '=VARP(B2:B12)') - ->setCellValue('B35', '=VARPA(B2:B12)'); - -$spreadsheet->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)') - ->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )') - ->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")') - ->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )') - ->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )'); - -$spreadsheet->getActiveSheet()->setCellValue('C1', 'Range 2') - ->setCellValue('C2', 1) - ->setCellValue('C3', 2) - ->setCellValue('C4', 2) - ->setCellValue('C5', 3) - ->setCellValue('C6', 3) - ->setCellValue('C7', 3) - ->setCellValue('C8', '0') - ->setCellValue('C9', 4) - ->setCellValue('C10', 4) - ->setCellValue('C11', 4) - ->setCellValue('C12', 4); - -$spreadsheet->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)') - ->setCellValue('C15', '=SUM(C2:C12)') - ->setCellValue('C16', '=MAX(C2:C12)') - ->setCellValue('C17', '=MIN(C2:C12)') - ->setCellValue('C18', '=AVERAGE(C2:C12)') - ->setCellValue('C19', '=MEDIAN(C2:C12)') - ->setCellValue('C20', '=MODE(C2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)') - ->setCellValue('C23', '=MAXA(C2:C12)') - ->setCellValue('C24', '=MINA(C2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)') - ->setCellValue('C27', '=STDEVA(C2:C12)') - ->setCellValue('C28', '=STDEVP(C2:C12)') - ->setCellValue('C29', '=STDEVPA(C2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)') - ->setCellValue('C32', '=VAR(C2:C12)') - ->setCellValue('C33', '=VARA(C2:C12)') - ->setCellValue('C34', '=VARP(C2:C12)') - ->setCellValue('C35', '=VARPA(C2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('D1', 'Range 3') - ->setCellValue('D2', 2) - ->setCellValue('D3', 3) - ->setCellValue('D4', 4); - -$spreadsheet->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"'); - -$spreadsheet->getActiveSheet()->setCellValue('E12', 'Other functions') - ->setCellValue('E14', '=PI()') - ->setCellValue('E15', '=RAND()') - ->setCellValue('E16', '=RANDBETWEEN(5, 10)'); - -$spreadsheet->getActiveSheet()->setCellValue('E17', 'Count of both ranges:') - ->setCellValue('F17', '=COUNT(B2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('E18', 'Total of both ranges:') - ->setCellValue('F18', '=SUM(B2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:') - ->setCellValue('F19', '=MAX(B2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:') - ->setCellValue('F20', '=MIN(B2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('E21', 'Average of both ranges:') - ->setCellValue('F21', '=AVERAGE(B2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('E22', 'Median of both ranges:') - ->setCellValue('F22', '=MEDIAN(B2:C12)'); - -$spreadsheet->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:') - ->setCellValue('F23', '=MODE(B2:C12)'); - -// Calculated data -$helper->log('Calculated data'); -for ($col = 'B'; $col != 'G'; ++$col) { - for ($row = 14; $row <= 41; ++$row) { - if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) && - ($formula[0] == '=')) { - echo 'Value of ', $col, $row, ' [', $formula, ']: ', - $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue() . EOL; - } - } -} - -// -// If we set Pre Calculated Formulas to true then PhpSpreadsheet will calculate all formulae in the -// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae -// using functions or features (such as array formulae) that aren't yet supported by the calculation engine -// If the value is false (the default) for the Xlsx Writer, then MS Excel (or the application used to -// open the file) will need to recalculate values itself to guarantee that the correct results are available. -// -//$writer->setPreCalculateFormulas(true); - -// Save -$helper->write($spreadsheet, __FILE__); diff --git a/samples/10_Autofilter.php b/samples/Autofilter/10_Autofilter.php similarity index 98% rename from samples/10_Autofilter.php rename to samples/Autofilter/10_Autofilter.php index 7058e6a5..04d176ce 100644 --- a/samples/10_Autofilter.php +++ b/samples/Autofilter/10_Autofilter.php @@ -2,7 +2,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/10_Autofilter_selection_1.php b/samples/Autofilter/10_Autofilter_selection_1.php similarity index 99% rename from samples/10_Autofilter_selection_1.php rename to samples/Autofilter/10_Autofilter_selection_1.php index 1b34b019..9bc47f8b 100644 --- a/samples/10_Autofilter_selection_1.php +++ b/samples/Autofilter/10_Autofilter_selection_1.php @@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/10_Autofilter_selection_2.php b/samples/Autofilter/10_Autofilter_selection_2.php similarity index 99% rename from samples/10_Autofilter_selection_2.php rename to samples/Autofilter/10_Autofilter_selection_2.php index 9bfb254a..9d0afa0f 100644 --- a/samples/10_Autofilter_selection_2.php +++ b/samples/Autofilter/10_Autofilter_selection_2.php @@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/10_Autofilter_selection_display.php b/samples/Autofilter/10_Autofilter_selection_display.php similarity index 95% rename from samples/10_Autofilter_selection_display.php rename to samples/Autofilter/10_Autofilter_selection_display.php index 2be654d3..9a6e8c88 100644 --- a/samples/10_Autofilter_selection_display.php +++ b/samples/Autofilter/10_Autofilter_selection_display.php @@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); @@ -163,9 +163,8 @@ $spreadsheet->setActiveSheetIndex(0); $helper->log('Display filtered rows'); foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) { if ($spreadsheet->getActiveSheet()->getRowDimension($row->getRowIndex())->getVisible()) { - echo ' Row number - ', $row->getRowIndex(), ' '; - echo $spreadsheet->getActiveSheet()->getCell('C' . $row->getRowIndex())->getValue(), ' '; - echo $spreadsheet->getActiveSheet()->getCell('D' . $row->getRowIndex())->getFormattedValue(), ' '; - echo EOL; + $helper->log(' Row number - ' . $row->getRowIndex()); + $helper->log($spreadsheet->getActiveSheet()->getCell('C' . $row->getRowIndex())->getValue()); + $helper->log($spreadsheet->getActiveSheet()->getCell('D' . $row->getRowIndex())->getFormattedValue()); } } diff --git a/samples/01_Simple.php b/samples/Basic/01_Simple.php similarity index 98% rename from samples/01_Simple.php rename to samples/Basic/01_Simple.php index 3ba6ba05..02e39de0 100644 --- a/samples/01_Simple.php +++ b/samples/Basic/01_Simple.php @@ -2,7 +2,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $helper->log('Create new Spreadsheet object'); diff --git a/samples/01_Simple_download_ods.php b/samples/Basic/01_Simple_download_ods.php similarity index 93% rename from samples/01_Simple_download_ods.php rename to samples/Basic/01_Simple_download_ods.php index 4031eec6..50a35768 100644 --- a/samples/01_Simple_download_ods.php +++ b/samples/Basic/01_Simple_download_ods.php @@ -4,11 +4,11 @@ use PhpOffice\PhpSpreadsheet\Helper\Sample; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require_once __DIR__ . '/../src/Bootstrap.php'; +require_once __DIR__ . '/../../src/Bootstrap.php'; $helper = new Sample(); if ($helper->isCli()) { - echo 'This example should only be run from a Web Browser' . PHP_EOL; + $helper->log('This example should only be run from a Web Browser' . PHP_EOL); return; } diff --git a/samples/01_Simple_download_pdf.php b/samples/Basic/01_Simple_download_pdf.php similarity index 93% rename from samples/01_Simple_download_pdf.php rename to samples/Basic/01_Simple_download_pdf.php index 04c91a18..7f013194 100644 --- a/samples/01_Simple_download_pdf.php +++ b/samples/Basic/01_Simple_download_pdf.php @@ -5,11 +5,11 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require_once __DIR__ . '/../src/Bootstrap.php'; +require_once __DIR__ . '/../../src/Bootstrap.php'; $helper = new Sample(); if ($helper->isCli()) { - echo 'This example should only be run from a Web Browser' . PHP_EOL; + $helper->log('This example should only be run from a Web Browser' . PHP_EOL); return; } diff --git a/samples/01_Simple_download_xls.php b/samples/Basic/01_Simple_download_xls.php similarity index 93% rename from samples/01_Simple_download_xls.php rename to samples/Basic/01_Simple_download_xls.php index 71fcbc7e..94fb789e 100644 --- a/samples/01_Simple_download_xls.php +++ b/samples/Basic/01_Simple_download_xls.php @@ -4,11 +4,11 @@ use PhpOffice\PhpSpreadsheet\Helper\Sample; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require_once __DIR__ . '/../src/Bootstrap.php'; +require_once __DIR__ . '/../../src/Bootstrap.php'; $helper = new Sample(); if ($helper->isCli()) { - echo 'This example should only be run from a Web Browser' . PHP_EOL; + $helper->log('This example should only be run from a Web Browser' . PHP_EOL); return; } diff --git a/samples/01_Simple_download_xlsx.php b/samples/Basic/01_Simple_download_xlsx.php similarity index 93% rename from samples/01_Simple_download_xlsx.php rename to samples/Basic/01_Simple_download_xlsx.php index 45ba9bc3..4262b9cd 100644 --- a/samples/01_Simple_download_xlsx.php +++ b/samples/Basic/01_Simple_download_xlsx.php @@ -4,11 +4,11 @@ use PhpOffice\PhpSpreadsheet\Helper\Sample; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require_once __DIR__ . '/../src/Bootstrap.php'; +require_once __DIR__ . '/../../src/Bootstrap.php'; $helper = new Sample(); if ($helper->isCli()) { - echo 'This example should only be run from a Web Browser' . PHP_EOL; + $helper->log('This example should only be run from a Web Browser' . PHP_EOL); return; } diff --git a/samples/02_Types.php b/samples/Basic/02_Types.php similarity index 99% rename from samples/02_Types.php rename to samples/Basic/02_Types.php index 84bc5002..a61a9d6a 100644 --- a/samples/02_Types.php +++ b/samples/Basic/02_Types.php @@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/03_Formulas.php b/samples/Basic/03_Formulas.php similarity index 82% rename from samples/03_Formulas.php rename to samples/Basic/03_Formulas.php index 752b99c8..0d810738 100644 --- a/samples/03_Formulas.php +++ b/samples/Basic/03_Formulas.php @@ -2,7 +2,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); @@ -35,31 +35,31 @@ $spreadsheet->getActiveSheet()->setCellValue('C1', 'Range #2') ->setCellValue('C3', 11) ->setCellValue('C4', 17) ->setCellValue('C5', '=SUM(C2:C4)'); -$helper->log('Sum of Range #2 is ', $spreadsheet->getActiveSheet()->getCell('C5')->getCalculatedValue()); +$helper->log('Sum of Range #2 is ' . $spreadsheet->getActiveSheet()->getCell('C5')->getCalculatedValue()); $spreadsheet->getActiveSheet() ->setCellValue('A7', 'Total of both ranges:'); $spreadsheet->getActiveSheet() ->setCellValue('B7', '=SUM(B5:C5)'); -$helper->log('Sum of both Ranges is ', $spreadsheet->getActiveSheet()->getCell('B7')->getCalculatedValue()); +$helper->log('Sum of both Ranges is ' . $spreadsheet->getActiveSheet()->getCell('B7')->getCalculatedValue()); $spreadsheet->getActiveSheet() ->setCellValue('A8', 'Minimum of both ranges:'); $spreadsheet->getActiveSheet() ->setCellValue('B8', '=MIN(B2:C4)'); -$helper->log('Minimum value in either Range is ', $spreadsheet->getActiveSheet()->getCell('B8')->getCalculatedValue()); +$helper->log('Minimum value in either Range is ' . $spreadsheet->getActiveSheet()->getCell('B8')->getCalculatedValue()); $spreadsheet->getActiveSheet() ->setCellValue('A9', 'Maximum of both ranges:'); $spreadsheet->getActiveSheet() ->setCellValue('B9', '=MAX(B2:C4)'); -$helper->log('Maximum value in either Range is ', $spreadsheet->getActiveSheet()->getCell('B9')->getCalculatedValue()); +$helper->log('Maximum value in either Range is ' . $spreadsheet->getActiveSheet()->getCell('B9')->getCalculatedValue()); $spreadsheet->getActiveSheet() ->setCellValue('A10', 'Average of both ranges:'); $spreadsheet->getActiveSheet() ->setCellValue('B10', '=AVERAGE(B2:C4)'); -$helper->log('Average value of both Ranges is ', $spreadsheet->getActiveSheet()->getCell('B10')->getCalculatedValue()); +$helper->log('Average value of both Ranges is ' . $spreadsheet->getActiveSheet()->getCell('B10')->getCalculatedValue()); $spreadsheet->getActiveSheet() ->getColumnDimension('A') ->setAutoSize(true); diff --git a/samples/04_Printing.php b/samples/Basic/04_Printing.php similarity index 95% rename from samples/04_Printing.php rename to samples/Basic/04_Printing.php index e8854821..fc340a6c 100644 --- a/samples/04_Printing.php +++ b/samples/Basic/04_Printing.php @@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter; use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing; use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); @@ -41,7 +41,7 @@ $spreadsheet->getActiveSheet() $helper->log('Add a drawing to the header'); $drawing = new HeaderFooterDrawing(); $drawing->setName('PhpSpreadsheet logo'); -$drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png'); +$drawing->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png'); $drawing->setHeight(36); $spreadsheet->getActiveSheet() ->getHeaderFooter() diff --git a/samples/Basic/05_Feature_demo.php b/samples/Basic/05_Feature_demo.php new file mode 100644 index 00000000..a85ebbc2 --- /dev/null +++ b/samples/Basic/05_Feature_demo.php @@ -0,0 +1,7 @@ +write($spreadsheet, __FILE__); diff --git a/samples/Basic/06_Largescale.php b/samples/Basic/06_Largescale.php new file mode 100644 index 00000000..2e8a3e67 --- /dev/null +++ b/samples/Basic/06_Largescale.php @@ -0,0 +1,8 @@ +write($spreadsheet, __FILE__); diff --git a/samples/07_Reader.php b/samples/Basic/07_Reader.php similarity index 78% rename from samples/07_Reader.php rename to samples/Basic/07_Reader.php index 05186521..4d9bd79e 100644 --- a/samples/07_Reader.php +++ b/samples/Basic/07_Reader.php @@ -3,10 +3,10 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create temporary file that will be read -$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +$sampleSpreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $filename = $helper->getTemporaryFilename(); $writer = new Xlsx($sampleSpreadsheet); $writer->save($filename); diff --git a/samples/08_Conditional_formatting.php b/samples/Basic/08_Conditional_formatting.php similarity index 99% rename from samples/08_Conditional_formatting.php rename to samples/Basic/08_Conditional_formatting.php index 36c3aaee..e73fa3f6 100644 --- a/samples/08_Conditional_formatting.php +++ b/samples/Basic/08_Conditional_formatting.php @@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\Conditional; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/08_Conditional_formatting_2.php b/samples/Basic/08_Conditional_formatting_2.php similarity index 98% rename from samples/08_Conditional_formatting_2.php rename to samples/Basic/08_Conditional_formatting_2.php index 07d2361d..0bf4a30c 100644 --- a/samples/08_Conditional_formatting_2.php +++ b/samples/Basic/08_Conditional_formatting_2.php @@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\Conditional; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/09_Pagebreaks.php b/samples/Basic/09_Pagebreaks.php similarity index 98% rename from samples/09_Pagebreaks.php rename to samples/Basic/09_Pagebreaks.php index c4cf33af..31bc17a1 100644 --- a/samples/09_Pagebreaks.php +++ b/samples/Basic/09_Pagebreaks.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/11_Documentsecurity.php b/samples/Basic/11_Documentsecurity.php similarity index 98% rename from samples/11_Documentsecurity.php rename to samples/Basic/11_Documentsecurity.php index 0298e7ee..d92c7d4e 100644 --- a/samples/11_Documentsecurity.php +++ b/samples/Basic/11_Documentsecurity.php @@ -2,7 +2,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/12_CellProtection.php b/samples/Basic/12_CellProtection.php similarity index 97% rename from samples/12_CellProtection.php rename to samples/Basic/12_CellProtection.php index a84bb8a5..e29aa5e4 100644 --- a/samples/12_CellProtection.php +++ b/samples/Basic/12_CellProtection.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Protection; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/Basic/13_Calculation.php b/samples/Basic/13_Calculation.php new file mode 100644 index 00000000..4bbc296d --- /dev/null +++ b/samples/Basic/13_Calculation.php @@ -0,0 +1,176 @@ +log('List implemented functions'); +$calc = Calculation::getInstance(); +print_r($calc->getImplementedFunctionNames()); + +// Create new Spreadsheet object +$helper->log('Create new Spreadsheet object'); +$spreadsheet = new Spreadsheet(); + +// Add some data, we will use some formulas here +$helper->log('Add some data and formulas'); +$spreadsheet->getActiveSheet()->setCellValue('A14', 'Count:') + ->setCellValue('A15', 'Sum:') + ->setCellValue('A16', 'Max:') + ->setCellValue('A17', 'Min:') + ->setCellValue('A18', 'Average:') + ->setCellValue('A19', 'Median:') + ->setCellValue('A20', 'Mode:'); + +$spreadsheet->getActiveSheet()->setCellValue('A22', 'CountA:') + ->setCellValue('A23', 'MaxA:') + ->setCellValue('A24', 'MinA:'); + +$spreadsheet->getActiveSheet()->setCellValue('A26', 'StDev:') + ->setCellValue('A27', 'StDevA:') + ->setCellValue('A28', 'StDevP:') + ->setCellValue('A29', 'StDevPA:'); + +$spreadsheet->getActiveSheet()->setCellValue('A31', 'DevSq:') + ->setCellValue('A32', 'Var:') + ->setCellValue('A33', 'VarA:') + ->setCellValue('A34', 'VarP:') + ->setCellValue('A35', 'VarPA:'); + +$spreadsheet->getActiveSheet()->setCellValue('A37', 'Date:'); + +$spreadsheet->getActiveSheet()->setCellValue('B1', 'Range 1') + ->setCellValue('B2', 2) + ->setCellValue('B3', 8) + ->setCellValue('B4', 10) + ->setCellValue('B5', true) + ->setCellValue('B6', false) + ->setCellValue('B7', 'Text String') + ->setCellValue('B9', '22') + ->setCellValue('B10', 4) + ->setCellValue('B11', 6) + ->setCellValue('B12', 12); + +$spreadsheet->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)') + ->setCellValue('B15', '=SUM(B2:B12)') + ->setCellValue('B16', '=MAX(B2:B12)') + ->setCellValue('B17', '=MIN(B2:B12)') + ->setCellValue('B18', '=AVERAGE(B2:B12)') + ->setCellValue('B19', '=MEDIAN(B2:B12)') + ->setCellValue('B20', '=MODE(B2:B12)'); + +$spreadsheet->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)') + ->setCellValue('B23', '=MAXA(B2:B12)') + ->setCellValue('B24', '=MINA(B2:B12)'); + +$spreadsheet->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)') + ->setCellValue('B27', '=STDEVA(B2:B12)') + ->setCellValue('B28', '=STDEVP(B2:B12)') + ->setCellValue('B29', '=STDEVPA(B2:B12)'); + +$spreadsheet->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)') + ->setCellValue('B32', '=VAR(B2:B12)') + ->setCellValue('B33', '=VARA(B2:B12)') + ->setCellValue('B34', '=VARP(B2:B12)') + ->setCellValue('B35', '=VARPA(B2:B12)'); + +$spreadsheet->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)') + ->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )') + ->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")') + ->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )') + ->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )'); + +$spreadsheet->getActiveSheet()->setCellValue('C1', 'Range 2') + ->setCellValue('C2', 1) + ->setCellValue('C3', 2) + ->setCellValue('C4', 2) + ->setCellValue('C5', 3) + ->setCellValue('C6', 3) + ->setCellValue('C7', 3) + ->setCellValue('C8', '0') + ->setCellValue('C9', 4) + ->setCellValue('C10', 4) + ->setCellValue('C11', 4) + ->setCellValue('C12', 4); + +$spreadsheet->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)') + ->setCellValue('C15', '=SUM(C2:C12)') + ->setCellValue('C16', '=MAX(C2:C12)') + ->setCellValue('C17', '=MIN(C2:C12)') + ->setCellValue('C18', '=AVERAGE(C2:C12)') + ->setCellValue('C19', '=MEDIAN(C2:C12)') + ->setCellValue('C20', '=MODE(C2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)') + ->setCellValue('C23', '=MAXA(C2:C12)') + ->setCellValue('C24', '=MINA(C2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)') + ->setCellValue('C27', '=STDEVA(C2:C12)') + ->setCellValue('C28', '=STDEVP(C2:C12)') + ->setCellValue('C29', '=STDEVPA(C2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)') + ->setCellValue('C32', '=VAR(C2:C12)') + ->setCellValue('C33', '=VARA(C2:C12)') + ->setCellValue('C34', '=VARP(C2:C12)') + ->setCellValue('C35', '=VARPA(C2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('D1', 'Range 3') + ->setCellValue('D2', 2) + ->setCellValue('D3', 3) + ->setCellValue('D4', 4); + +$spreadsheet->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"'); + +$spreadsheet->getActiveSheet()->setCellValue('E12', 'Other functions') + ->setCellValue('E14', '=PI()') + ->setCellValue('E15', '=RAND()') + ->setCellValue('E16', '=RANDBETWEEN(5, 10)'); + +$spreadsheet->getActiveSheet()->setCellValue('E17', 'Count of both ranges:') + ->setCellValue('F17', '=COUNT(B2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('E18', 'Total of both ranges:') + ->setCellValue('F18', '=SUM(B2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:') + ->setCellValue('F19', '=MAX(B2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:') + ->setCellValue('F20', '=MIN(B2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('E21', 'Average of both ranges:') + ->setCellValue('F21', '=AVERAGE(B2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('E22', 'Median of both ranges:') + ->setCellValue('F22', '=MEDIAN(B2:C12)'); + +$spreadsheet->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:') + ->setCellValue('F23', '=MODE(B2:C12)'); + +// Calculated data +$helper->log('Calculated data'); +for ($col = 'B'; $col != 'G'; ++$col) { + for ($row = 14; $row <= 41; ++$row) { + if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) && + ($formula[0] == '=')) { + $helper->log('Value of ' . $col . $row . ' [' . $formula . ']: ' . $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue()); + } + } +} + +// +// If we set Pre Calculated Formulas to true then PhpSpreadsheet will calculate all formulae in the +// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae +// using functions or features (such as array formulae) that aren't yet supported by the calculation engine +// If the value is false (the default) for the Xlsx Writer, then MS Excel (or the application used to +// open the file) will need to recalculate values itself to guarantee that the correct results are available. +// +//$writer->setPreCalculateFormulas(true); +// Save +$helper->write($spreadsheet, __FILE__); diff --git a/samples/13_CalculationCyclicFormulae.php b/samples/Basic/13_CalculationCyclicFormulae.php similarity index 82% rename from samples/13_CalculationCyclicFormulae.php rename to samples/Basic/13_CalculationCyclicFormulae.php index 968c467c..006151bb 100644 --- a/samples/13_CalculationCyclicFormulae.php +++ b/samples/Basic/13_CalculationCyclicFormulae.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); @@ -24,8 +24,7 @@ for ($row = 1; $row <= 2; ++$row) { for ($col = 'A'; $col != 'C'; ++$col) { if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) && ($formula[0] == '=')) { - echo 'Value of ', $col, $row, ' [', $formula, ']: ', - $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue() . EOL; + $helper->log('Value of ' . $col . $row . ' [' . $formula . ']: ' . $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue()); } } } diff --git a/samples/14_Xls.php b/samples/Basic/14_Xls.php similarity index 71% rename from samples/14_Xls.php rename to samples/Basic/14_Xls.php index 03a38d28..ce27eb8c 100644 --- a/samples/14_Xls.php +++ b/samples/Basic/14_Xls.php @@ -2,8 +2,8 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +require __DIR__ . '/../Header.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $filename = $helper->getFilename(__FILE__, 'xls'); $writer = IOFactory::createWriter($spreadsheet, 'Xls'); diff --git a/samples/15_Datavalidation.php b/samples/Basic/15_Datavalidation.php similarity index 98% rename from samples/15_Datavalidation.php rename to samples/Basic/15_Datavalidation.php index 416a102a..45496ffb 100644 --- a/samples/15_Datavalidation.php +++ b/samples/Basic/15_Datavalidation.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Cell\DataValidation; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/16_Csv.php b/samples/Basic/16_Csv.php similarity index 90% rename from samples/16_Csv.php rename to samples/Basic/16_Csv.php index 0c1db51d..23c91d19 100644 --- a/samples/16_Csv.php +++ b/samples/Basic/16_Csv.php @@ -2,8 +2,8 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +require __DIR__ . '/../Header.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $helper->log('Write to CSV format'); $writer = IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',') diff --git a/samples/17_Html.php b/samples/Basic/17_Html.php similarity index 71% rename from samples/17_Html.php rename to samples/Basic/17_Html.php index 9ea9f0bd..b90b7212 100644 --- a/samples/17_Html.php +++ b/samples/Basic/17_Html.php @@ -2,8 +2,8 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +require __DIR__ . '/../Header.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $filename = $helper->getFilename(__FILE__, 'html'); $writer = IOFactory::createWriter($spreadsheet, 'Html'); diff --git a/samples/18_Extendedcalculation.php b/samples/Basic/18_Extendedcalculation.php similarity index 94% rename from samples/18_Extendedcalculation.php rename to samples/Basic/18_Extendedcalculation.php index e459e9d3..ad8aaaf4 100644 --- a/samples/18_Extendedcalculation.php +++ b/samples/Basic/18_Extendedcalculation.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // List functions $helper->log('List implemented functions'); @@ -64,6 +64,6 @@ $spreadsheet->getActiveSheet()->setCellValue('F14', '=COUNT(B2:C12)'); // Calculated data $helper->log('Calculated data'); -echo 'Value of B14 [=COUNT(B2:B12)]: ' . $spreadsheet->getActiveSheet()->getCell('B14')->getCalculatedValue() . "\r\n"; +$helper->log('Value of B14 [=COUNT(B2:B12)]: ' . $spreadsheet->getActiveSheet()->getCell('B14')->getCalculatedValue()); $helper->logEndingNotes(); diff --git a/samples/19_Namedrange.php b/samples/Basic/19_Namedrange.php similarity index 98% rename from samples/19_Namedrange.php rename to samples/Basic/19_Namedrange.php index 53c25660..ad9abc45 100644 --- a/samples/19_Namedrange.php +++ b/samples/Basic/19_Namedrange.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/20_Read_Excel2003XML.php b/samples/Basic/20_Read_Excel2003XML.php similarity index 70% rename from samples/20_Read_Excel2003XML.php rename to samples/Basic/20_Read_Excel2003XML.php index 6e2f464d..44425e20 100644 --- a/samples/20_Read_Excel2003XML.php +++ b/samples/Basic/20_Read_Excel2003XML.php @@ -2,9 +2,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$filename = __DIR__ . '/templates/Excel2003XMLTest.xml'; +$filename = __DIR__ . '/../templates/Excel2003XMLTest.xml'; $callStartTime = microtime(true); $spreadsheet = IOFactory::load($filename); $helper->logRead('Xml', $filename, $callStartTime); diff --git a/samples/20_Read_Gnumeric.php b/samples/Basic/20_Read_Gnumeric.php similarity index 70% rename from samples/20_Read_Gnumeric.php rename to samples/Basic/20_Read_Gnumeric.php index d2c598c4..2d6ce221 100644 --- a/samples/20_Read_Gnumeric.php +++ b/samples/Basic/20_Read_Gnumeric.php @@ -2,9 +2,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$filename = __DIR__ . '/templates/GnumericTest.gnumeric'; +$filename = __DIR__ . '/../templates/GnumericTest.gnumeric'; $callStartTime = microtime(true); $spreadsheet = IOFactory::load($filename); $helper->logRead('Gnumeric', $filename, $callStartTime); diff --git a/samples/20_Read_Ods.php b/samples/Basic/20_Read_Ods.php similarity index 71% rename from samples/20_Read_Ods.php rename to samples/Basic/20_Read_Ods.php index 10a8275c..64f54827 100644 --- a/samples/20_Read_Ods.php +++ b/samples/Basic/20_Read_Ods.php @@ -2,9 +2,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$filename = __DIR__ . '/templates/OOCalcTest.ods'; +$filename = __DIR__ . '/../templates/OOCalcTest.ods'; $callStartTime = microtime(true); $spreadsheet = IOFactory::load($filename); $helper->logRead('Ods', $filename, $callStartTime); diff --git a/samples/20_Read_Sylk.php b/samples/Basic/20_Read_Sylk.php similarity index 72% rename from samples/20_Read_Sylk.php rename to samples/Basic/20_Read_Sylk.php index c07c9647..1a064593 100644 --- a/samples/20_Read_Sylk.php +++ b/samples/Basic/20_Read_Sylk.php @@ -2,9 +2,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$filename = __DIR__ . '/templates/SylkTest.slk'; +$filename = __DIR__ . '/../templates/SylkTest.slk'; $callStartTime = microtime(true); $spreadsheet = IOFactory::load($filename); $helper->logRead('Slk', $filename, $callStartTime); diff --git a/samples/20_Read_Xls.php b/samples/Basic/20_Read_Xls.php similarity index 81% rename from samples/20_Read_Xls.php rename to samples/Basic/20_Read_Xls.php index 542f96a2..9e5fa014 100644 --- a/samples/20_Read_Xls.php +++ b/samples/Basic/20_Read_Xls.php @@ -2,9 +2,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; // Write temporary file $filename = $helper->getTemporaryFilename('xls'); diff --git a/samples/22_Heavily_formatted.php b/samples/Basic/22_Heavily_formatted.php similarity index 97% rename from samples/22_Heavily_formatted.php rename to samples/Basic/22_Heavily_formatted.php index feb2d957..d8259990 100644 --- a/samples/22_Heavily_formatted.php +++ b/samples/Basic/22_Heavily_formatted.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Fill; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/23_Sharedstyles.php b/samples/Basic/23_Sharedstyles.php similarity index 98% rename from samples/23_Sharedstyles.php rename to samples/Basic/23_Sharedstyles.php index 1405431c..0499e9ba 100644 --- a/samples/23_Sharedstyles.php +++ b/samples/Basic/23_Sharedstyles.php @@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Style; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Fill; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/24_Readfilter.php b/samples/Basic/24_Readfilter.php similarity index 90% rename from samples/24_Readfilter.php rename to samples/Basic/24_Readfilter.php index f5258604..844996f2 100644 --- a/samples/24_Readfilter.php +++ b/samples/Basic/24_Readfilter.php @@ -5,10 +5,10 @@ namespace PhpOffice\PhpSpreadsheet; use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Write temporary file -$largeSpreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php'; +$largeSpreadsheet = require __DIR__ . '/../templates/largeSpreadsheet.php'; $writer = new Xlsx($largeSpreadsheet); $filename = $helper->getTemporaryFilename(); $callStartTime = microtime(true); diff --git a/samples/25_In_memory_image.php b/samples/Basic/25_In_memory_image.php similarity index 97% rename from samples/25_In_memory_image.php rename to samples/Basic/25_In_memory_image.php index 5756bd3e..09b25c64 100644 --- a/samples/25_In_memory_image.php +++ b/samples/Basic/25_In_memory_image.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/26_Utf8.php b/samples/Basic/26_Utf8.php similarity index 93% rename from samples/26_Utf8.php rename to samples/Basic/26_Utf8.php index 790640a0..02b60801 100644 --- a/samples/26_Utf8.php +++ b/samples/Basic/26_Utf8.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Settings; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Change these values to select the PDF Rendering library that you wish to use // and its directory location on your server @@ -14,7 +14,7 @@ $rendererName = Settings::PDF_RENDERER_DOMPDF; // Read from Xlsx (.xlsx) template $helper->log('Load Xlsx template file'); $reader = IOFactory::createReader('Xlsx'); -$spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx'); +$spreadsheet = $reader->load(__DIR__ . '/../templates/26template.xlsx'); /* at this point, we could do some manipulations with the template, but we skip this step */ $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']); diff --git a/samples/27_Images_Xls.php b/samples/Basic/27_Images_Xls.php similarity index 66% rename from samples/27_Images_Xls.php rename to samples/Basic/27_Images_Xls.php index 4923efe2..4c20a9ac 100644 --- a/samples/27_Images_Xls.php +++ b/samples/Basic/27_Images_Xls.php @@ -2,12 +2,12 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Read from Xls (.xls) template $helper->log('Load Xlsx template file'); $reader = IOFactory::createReader('Xls'); -$spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls'); +$spreadsheet = $reader->load(__DIR__ . '/../templates/27template.xls'); // Save $helper->write($spreadsheet, __FILE__); diff --git a/samples/28_Iterator.php b/samples/Basic/28_Iterator.php similarity index 90% rename from samples/28_Iterator.php rename to samples/Basic/28_Iterator.php index 5dbb49e4..64981c5c 100644 --- a/samples/28_Iterator.php +++ b/samples/Basic/28_Iterator.php @@ -3,9 +3,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +$sampleSpreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $filename = $helper->getTemporaryFilename(); $writer = new Xlsx($sampleSpreadsheet); $callStartTime = microtime(true); diff --git a/samples/29_Advanced_value_binder.php b/samples/Basic/29_Advanced_value_binder.php similarity index 99% rename from samples/29_Advanced_value_binder.php rename to samples/Basic/29_Advanced_value_binder.php index 7f22c8f0..c0131cef 100644 --- a/samples/29_Advanced_value_binder.php +++ b/samples/Basic/29_Advanced_value_binder.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Set timezone $helper->log('Set timezone'); diff --git a/samples/30_Template.php b/samples/Basic/30_Template.php similarity index 91% rename from samples/30_Template.php rename to samples/Basic/30_Template.php index 4c6d867b..1f8a9629 100644 --- a/samples/30_Template.php +++ b/samples/Basic/30_Template.php @@ -3,11 +3,11 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Shared\Date; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $helper->log('Load from Xls template'); $reader = IOFactory::createReader('Xls'); -$spreadsheet = $reader->load(__DIR__ . '/templates/30template.xls'); +$spreadsheet = $reader->load(__DIR__ . '/../templates/30template.xls'); $helper->log('Add new data to the template'); $data = [['title' => 'Excel for dummies', diff --git a/samples/31_Document_properties_write.php b/samples/Basic/31_Document_properties_write.php similarity index 84% rename from samples/31_Document_properties_write.php rename to samples/Basic/31_Document_properties_write.php index 15936ffa..0611389f 100644 --- a/samples/31_Document_properties_write.php +++ b/samples/Basic/31_Document_properties_write.php @@ -3,10 +3,10 @@ use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $inputFileType = 'Xlsx'; -$inputFileName = __DIR__ . '/templates/31docproperties.xlsx'; +$inputFileName = __DIR__ . '/../templates/31docproperties.xlsx'; $spreadsheetReader = IOFactory::createReader($inputFileType); $callStartTime = microtime(true); @@ -26,7 +26,6 @@ $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); -// Echo memory peak usage $helper->logEndingNotes(); // Reread File @@ -38,9 +37,9 @@ $helper->log('Get properties'); $helper->log('Core Properties:'); $helper->log(' Created by - ' . $spreadsheet->getProperties()->getCreator()); -$helper->log(' Created on - ' . date('d-M-Y', $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getCreated())); +$helper->log(' Created on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getCreated())); $helper->log(' Last Modified by - ' . $spreadsheet->getProperties()->getLastModifiedBy()); -$helper->log(' Last Modified on - ' . date('d-M-Y', $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getModified())); +$helper->log(' Last Modified on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getModified())); $helper->log(' Title - ' . $spreadsheet->getProperties()->getTitle()); $helper->log(' Subject - ' . $spreadsheet->getProperties()->getSubject()); $helper->log(' Description - ' . $spreadsheet->getProperties()->getDescription()); @@ -66,5 +65,4 @@ foreach ($customProperties as $customProperty) { $helper->log(' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue); } -// Echo memory peak usage $helper->logEndingNotes(); diff --git a/samples/31_Document_properties_write_xls.php b/samples/Basic/31_Document_properties_write_xls.php similarity index 84% rename from samples/31_Document_properties_write_xls.php rename to samples/Basic/31_Document_properties_write_xls.php index a427be18..4f63e443 100644 --- a/samples/31_Document_properties_write_xls.php +++ b/samples/Basic/31_Document_properties_write_xls.php @@ -3,10 +3,10 @@ use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $inputFileType = 'Xls'; -$inputFileName = __DIR__ . '/templates/31docproperties.xls'; +$inputFileName = __DIR__ . '/../templates/31docproperties.xls'; $spreadsheetReader = IOFactory::createReader($inputFileType); $callStartTime = microtime(true); @@ -26,7 +26,6 @@ $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); -// Echo memory peak usage $helper->logEndingNotes(); // Reread File @@ -38,9 +37,9 @@ $helper->log('Get properties'); $helper->log('Core Properties:'); $helper->log(' Created by - ' . $spreadsheet->getProperties()->getCreator()); -$helper->log(' Created on - ' . date('d-M-Y', $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getCreated())); +$helper->log(' Created on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getCreated())); $helper->log(' Last Modified by - ' . $spreadsheet->getProperties()->getLastModifiedBy()); -$helper->log(' Last Modified on - ' . date('d-M-Y', $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getModified())); +$helper->log(' Last Modified on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getModified())); $helper->log(' Title - ' . $spreadsheet->getProperties()->getTitle()); $helper->log(' Subject - ' . $spreadsheet->getProperties()->getSubject()); $helper->log(' Description - ' . $spreadsheet->getProperties()->getDescription()); @@ -66,5 +65,4 @@ foreach ($customProperties as $customProperty) { $helper->log(' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue); } -// Echo memory peak usage $helper->logEndingNotes(); diff --git a/samples/37_Page_layout_view.php b/samples/Basic/37_Page_layout_view.php similarity index 96% rename from samples/37_Page_layout_view.php rename to samples/Basic/37_Page_layout_view.php index 2cdb3e12..725f004c 100644 --- a/samples/37_Page_layout_view.php +++ b/samples/Basic/37_Page_layout_view.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\SheetView; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/38_Clone_worksheet.php b/samples/Basic/38_Clone_worksheet.php similarity index 98% rename from samples/38_Clone_worksheet.php rename to samples/Basic/38_Clone_worksheet.php index b55b9025..dde310cb 100644 --- a/samples/38_Clone_worksheet.php +++ b/samples/Basic/38_Clone_worksheet.php @@ -2,7 +2,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/39_Dropdown.php b/samples/Basic/39_Dropdown.php similarity index 96% rename from samples/39_Dropdown.php rename to samples/Basic/39_Dropdown.php index bb68c3e9..79b6bbfb 100644 --- a/samples/39_Dropdown.php +++ b/samples/Basic/39_Dropdown.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Cell\DataValidation; use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); @@ -30,10 +30,10 @@ $continentColumn = 'D'; $column = 'F'; // Set data for dropdowns -$continents = glob('./data/continents/*'); +$continents = glob(__DIR__ . '/data/continents/*'); foreach ($continents as $key => $filename) { $continent = pathinfo($filename, PATHINFO_FILENAME); - echo "Loading $continent", EOL; + $helper->log("Loading $continent"); $continent = str_replace(' ', '_', $continent); $countries = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $countryCount = count($countries); diff --git a/samples/40_Duplicate_style.php b/samples/Basic/40_Duplicate_style.php similarity index 89% rename from samples/40_Duplicate_style.php rename to samples/Basic/40_Duplicate_style.php index 4a006f90..9d167641 100644 --- a/samples/40_Duplicate_style.php +++ b/samples/Basic/40_Duplicate_style.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $helper->log('Create new Spreadsheet object'); $spreadsheet = new Spreadsheet(); @@ -30,7 +30,7 @@ for ($col = 0; $col < 50; ++$col) { } } $d = microtime(true) - $t; -$helper->log('Add data (end), time: ' . round($d, 2) . ' s'); +$helper->log('Add data (end) . time: ' . round($d . 2) . ' s'); // Save $helper->write($spreadsheet, __FILE__); diff --git a/samples/41_Password.php b/samples/Basic/41_Password.php similarity index 71% rename from samples/41_Password.php rename to samples/Basic/41_Password.php index 6844b8e4..9aa8e6db 100644 --- a/samples/41_Password.php +++ b/samples/Basic/41_Password.php @@ -1,7 +1,7 @@ getSecurity()->setLockWindows(true); diff --git a/samples/42_RichText.php b/samples/Basic/42_RichText.php similarity index 98% rename from samples/42_RichText.php rename to samples/Basic/42_RichText.php index 88db805c..722b0326 100644 --- a/samples/42_RichText.php +++ b/samples/Basic/42_RichText.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\Helper\Html as HtmlHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); diff --git a/samples/43_Merge_workbooks.php b/samples/Basic/43_Merge_workbooks.php similarity index 81% rename from samples/43_Merge_workbooks.php rename to samples/Basic/43_Merge_workbooks.php index 57721a4a..86314b3b 100644 --- a/samples/43_Merge_workbooks.php +++ b/samples/Basic/43_Merge_workbooks.php @@ -2,16 +2,16 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $helper->log('Load MergeBook1 from Xlsx file'); -$filename1 = __DIR__ . '/templates/43mergeBook1.xlsx'; +$filename1 = __DIR__ . '/../templates/43mergeBook1.xlsx'; $callStartTime = microtime(true); $spreadsheet1 = IOFactory::load($filename1); $helper->logRead('Xlsx', $filename1, $callStartTime); $helper->log('Load MergeBook2 from Xlsx file'); -$filename2 = __DIR__ . '/templates/43mergeBook2.xlsx'; +$filename2 = __DIR__ . '/../templates/43mergeBook2.xlsx'; $callStartTime = microtime(true); $spreadsheet2 = IOFactory::load($filename2); $helper->logRead('Xlsx', $filename2, $callStartTime); diff --git a/samples/44_Worksheet_info.php b/samples/Basic/44_Worksheet_info.php similarity index 84% rename from samples/44_Worksheet_info.php rename to samples/Basic/44_Worksheet_info.php index cacb9ae6..33c0cd05 100644 --- a/samples/44_Worksheet_info.php +++ b/samples/Basic/44_Worksheet_info.php @@ -3,10 +3,10 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create temporary file that will be read -$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +$sampleSpreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $filename = $helper->getTemporaryFilename(); $writer = new Xlsx($sampleSpreadsheet); $writer->save($filename); diff --git a/samples/45_Quadratic_equation_solver.php b/samples/Basic/45_Quadratic_equation_solver.php similarity index 84% rename from samples/45_Quadratic_equation_solver.php rename to samples/Basic/45_Quadratic_equation_solver.php index 39f6685d..11edb856 100644 --- a/samples/45_Quadratic_equation_solver.php +++ b/samples/Basic/45_Quadratic_equation_solver.php @@ -1,7 +1,7 @@
Enter the coefficients for the Ax2 + Bx + C = 0 @@ -24,10 +24,10 @@ require __DIR__ . '/Header.php'; /** If the user has submitted the form, then we need to execute a calculation * */ if (isset($_POST['submit'])) { if ($_POST['A'] == 0) { - echo 'The equation is not quadratic'; + $helper->log('The equation is not quadratic'); } else { /* Calculate and Display the results * */ - echo '
Roots:
'; + $helper->log('
Roots:
'); $discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')'; $discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula); @@ -35,8 +35,8 @@ if (isset($_POST['submit'])) { $r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')'; $r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))'; - echo Calculation::getInstance()->calculateFormula($r1Formula) . '
'; - echo Calculation::getInstance()->calculateFormula($r2Formula) . '
'; + $helper->log(Calculation::getInstance()->calculateFormula($r1Formula)); + $helper->log(Calculation::getInstance()->calculateFormula($r2Formula)); $callEndTime = microtime(true); $helper->logEndingNotes(); } diff --git a/samples/46_ReadHtml.php b/samples/Basic/46_ReadHtml.php similarity index 78% rename from samples/46_ReadHtml.php rename to samples/Basic/46_ReadHtml.php index 838d2868..bd37af9b 100644 --- a/samples/46_ReadHtml.php +++ b/samples/Basic/46_ReadHtml.php @@ -5,9 +5,9 @@ error_reporting(0); use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$html = __DIR__ . '/templates/46readHtml.html'; +$html = __DIR__ . '/../templates/46readHtml.html'; $callStartTime = microtime(true); $objReader = IOFactory::createReader('Html'); diff --git a/samples/data/continents/Africa.txt b/samples/Basic/data/continents/Africa.txt similarity index 100% rename from samples/data/continents/Africa.txt rename to samples/Basic/data/continents/Africa.txt diff --git a/samples/data/continents/Asia.txt b/samples/Basic/data/continents/Asia.txt similarity index 100% rename from samples/data/continents/Asia.txt rename to samples/Basic/data/continents/Asia.txt diff --git a/samples/data/continents/Europe.txt b/samples/Basic/data/continents/Europe.txt similarity index 100% rename from samples/data/continents/Europe.txt rename to samples/Basic/data/continents/Europe.txt diff --git a/samples/data/continents/North America.txt b/samples/Basic/data/continents/North America.txt similarity index 100% rename from samples/data/continents/North America.txt rename to samples/Basic/data/continents/North America.txt diff --git a/samples/data/continents/Oceania.txt b/samples/Basic/data/continents/Oceania.txt similarity index 100% rename from samples/data/continents/Oceania.txt rename to samples/Basic/data/continents/Oceania.txt diff --git a/samples/data/continents/South America.txt b/samples/Basic/data/continents/South America.txt similarity index 100% rename from samples/data/continents/South America.txt rename to samples/Basic/data/continents/South America.txt diff --git a/samples/Calculations/Database/DAVERAGE.php b/samples/Calculations/Database/DAVERAGE.php new file mode 100644 index 00000000..92d84014 --- /dev/null +++ b/samples/Calculations/Database/DAVERAGE.php @@ -0,0 +1,56 @@ +log('Returns the average of selected database entries.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The Average yield of Apple trees over 10\' in height'); +$worksheet->setCellValue('B12', '=DAVERAGE(A4:E10,"Yield",A1:B2)'); + +$worksheet->setCellValue('A13', 'The Average age of all Apple and Pear trees in the orchard'); +$worksheet->setCellValue('B13', '=DAVERAGE(A4:E10,3,A1:A3)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DAVERAGE() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DAVERAGE() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DCOUNT.php b/samples/Calculations/Database/DCOUNT.php new file mode 100644 index 00000000..d869a4bc --- /dev/null +++ b/samples/Calculations/Database/DCOUNT.php @@ -0,0 +1,55 @@ +log('Counts the cells that contain numbers in a database.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height'); +$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)'); + +$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard'); +$worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DCOUNT() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DGET.php b/samples/Calculations/Database/DGET.php new file mode 100644 index 00000000..9f543c91 --- /dev/null +++ b/samples/Calculations/Database/DGET.php @@ -0,0 +1,52 @@ +log('Extracts a single value from a column of a list or database that matches conditions that you specify.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The height of the Apple tree between 10\' and 16\' tall'); +$worksheet->setCellValue('B12', '=DGET(A4:E10,"Height",A1:F2)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$helper->log('ALL'); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DMAX.php b/samples/Calculations/Database/DMAX.php new file mode 100644 index 00000000..c48928d4 --- /dev/null +++ b/samples/Calculations/Database/DMAX.php @@ -0,0 +1,55 @@ +log('Returns the maximum value from selected database entries.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The tallest tree in the orchard'); +$worksheet->setCellValue('B12', '=DMAX(A4:E10,"Height",A4:E10)'); + +$worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard'); +$worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$helper->log('ALL'); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DMIN.php b/samples/Calculations/Database/DMIN.php new file mode 100644 index 00000000..7bcaa206 --- /dev/null +++ b/samples/Calculations/Database/DMIN.php @@ -0,0 +1,55 @@ +log('Returns the minimum value from selected database entries.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The shortest tree in the orchard'); +$worksheet->setCellValue('B12', '=DMIN(A4:E10,"Height",A4:E10)'); + +$worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard'); +$worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$helper->log('ALL'); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DMIN() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DMIN() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DPRODUCT.php b/samples/Calculations/Database/DPRODUCT.php new file mode 100644 index 00000000..7c14ded6 --- /dev/null +++ b/samples/Calculations/Database/DPRODUCT.php @@ -0,0 +1,52 @@ +log('Multiplies the values in a column of a list or database that match conditions that you specify.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The product of the yields of all Apple trees over 10\' in the orchard'); +$worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$helper->log('ALL'); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DSTDEV.php b/samples/Calculations/Database/DSTDEV.php new file mode 100644 index 00000000..7f09fa59 --- /dev/null +++ b/samples/Calculations/Database/DSTDEV.php @@ -0,0 +1,56 @@ +log('Estimates the standard deviation based on a sample of selected database entries.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees'); +$worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)'); + +$worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees'); +$worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DSTDEV() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DSTDEV() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DSTDEVP.php b/samples/Calculations/Database/DSTDEVP.php new file mode 100644 index 00000000..9e999a80 --- /dev/null +++ b/samples/Calculations/Database/DSTDEVP.php @@ -0,0 +1,55 @@ +log('Calculates the standard deviation based on the entire population of selected database entries.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The standard deviation in the yield of Apple and Pear trees'); +$worksheet->setCellValue('B12', '=DSTDEVP(A4:E10,"Yield",A1:A3)'); + +$worksheet->setCellValue('A13', 'The standard deviation in height of Apple and Pear trees'); +$worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DSTDEVP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DSTDEVP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DVAR.php b/samples/Calculations/Database/DVAR.php new file mode 100644 index 00000000..2a5f8749 --- /dev/null +++ b/samples/Calculations/Database/DVAR.php @@ -0,0 +1,55 @@ +log('Estimates variance based on a sample from selected database entries.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The estimated variance in the yield of Apple and Pear trees'); +$worksheet->setCellValue('B12', '=DVAR(A4:E10,"Yield",A1:A3)'); + +$worksheet->setCellValue('A13', 'The estimated variance in height of Apple and Pear trees'); +$worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DVAR() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DVAR() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/Database/DVARP.php b/samples/Calculations/Database/DVARP.php new file mode 100644 index 00000000..4f57113b --- /dev/null +++ b/samples/Calculations/Database/DVARP.php @@ -0,0 +1,56 @@ +log('Calculates variance based on the entire population of selected database entries,'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], + ['Apple', 18, 20, 14, 105.00], + ['Pear', 12, 12, 10, 96.00], + ['Cherry', 13, 14, 9, 105.00], + ['Apple', 14, 15, 10, 75.00], + ['Pear', 9, 8, 8, 76.80], + ['Apple', 8, 9, 6, 45.00], +]; +$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], + ['="=Apple"', '>10', null, null, null, '<16'], + ['="=Pear"', null, null, null, null, null], +]; + +$worksheet->fromArray($criteria, null, 'A1'); +$worksheet->fromArray($database, null, 'A4'); + +$worksheet->setCellValue('A12', 'The variance in the yield of Apple and Pear trees'); +$worksheet->setCellValue('B12', '=DVARP(A4:E10,"Yield",A1:A3)'); + +$worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees'); +$worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)'); + +$helper->log('Database'); + +$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); +var_dump($databaseData); + +// Test the formulae +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A12')->getValue()); +$helper->log('DVARP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); + +$helper->log('Criteria'); + +$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); +var_dump($criteriaData); + +$helper->log($worksheet->getCell('A13')->getValue()); +$helper->log('DVARP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); diff --git a/samples/Calculations/DateTime/DATE.php b/samples/Calculations/DateTime/DATE.php new file mode 100644 index 00000000..5d758f76 --- /dev/null +++ b/samples/Calculations/DateTime/DATE.php @@ -0,0 +1,41 @@ +log('Returns the serial number of a particular date.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testDates = [[2012, 3, 26], [2012, 2, 29], [2012, 4, 1], [2012, 12, 25], + [2012, 10, 31], [2012, 11, 5], [2012, 1, 1], [2012, 3, 17], + [2011, 2, 29], [7, 5, 3], [2012, 13, 1], [2012, 11, 45], + [2012, 0, 0], [2012, 1, 0], [2012, 0, 1], + [2012, -2, 2], [2012, 2, -2], [2012, -2, -2], +]; +$testDateCount = count($testDates); + +$worksheet->fromArray($testDates, null, 'A1', true); + +for ($row = 1; $row <= $testDateCount; ++$row) { + $worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')'); + $worksheet->setCellValue('E' . $row, '=D' . $row); +} +$worksheet->getStyle('E1:E' . $testDateCount) + ->getNumberFormat() + ->setFormatCode('yyyy-mmm-dd'); + +// Test the formulae +for ($row = 1; $row <= $testDateCount; ++$row) { + $helper->log('Year: ' . $worksheet->getCell('A' . $row)->getFormattedValue()); + $helper->log('Month: ' . $worksheet->getCell('B' . $row)->getFormattedValue()); + $helper->log('Day: ' . $worksheet->getCell('C' . $row)->getFormattedValue()); + $helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue()); + $helper->log('Excel DateStamp: ' . $worksheet->getCell('D' . $row)->getFormattedValue()); + $helper->log('Formatted DateStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue()); + $helper->log(''); +} diff --git a/samples/Calculations/DateTime/DATEVALUE.php b/samples/Calculations/DateTime/DATEVALUE.php new file mode 100644 index 00000000..5cdb936d --- /dev/null +++ b/samples/Calculations/DateTime/DATEVALUE.php @@ -0,0 +1,39 @@ +log('Converts a date in the form of text to a serial number.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012', + '2012-Oct-31', '5th November', 'January 1st', 'April 2012', + '17-03', '03-2012', '29 Feb 2011', '03-05-07', + '03-MAY-07', '03-13-07', +]; +$testDateCount = count($testDates); + +for ($row = 1; $row <= $testDateCount; ++$row) { + $worksheet->setCellValue('A' . $row, $testDates[$row - 1]); + $worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')'); + $worksheet->setCellValue('C' . $row, '=B' . $row); +} + +$worksheet->getStyle('C1:C' . $testDateCount) + ->getNumberFormat() + ->setFormatCode('yyyy-mmm-dd'); + +// Test the formulae +$helper->log('Warning: The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel DATEFORMAT() function.'); +for ($row = 1; $row <= $testDateCount; ++$row) { + $helper->log('Date String: ' . $worksheet->getCell('A' . $row)->getFormattedValue()); + $helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue()); + $helper->log('Excel DateStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue()); + $helper->log('Formatted DateStamp' . $worksheet->getCell('C' . $row)->getFormattedValue()); + $helper->log(''); +} diff --git a/samples/Calculations/DateTime/TIME.php b/samples/Calculations/DateTime/TIME.php new file mode 100644 index 00000000..3d4208ad --- /dev/null +++ b/samples/Calculations/DateTime/TIME.php @@ -0,0 +1,39 @@ +log('Returns the serial number of a particular time.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testDates = [[3, 15], [13, 15], [15, 15, 15], [3, 15, 30], + [15, 15, 15], [5], [9, 15, 0], [9, 15, -1], + [13, -14, -15], [0, 0, -1], +]; +$testDateCount = count($testDates); + +$worksheet->fromArray($testDates, null, 'A1', true); + +for ($row = 1; $row <= $testDateCount; ++$row) { + $worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')'); + $worksheet->setCellValue('E' . $row, '=D' . $row); +} +$worksheet->getStyle('E1:E' . $testDateCount) + ->getNumberFormat() + ->setFormatCode('hh:mm:ss'); + +// Test the formulae +for ($row = 1; $row <= $testDateCount; ++$row) { + $helper->log('Hour: ' . $worksheet->getCell('A' . $row)->getFormattedValue()); + $helper->log('Minute: ' . $worksheet->getCell('B' . $row)->getFormattedValue()); + $helper->log('Second: ' . $worksheet->getCell('C' . $row)->getFormattedValue()); + $helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue()); + $helper->log('Excel TimeStamp: ' . $worksheet->getCell('D' . $row)->getFormattedValue()); + $helper->log('Formatted TimeStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue()); + $helper->log(''); +} diff --git a/samples/Calculations/DateTime/TIMEVALUE.php b/samples/Calculations/DateTime/TIMEVALUE.php new file mode 100644 index 00000000..f75393cd --- /dev/null +++ b/samples/Calculations/DateTime/TIMEVALUE.php @@ -0,0 +1,35 @@ +log('Converts a time in the form of text to a serial number.'); + +// Create new PhpSpreadsheet object +$spreadsheet = new Spreadsheet(); +$worksheet = $spreadsheet->getActiveSheet(); + +// Add some data +$testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM', +]; +$testDateCount = count($testDates); + +for ($row = 1; $row <= $testDateCount; ++$row) { + $worksheet->setCellValue('A' . $row, $testDates[$row - 1]); + $worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')'); + $worksheet->setCellValue('C' . $row, '=B' . $row); +} + +$worksheet->getStyle('C1:C' . $testDateCount) + ->getNumberFormat() + ->setFormatCode('hh:mm:ss'); + +// Test the formulae +for ($row = 1; $row <= $testDateCount; ++$row) { + $helper->log('Time String: ' . $worksheet->getCell('A' . $row)->getFormattedValue()); + $helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue()); + $helper->log('Excel TimeStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue()); + $helper->log('Formatted TimeStamp: ' . $worksheet->getCell('C' . $row)->getFormattedValue()); + $helper->log(''); +} diff --git a/samples/32_Chart_read_write.php b/samples/Chart/32_Chart_read_write.php similarity index 91% rename from samples/32_Chart_read_write.php rename to samples/Chart/32_Chart_read_write.php index 6668280c..38169720 100644 --- a/samples/32_Chart_read_write.php +++ b/samples/Chart/32_Chart_read_write.php @@ -2,15 +2,15 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $inputFileType = 'Xlsx'; -$inputFileNames = __DIR__ . '/templates/32readwrite*[0-9].xlsx'; +$inputFileNames = __DIR__ . '/../templates/32readwrite*[0-9].xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = []; for ($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = __DIR__ . '/../templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); @@ -31,7 +31,7 @@ foreach ($inputFileNames as $inputFileName) { $helper->log('Iterate worksheets looking at the charts'); foreach ($spreadsheet->getWorksheetIterator() as $worksheet) { $sheetName = $worksheet->getTitle(); - $helper->log('Worksheet: ', $sheetName); + $helper->log('Worksheet: ' . $sheetName); $chartNames = $worksheet->getChartNames(); if (empty($chartNames)) { @@ -45,7 +45,7 @@ foreach ($inputFileNames as $inputFileName) { } else { $caption = 'Untitled'; } - $helper->log(' ' . $chartName, ' - ', $caption); + $helper->log(' ' . $chartName . ' - ' . $caption); $indentation = str_repeat(' ', strlen($chartName) + 3); $groupCount = $chart->getPlotArea()->getPlotGroupCount(); if ($groupCount == 1) { diff --git a/samples/32_Chart_read_write_HTML.php b/samples/Chart/32_Chart_read_write_HTML.php similarity index 82% rename from samples/32_Chart_read_write_HTML.php rename to samples/Chart/32_Chart_read_write_HTML.php index ac2d1e1b..df859058 100644 --- a/samples/32_Chart_read_write_HTML.php +++ b/samples/Chart/32_Chart_read_write_HTML.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Settings; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Change these values to select the Rendering library that you wish to use // and its directory location on your server @@ -18,12 +18,12 @@ if (!Settings::setChartRenderer($rendererName, $rendererLibraryPath)) { } $inputFileType = 'Xlsx'; -$inputFileNames = __DIR__ . '/templates/36write*.xlsx'; +$inputFileNames = __DIR__ . '/../templates/36write*.xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = []; for ($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = __DIR__ . '/../templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); @@ -45,11 +45,11 @@ foreach ($inputFileNames as $inputFileName) { $helper->log('Iterate worksheets looking at the charts'); foreach ($spreadsheet->getWorksheetIterator() as $worksheet) { $sheetName = $worksheet->getTitle(); - echo 'Worksheet: ', $sheetName, EOL; + $helper->log('Worksheet: ' . $sheetName); $chartNames = $worksheet->getChartNames(); if (empty($chartNames)) { - echo ' There are no charts in this worksheet', EOL; + $helper->log(' There are no charts in this worksheet'); } else { natsort($chartNames); foreach ($chartNames as $i => $chartName) { @@ -59,12 +59,12 @@ foreach ($inputFileNames as $inputFileName) { } else { $caption = 'Untitled'; } - echo ' ', $chartName, ' - ', $caption, EOL; - echo str_repeat(' ', strlen($chartName) + 3); + $helper->log(' ' . $chartName . ' - ' . $caption); + $helper->log(str_repeat(' ', strlen($chartName) + 3)); $groupCount = $chart->getPlotArea()->getPlotGroupCount(); if ($groupCount == 1) { $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); - echo ' ', $chartType, EOL; + $helper->log(' ' . $chartType); } else { $chartTypes = []; for ($i = 0; $i < $groupCount; ++$i) { @@ -73,11 +73,11 @@ foreach ($inputFileNames as $inputFileName) { $chartTypes = array_unique($chartTypes); if (count($chartTypes) == 1) { $chartType = 'Multiple Plot ' . array_pop($chartTypes); - echo ' ', $chartType, EOL; + $helper->log(' ' . $chartType); } elseif (count($chartTypes) == 0) { - echo ' *** Type not yet implemented', EOL; + $helper->log(' *** Type not yet implemented'); } else { - echo ' Combination Chart', EOL; + $helper->log(' Combination Chart'); } } } diff --git a/samples/32_Chart_read_write_PDF.php b/samples/Chart/32_Chart_read_write_PDF.php similarity index 83% rename from samples/32_Chart_read_write_PDF.php rename to samples/Chart/32_Chart_read_write_PDF.php index ffd4ba40..446c67ac 100644 --- a/samples/32_Chart_read_write_PDF.php +++ b/samples/Chart/32_Chart_read_write_PDF.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Settings; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Change these values to select the Rendering library that you wish to use // for PDF files, and its directory location on your server @@ -26,12 +26,12 @@ if (!Settings::setChartRenderer($rendererName, $rendererLibraryPath)) { } $inputFileType = 'Xlsx'; -$inputFileNames = __DIR__ . '/templates/36write*.xlsx'; +$inputFileNames = __DIR__ . '/../templates/36write*.xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = []; for ($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = __DIR__ . '/../templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); @@ -53,11 +53,11 @@ foreach ($inputFileNames as $inputFileName) { $helper->log('Iterate worksheets looking at the charts'); foreach ($spreadsheet->getWorksheetIterator() as $worksheet) { $sheetName = $worksheet->getTitle(); - echo 'Worksheet: ', $sheetName, EOL; + $helper->log('Worksheet: ' . $sheetName); $chartNames = $worksheet->getChartNames(); if (empty($chartNames)) { - echo ' There are no charts in this worksheet', EOL; + $helper->log(' There are no charts in this worksheet'); } else { natsort($chartNames); foreach ($chartNames as $i => $chartName) { @@ -67,12 +67,12 @@ foreach ($inputFileNames as $inputFileName) { } else { $caption = 'Untitled'; } - echo ' ', $chartName, ' - ', $caption, EOL; - echo str_repeat(' ', strlen($chartName) + 3); + $helper->log(' ' . $chartName . ' - ' . $caption); + $helper->log(str_repeat(' ', strlen($chartName) + 3)); $groupCount = $chart->getPlotArea()->getPlotGroupCount(); if ($groupCount == 1) { $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); - echo ' ', $chartType, EOL; + $helper->log(' ' . $chartType); } else { $chartTypes = []; for ($i = 0; $i < $groupCount; ++$i) { @@ -81,11 +81,11 @@ foreach ($inputFileNames as $inputFileName) { $chartTypes = array_unique($chartTypes); if (count($chartTypes) == 1) { $chartType = 'Multiple Plot ' . array_pop($chartTypes); - echo ' ', $chartType, EOL; + $helper->log(' ' . $chartType); } elseif (count($chartTypes) == 0) { - echo ' *** Type not yet implemented', EOL; + $helper->log(' *** Type not yet implemented'); } else { - echo ' Combination Chart', EOL; + $helper->log(' Combination Chart'); } } } diff --git a/samples/33_Chart_create_area.php b/samples/Chart/33_Chart_create_area.php similarity index 98% rename from samples/33_Chart_create_area.php rename to samples/Chart/33_Chart_create_area.php index 2fba7ca7..c9f1c7f9 100644 --- a/samples/33_Chart_create_area.php +++ b/samples/Chart/33_Chart_create_area.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_bar.php b/samples/Chart/33_Chart_create_bar.php similarity index 75% rename from samples/33_Chart_create_bar.php rename to samples/Chart/33_Chart_create_bar.php index 96ac5ef7..a05cf927 100644 --- a/samples/33_Chart_create_bar.php +++ b/samples/Chart/33_Chart_create_bar.php @@ -2,9 +2,9 @@ use PhpOffice\PhpSpreadsheet\IOFactory; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; -$spreadsheet = require __DIR__ . '/templates/chartSpreadsheet.php'; +$spreadsheet = require __DIR__ . '/../templates/chartSpreadsheet.php'; // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); diff --git a/samples/33_Chart_create_bar_stacked.php b/samples/Chart/33_Chart_create_bar_stacked.php similarity index 98% rename from samples/33_Chart_create_bar_stacked.php rename to samples/Chart/33_Chart_create_bar_stacked.php index 86178d79..9cfdf781 100644 --- a/samples/33_Chart_create_bar_stacked.php +++ b/samples/Chart/33_Chart_create_bar_stacked.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_column.php b/samples/Chart/33_Chart_create_column.php similarity index 98% rename from samples/33_Chart_create_column.php rename to samples/Chart/33_Chart_create_column.php index 49d65c75..67e6fedb 100644 --- a/samples/33_Chart_create_column.php +++ b/samples/Chart/33_Chart_create_column.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_column_2.php b/samples/Chart/33_Chart_create_column_2.php similarity index 99% rename from samples/33_Chart_create_column_2.php rename to samples/Chart/33_Chart_create_column_2.php index f4afcedb..6b658ac4 100644 --- a/samples/33_Chart_create_column_2.php +++ b/samples/Chart/33_Chart_create_column_2.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_composite.php b/samples/Chart/33_Chart_create_composite.php similarity index 99% rename from samples/33_Chart_create_composite.php rename to samples/Chart/33_Chart_create_composite.php index 692209f8..11fe0b38 100644 --- a/samples/33_Chart_create_composite.php +++ b/samples/Chart/33_Chart_create_composite.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_line.php b/samples/Chart/33_Chart_create_line.php similarity index 98% rename from samples/33_Chart_create_line.php rename to samples/Chart/33_Chart_create_line.php index 0f1184f6..ea26191f 100644 --- a/samples/33_Chart_create_line.php +++ b/samples/Chart/33_Chart_create_line.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_multiple_charts.php b/samples/Chart/33_Chart_create_multiple_charts.php similarity index 99% rename from samples/33_Chart_create_multiple_charts.php rename to samples/Chart/33_Chart_create_multiple_charts.php index bd2cf606..64fbfe21 100644 --- a/samples/33_Chart_create_multiple_charts.php +++ b/samples/Chart/33_Chart_create_multiple_charts.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_pie.php b/samples/Chart/33_Chart_create_pie.php similarity index 99% rename from samples/33_Chart_create_pie.php rename to samples/Chart/33_Chart_create_pie.php index 3b5ea810..3693cfe1 100644 --- a/samples/33_Chart_create_pie.php +++ b/samples/Chart/33_Chart_create_pie.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_radar.php b/samples/Chart/33_Chart_create_radar.php similarity index 99% rename from samples/33_Chart_create_radar.php rename to samples/Chart/33_Chart_create_radar.php index 49053c95..50179ea2 100644 --- a/samples/33_Chart_create_radar.php +++ b/samples/Chart/33_Chart_create_radar.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_scatter.php b/samples/Chart/33_Chart_create_scatter.php similarity index 98% rename from samples/33_Chart_create_scatter.php rename to samples/Chart/33_Chart_create_scatter.php index f756c5a9..4d1b8745 100644 --- a/samples/33_Chart_create_scatter.php +++ b/samples/Chart/33_Chart_create_scatter.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/33_Chart_create_stock.php b/samples/Chart/33_Chart_create_stock.php similarity index 99% rename from samples/33_Chart_create_stock.php rename to samples/Chart/33_Chart_create_stock.php index 30c876b5..9606e52c 100644 --- a/samples/33_Chart_create_stock.php +++ b/samples/Chart/33_Chart_create_stock.php @@ -10,7 +10,7 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); diff --git a/samples/34_Chart_update.php b/samples/Chart/34_Chart_update.php similarity index 89% rename from samples/34_Chart_update.php rename to samples/Chart/34_Chart_update.php index bed5241d..638d2e0a 100644 --- a/samples/34_Chart_update.php +++ b/samples/Chart/34_Chart_update.php @@ -3,10 +3,10 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Create temporary file that will be read -$sampleSpreadsheet = require __DIR__ . '/templates/chartSpreadsheet.php'; +$sampleSpreadsheet = require __DIR__ . '/../templates/chartSpreadsheet.php'; $filename = $helper->getTemporaryFilename(); $writer = new Xlsx($sampleSpreadsheet); $writer->save($filename); diff --git a/samples/35_Chart_render.php b/samples/Chart/35_Chart_render.php similarity index 81% rename from samples/35_Chart_render.php rename to samples/Chart/35_Chart_render.php index a63b28ef..672e8554 100644 --- a/samples/35_Chart_render.php +++ b/samples/Chart/35_Chart_render.php @@ -3,7 +3,7 @@ use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Settings; -require __DIR__ . '/Header.php'; +require __DIR__ . '/../Header.php'; // Change these values to select the Rendering library that you wish to use // and its directory location on your server @@ -18,12 +18,12 @@ if (!Settings::setChartRenderer($rendererName, $rendererLibraryPath)) { } $inputFileType = 'Xlsx'; -$inputFileNames = __DIR__ . '/templates/32readwrite*[0-9].xlsx'; +$inputFileNames = __DIR__ . '/../templates/32readwrite*[0-9].xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = []; for ($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = __DIR__ . '/../templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); @@ -32,11 +32,11 @@ foreach ($inputFileNames as $inputFileName) { $inputFileNameShort = basename($inputFileName); if (!file_exists($inputFileName)) { - $helper->log('File ', $inputFileNameShort, ' does not exist'); + $helper->log('File ' . $inputFileNameShort . ' does not exist'); continue; } - $helper->log("Load Test from $inputFileType file ", $inputFileNameShort); + $helper->log("Load Test from $inputFileType file " . $inputFileNameShort); $reader = IOFactory::createReader($inputFileType); $reader->setIncludeCharts(true); @@ -45,7 +45,7 @@ foreach ($inputFileNames as $inputFileName) { $helper->log('Iterate worksheets looking at the charts'); foreach ($spreadsheet->getWorksheetIterator() as $worksheet) { $sheetName = $worksheet->getTitle(); - $helper->log('Worksheet: ', $sheetName); + $helper->log('Worksheet: ' . $sheetName); $chartNames = $worksheet->getChartNames(); if (empty($chartNames)) { @@ -59,7 +59,7 @@ foreach ($inputFileNames as $inputFileName) { } else { $caption = 'Untitled'; } - $helper->log(' ', $chartName, ' - ', $caption); + $helper->log(' ' . $chartName . ' - ' . $caption); $jpegFile = $helper->getFilename('35-' . $inputFileNameShort, 'jpg'); if (file_exists($jpegFile)) { @@ -68,7 +68,7 @@ foreach ($inputFileNames as $inputFileName) { try { $chart->render($jpegFile); } catch (Exception $e) { - $helper->log('Error rendering chart: ', $e->getMessage()); + $helper->log('Error rendering chart: ' . $e->getMessage()); } } } @@ -78,5 +78,4 @@ foreach ($inputFileNames as $inputFileName) { unset($spreadsheet); } -// Echo done $helper->log('Done rendering charts as images'); diff --git a/samples/Header.php b/samples/Header.php index 759ff1a8..0b5a4608 100644 --- a/samples/Header.php +++ b/samples/Header.php @@ -9,9 +9,6 @@ error_reporting(E_ALL); require_once __DIR__ . '/../src/Bootstrap.php'; $helper = new Sample(); -if (!defined('EOL')) { - define('EOL', $helper->isCli() ? PHP_EOL : '
'); -} // Return to the caller script when runs by CLI if ($helper->isCli()) { @@ -22,11 +19,11 @@ if ($helper->isCli()) { - - - - - + + + + +
@@ -39,23 +36,25 @@ if ($helper->isCli()) { - PHPSpreadsheet + PHPSpreadsheet
diff --git a/samples/21_Pdf_Domdf.php b/samples/Pdf/21_Pdf_Domdf.php similarity index 83% rename from samples/21_Pdf_Domdf.php rename to samples/Pdf/21_Pdf_Domdf.php index f13ca72c..6750da2f 100644 --- a/samples/21_Pdf_Domdf.php +++ b/samples/Pdf/21_Pdf_Domdf.php @@ -3,8 +3,8 @@ use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; -require __DIR__ . '/Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +require __DIR__ . '/../Header.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $helper->log('Hide grid lines'); $spreadsheet->getActiveSheet()->setShowGridLines(false); diff --git a/samples/21_Pdf_TCPDF.php b/samples/Pdf/21_Pdf_TCPDF.php similarity index 83% rename from samples/21_Pdf_TCPDF.php rename to samples/Pdf/21_Pdf_TCPDF.php index 1bf75c84..683ba547 100644 --- a/samples/21_Pdf_TCPDF.php +++ b/samples/Pdf/21_Pdf_TCPDF.php @@ -3,8 +3,8 @@ use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; -require __DIR__ . '/Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +require __DIR__ . '/../Header.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $helper->log('Hide grid lines'); $spreadsheet->getActiveSheet()->setShowGridLines(false); diff --git a/samples/21_Pdf_mPDF.php b/samples/Pdf/21_Pdf_mPDF.php similarity index 83% rename from samples/21_Pdf_mPDF.php rename to samples/Pdf/21_Pdf_mPDF.php index 8e46f838..1d455c5b 100644 --- a/samples/21_Pdf_mPDF.php +++ b/samples/Pdf/21_Pdf_mPDF.php @@ -3,8 +3,8 @@ use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; -require __DIR__ . '/Header.php'; -$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; +require __DIR__ . '/../Header.php'; +$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php'; $helper->log('Hide grid lines'); $spreadsheet->getActiveSheet()->setShowGridLines(false); diff --git a/samples/Reader/01_Simple_file_reader_using_IOFactory.php b/samples/Reader/01_Simple_file_reader_using_IOFactory.php new file mode 100644 index 00000000..584fd5be --- /dev/null +++ b/samples/Reader/01_Simple_file_reader_using_IOFactory.php @@ -0,0 +1,11 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory to identify the format'); +$spreadsheet = IOFactory::load($inputFileName); +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/02_Simple_file_reader_using_a_specified_reader.php b/samples/Reader/02_Simple_file_reader_using_a_specified_reader.php new file mode 100644 index 00000000..9a705123 --- /dev/null +++ b/samples/Reader/02_Simple_file_reader_using_a_specified_reader.php @@ -0,0 +1,13 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using ' . Xls::class); +$reader = new Xls(); +$spreadsheet = $reader->load($inputFileName); + +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/03_Simple_file_reader_using_the_IOFactory_to_return_a_reader.php b/samples/Reader/03_Simple_file_reader_using_the_IOFactory_to_return_a_reader.php new file mode 100644 index 00000000..305651de --- /dev/null +++ b/samples/Reader/03_Simple_file_reader_using_the_IOFactory_to_return_a_reader.php @@ -0,0 +1,15 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$spreadsheet = $reader->load($inputFileName); + +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/04_Simple_file_reader_using_the_IOFactory_to_identify_a_reader_to_use.php b/samples/Reader/04_Simple_file_reader_using_the_IOFactory_to_identify_a_reader_to_use.php new file mode 100644 index 00000000..98aabfc6 --- /dev/null +++ b/samples/Reader/04_Simple_file_reader_using_the_IOFactory_to_identify_a_reader_to_use.php @@ -0,0 +1,17 @@ +log('File ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' has been identified as an ' . $inputFileType . ' file'); + +$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with the identified reader type'); +$reader = IOFactory::createReader($inputFileType); +$spreadsheet = $reader->load($inputFileName); + +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/05_Simple_file_reader_using_the_read_data_only_option.php b/samples/Reader/05_Simple_file_reader_using_the_read_data_only_option.php new file mode 100644 index 00000000..d3ce9d82 --- /dev/null +++ b/samples/Reader/05_Simple_file_reader_using_the_read_data_only_option.php @@ -0,0 +1,17 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$helper->log('Turning Formatting off for Load'); +$reader->setReadDataOnly(true); +$spreadsheet = $reader->load($inputFileName); + +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/06_Simple_file_reader_loading_all_worksheets.php b/samples/Reader/06_Simple_file_reader_loading_all_worksheets.php new file mode 100644 index 00000000..5507c52b --- /dev/null +++ b/samples/Reader/06_Simple_file_reader_loading_all_worksheets.php @@ -0,0 +1,20 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$helper->log('Loading all WorkSheets'); +$reader->setLoadAllSheets(); +$spreadsheet = $reader->load($inputFileName); + +$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); +$loadedSheetNames = $spreadsheet->getSheetNames(); +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log($sheetIndex . ' -> ' . $loadedSheetName); +} diff --git a/samples/Reader/07_Simple_file_reader_loading_a_single_named_worksheet.php b/samples/Reader/07_Simple_file_reader_loading_a_single_named_worksheet.php new file mode 100644 index 00000000..142a17f8 --- /dev/null +++ b/samples/Reader/07_Simple_file_reader_loading_a_single_named_worksheet.php @@ -0,0 +1,21 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$helper->log('Loading Sheet "' . $sheetname . '" only'); +$reader->setLoadSheetsOnly($sheetname); +$spreadsheet = $reader->load($inputFileName); + +$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); +$loadedSheetNames = $spreadsheet->getSheetNames(); +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log($sheetIndex . ' -> ' . $loadedSheetName); +} diff --git a/samples/Reader/08_Simple_file_reader_loading_several_named_worksheets.php b/samples/Reader/08_Simple_file_reader_loading_several_named_worksheets.php new file mode 100644 index 00000000..66efc3e0 --- /dev/null +++ b/samples/Reader/08_Simple_file_reader_loading_several_named_worksheets.php @@ -0,0 +1,21 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$helper->log('Loading Sheet' . ((count($sheetnames) == 1) ? '' : 's') . ' "' . implode('" and "', $sheetnames) . '" only'); +$reader->setLoadSheetsOnly($sheetnames); +$spreadsheet = $reader->load($inputFileName); + +$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); +$loadedSheetNames = $spreadsheet->getSheetNames(); +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log($sheetIndex . ' -> ' . $loadedSheetName); +} diff --git a/samples/Reader/09_Simple_file_reader_using_a_read_filter.php b/samples/Reader/09_Simple_file_reader_using_a_read_filter.php new file mode 100644 index 00000000..68100989 --- /dev/null +++ b/samples/Reader/09_Simple_file_reader_using_a_read_filter.php @@ -0,0 +1,40 @@ += 1 && $row <= 7) { + if (in_array($column, range('A', 'E'))) { + return true; + } + } + + return false; + } +} + +$filterSubset = new MyReadFilter(); + +$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$helper->log('Loading Sheet "' . $sheetname . '" only'); +$reader->setLoadSheetsOnly($sheetname); +$helper->log('Loading Sheet using filter'); +$reader->setReadFilter($filterSubset); +$spreadsheet = $reader->load($inputFileName); + +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php b/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php new file mode 100644 index 00000000..e2f7c32c --- /dev/null +++ b/samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php @@ -0,0 +1,50 @@ +_startRow = $startRow; + $this->_endRow = $endRow; + $this->_columns = $columns; + } + + public function readCell($column, $row, $worksheetName = '') + { + if ($row >= $this->_startRow && $row <= $this->_endRow) { + if (in_array($column, $this->_columns)) { + return true; + } + } + + return false; + } +} + +$filterSubset = new MyReadFilter(9, 15, range('G', 'K')); + +$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); +$helper->log('Loading Sheet "' . $sheetname . '" only'); +$reader->setLoadSheetsOnly($sheetname); +$helper->log('Loading Sheet using configurable filter'); +$reader->setReadFilter($filterSubset); +$spreadsheet = $reader->load($inputFileName); + +$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); +var_dump($sheetData); diff --git a/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php b/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php new file mode 100644 index 00000000..a71cac70 --- /dev/null +++ b/samples/Reader/11_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_1).php @@ -0,0 +1,63 @@ +_startRow = $startRow; + $this->_endRow = $startRow + $chunkSize; + } + + public function readCell($column, $row, $worksheetName = '') + { + // Only read the heading row, and the rows that were configured in the constructor + if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { + return true; + } + + return false; + } +} + +$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +/* Create a new Reader of the type defined in $inputFileType * */ +$reader = IOFactory::createReader($inputFileType); + +/* Define how many rows we want for each "chunk" * */ +$chunkSize = 20; + +/* Loop to read our worksheet in "chunk size" blocks * */ +for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { + $helper->log('Loading WorkSheet using configurable filter for headings row 1 and for rows ' . $startRow . ' to ' . ($startRow + $chunkSize - 1)); + /* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read * */ + $chunkFilter = new ChunkReadFilter($startRow, $chunkSize); + /* Tell the Reader that we want to use the new Read Filter that we've just Instantiated * */ + $reader->setReadFilter($chunkFilter); + /* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */ + $spreadsheet = $reader->load($inputFileName); + + // Do some processing here + + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); + var_dump($sheetData); +} diff --git a/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php b/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php new file mode 100644 index 00000000..a03e15e5 --- /dev/null +++ b/samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_(version_2).php @@ -0,0 +1,66 @@ +_startRow = $startRow; + $this->_endRow = $startRow + $chunkSize; + } + + public function readCell($column, $row, $worksheetName = '') + { + // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow + if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { + return true; + } + + return false; + } +} + +$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +/* Create a new Reader of the type defined in $inputFileType * */ +$reader = IOFactory::createReader($inputFileType); + +/* Define how many rows we want to read for each "chunk" * */ +$chunkSize = 20; +/* Create a new Instance of our Read Filter * */ +$chunkFilter = new ChunkReadFilter(); + +/* Tell the Reader that we want to use the Read Filter that we've Instantiated * */ +$reader->setReadFilter($chunkFilter); + +/* Loop to read our worksheet in "chunk size" blocks * */ +for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { + $helper->log('Loading WorkSheet using configurable filter for headings row 1 and for rows ' . $startRow . ' to ' . ($startRow + $chunkSize - 1)); + /* Tell the Read Filter, the limits on which rows we want to read this iteration * */ + $chunkFilter->setRows($startRow, $chunkSize); + /* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */ + $spreadsheet = $reader->load($inputFileName); + + // Do some processing here + + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); + var_dump($sheetData); +} diff --git a/samples/Reader/13_Simple_file_reader_for_multiple_CSV_files.php b/samples/Reader/13_Simple_file_reader_for_multiple_CSV_files.php new file mode 100644 index 00000000..d4817e30 --- /dev/null +++ b/samples/Reader/13_Simple_file_reader_for_multiple_CSV_files.php @@ -0,0 +1,29 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' into WorkSheet #1 using IOFactory with a defined reader type of ' . $inputFileType); +$spreadsheet = $reader->load($inputFileName); +$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); +foreach ($inputFileNames as $sheet => $inputFileName) { + $helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' into WorkSheet #' . ($sheet + 2) . ' using IOFactory with a defined reader type of ' . $inputFileType); + $reader->setSheetIndex($sheet + 1); + $reader->loadIntoExisting($inputFileName, $spreadsheet); + $spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); +} + +$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); +$loadedSheetNames = $spreadsheet->getSheetNames(); +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log('Worksheet #' . $sheetIndex . ' -> ' . $loadedSheetName . ''); + $spreadsheet->setActiveSheetIndexByName($loadedSheetName); + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); + var_dump($sheetData); +} diff --git a/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php b/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php new file mode 100644 index 00000000..7ac5a9fd --- /dev/null +++ b/samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php @@ -0,0 +1,85 @@ +_startRow = $startRow; + $this->_endRow = $startRow + $chunkSize; + } + + public function readCell($column, $row, $worksheetName = '') + { + // Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow + if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { + return true; + } + + return false; + } +} + +$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +/* Create a new Reader of the type defined in $inputFileType * */ +$reader = IOFactory::createReader($inputFileType); + +/* Define how many rows we want to read for each "chunk" * */ +$chunkSize = 100; +/* Create a new Instance of our Read Filter * */ +$chunkFilter = new ChunkReadFilter(); + +/* Tell the Reader that we want to use the Read Filter that we've Instantiated * */ +/* and that we want to store it in contiguous rows/columns * */ +$reader->setReadFilter($chunkFilter) + ->setContiguous(true); + +/* Instantiate a new PhpSpreadsheet object manually * */ +$spreadsheet = new Spreadsheet(); + +/* Set a sheet index * */ +$sheet = 0; +/* Loop to read our worksheet in "chunk size" blocks * */ +/** $startRow is set to 2 initially because we always read the headings in row #1 * */ +for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { + $helper->log('Loading WorkSheet #' . ($sheet + 1) . ' using configurable filter for headings row 1 and for rows ' . $startRow . ' to ' . ($startRow + $chunkSize - 1)); + /* Tell the Read Filter, the limits on which rows we want to read this iteration * */ + $chunkFilter->setRows($startRow, $chunkSize); + + /* Increment the worksheet index pointer for the Reader * */ + $reader->setSheetIndex($sheet); + /* Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object * */ + $reader->loadIntoExisting($inputFileName, $spreadsheet); + /* Set the worksheet title (to reference the "sheet" of data that we've loaded) * */ + /* and increment the sheet index as well * */ + $spreadsheet->getActiveSheet()->setTitle('Country Data #' . (++$sheet)); +} + +$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); +$loadedSheetNames = $spreadsheet->getSheetNames(); +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log('Worksheet #' . $sheetIndex . ' -> ' . $loadedSheetName . ''); + $spreadsheet->setActiveSheetIndexByName($loadedSheetName); + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true); + var_dump($sheetData); +} diff --git a/samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php b/samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php new file mode 100644 index 00000000..4cc7b975 --- /dev/null +++ b/samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php @@ -0,0 +1,40 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' into WorkSheet #1 using IOFactory with a defined reader type of ' . $inputFileType); +$reader->setDelimiter("\t"); +$spreadsheet = $reader->load($inputFileName); +$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); + +$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); +$loadedSheetNames = $spreadsheet->getSheetNames(); +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log('Worksheet #' . $sheetIndex . ' -> ' . $loadedSheetName . ' (Formatted)'); + $spreadsheet->setActiveSheetIndexByName($loadedSheetName); + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); + var_dump($sheetData); +} + +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log('Worksheet #' . $sheetIndex . ' -> ' . $loadedSheetName . ' (Unformatted)'); + $spreadsheet->setActiveSheetIndexByName($loadedSheetName); + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, false, true); + var_dump($sheetData); +} + +foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { + $helper->log('Worksheet #' . $sheetIndex . ' -> ' . $loadedSheetName . ' (Raw)'); + $spreadsheet->setActiveSheetIndexByName($loadedSheetName); + $sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true); + var_dump($sheetData); +} diff --git a/samples/Reader/16_Handling_loader_exceptions_using_TryCatch.php b/samples/Reader/16_Handling_loader_exceptions_using_TryCatch.php new file mode 100644 index 00000000..dd5fa273 --- /dev/null +++ b/samples/Reader/16_Handling_loader_exceptions_using_TryCatch.php @@ -0,0 +1,13 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory to identify the format'); +try { + $spreadsheet = IOFactory::load($inputFileName); +} catch (InvalidArgumentException $e) { + $helper->log('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); +} diff --git a/samples/Reader/17_Simple_file_reader_loading_several_named_worksheets.php b/samples/Reader/17_Simple_file_reader_loading_several_named_worksheets.php new file mode 100644 index 00000000..53941795 --- /dev/null +++ b/samples/Reader/17_Simple_file_reader_loading_several_named_worksheets.php @@ -0,0 +1,20 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType); +$reader = IOFactory::createReader($inputFileType); + +/* Read the list of Worksheet Names from the Workbook file * */ +$helper->log('Read the list of Worksheets in the WorkBook'); +$worksheetNames = $reader->listWorksheetNames($inputFileName); + +$helper->log('There are ' . count($worksheetNames) . ' worksheet' . ((count($worksheetNames) == 1) ? '' : 's') . ' in the workbook'); +foreach ($worksheetNames as $worksheetName) { + $helper->log($worksheetName); +} diff --git a/samples/Reader/18_Reading_list_of_worksheets_without_loading_entire_file.php b/samples/Reader/18_Reading_list_of_worksheets_without_loading_entire_file.php new file mode 100644 index 00000000..bb58a2d5 --- /dev/null +++ b/samples/Reader/18_Reading_list_of_worksheets_without_loading_entire_file.php @@ -0,0 +1,20 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' information using IOFactory with a defined reader type of ' . $inputFileType); + +$reader = IOFactory::createReader($inputFileType); +$worksheetNames = $reader->listWorksheetNames($inputFileName); + +$helper->log('

Worksheet Names

'); +$helper->log('
    '); +foreach ($worksheetNames as $worksheetName) { + $helper->log('
  1. ' . $worksheetName . '
  2. '); +} +$helper->log('
'); diff --git a/samples/Reader/19_Reading_worksheet_information_without_loading_entire_file.php b/samples/Reader/19_Reading_worksheet_information_without_loading_entire_file.php new file mode 100644 index 00000000..5cdc4988 --- /dev/null +++ b/samples/Reader/19_Reading_worksheet_information_without_loading_entire_file.php @@ -0,0 +1,23 @@ +log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' information using IOFactory with a defined reader type of ' . $inputFileType); + +$reader = IOFactory::createReader($inputFileType); +$worksheetData = $reader->listWorksheetInfo($inputFileName); + +$helper->log('

Worksheet Information

'); +$helper->log('
    '); +foreach ($worksheetData as $worksheet) { + $helper->log('
  1. ' . $worksheet['worksheetName']); + $helper->log('Rows: ' . $worksheet['totalRows'] . ' Columns: ' . $worksheet['totalColumns']); + $helper->log('Cell Range: A1:' . $worksheet['lastColumnLetter'] . $worksheet['totalRows']); + $helper->log('
  2. '); +} +$helper->log('
'); diff --git a/docs/Examples/Reader/sampleData/example1.csv b/samples/Reader/sampleData/example1.csv similarity index 100% rename from docs/Examples/Reader/sampleData/example1.csv rename to samples/Reader/sampleData/example1.csv diff --git a/docs/Examples/Reader/sampleData/example1.tsv b/samples/Reader/sampleData/example1.tsv similarity index 100% rename from docs/Examples/Reader/sampleData/example1.tsv rename to samples/Reader/sampleData/example1.tsv diff --git a/docs/Examples/Reader/sampleData/example1.xls b/samples/Reader/sampleData/example1.xls similarity index 100% rename from docs/Examples/Reader/sampleData/example1.xls rename to samples/Reader/sampleData/example1.xls diff --git a/docs/Examples/Reader/sampleData/example2.csv b/samples/Reader/sampleData/example2.csv similarity index 100% rename from docs/Examples/Reader/sampleData/example2.csv rename to samples/Reader/sampleData/example2.csv diff --git a/docs/Examples/Reader/sampleData/example2.xls b/samples/Reader/sampleData/example2.xls similarity index 100% rename from docs/Examples/Reader/sampleData/example2.xls rename to samples/Reader/sampleData/example2.xls diff --git a/samples/Reading_workbook_data/Custom_properties.php b/samples/Reading_workbook_data/Custom_properties.php new file mode 100644 index 00000000..8413b542 --- /dev/null +++ b/samples/Reading_workbook_data/Custom_properties.php @@ -0,0 +1,48 @@ +load($inputFileName); + +/* Read an array list of any custom properties for this document * */ +$customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); + +/* Loop through the list of custom properties * */ +foreach ($customPropertyList as $customPropertyName) { + $helper->log('' . $customPropertyName . ': '); + /* Retrieve the property value * */ + $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName); + /* Retrieve the property type * */ + $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName); + + /* Manipulate properties as appropriate for display purposes * */ + switch ($propertyType) { + case 'i': // integer + $propertyType = 'integer number'; + break; + case 'f': // float + $propertyType = 'floating point number'; + break; + case 's': // string + $propertyType = 'string'; + break; + case 'd': // date + $propertyValue = date('l, d<\s\up>S F Y g:i A', $propertyValue); + $propertyType = 'date'; + break; + case 'b': // boolean + $propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE'; + $propertyType = 'boolean'; + break; + } + + $helper->log($propertyValue . ' (' . $propertyType . ')'); +} diff --git a/samples/Reading_workbook_data/Custom_property_names.php b/samples/Reading_workbook_data/Custom_property_names.php new file mode 100644 index 00000000..d94f0e4c --- /dev/null +++ b/samples/Reading_workbook_data/Custom_property_names.php @@ -0,0 +1,20 @@ +load($inputFileName); + +/* Read an array list of any custom properties for this document * */ +$customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); + +foreach ($customPropertyList as $customPropertyName) { + $helper->log($customPropertyName); +} diff --git a/samples/Reading_workbook_data/Properties.php b/samples/Reading_workbook_data/Properties.php new file mode 100644 index 00000000..1dc324c0 --- /dev/null +++ b/samples/Reading_workbook_data/Properties.php @@ -0,0 +1,64 @@ +load($inputFileName); + +/* Read the document's creator property * */ +$creator = $spreadsheet->getProperties()->getCreator(); +$helper->log('Document Creator: ' . $creator); + +/* Read the Date when the workbook was created (as a PHP timestamp value) * */ +$creationDatestamp = $spreadsheet->getProperties()->getCreated(); +/* Format the date and time using the standard PHP date() function * */ +$creationDate = date('l, d<\s\up>S F Y', $creationDatestamp); +$creationTime = date('g:i A', $creationDatestamp); +$helper->log('Created On: ' . $creationDate . ' at ' . $creationTime); + +/* Read the name of the last person to modify this workbook * */ +$modifiedBy = $spreadsheet->getProperties()->getLastModifiedBy(); +$helper->log('Last Modified By: ' . $modifiedBy); + +/* Read the Date when the workbook was last modified (as a PHP timestamp value) * */ +$modifiedDatestamp = $spreadsheet->getProperties()->getModified(); +/* Format the date and time using the standard PHP date() function * */ +$modifiedDate = date('l, d<\s\up>S F Y', $modifiedDatestamp); +$modifiedTime = date('g:i A', $modifiedDatestamp); +$helper->log('Last Modified On: ' . $modifiedDate . ' at ' . $modifiedTime); + +/* Read the workbook title property * */ +$workbookTitle = $spreadsheet->getProperties()->getTitle(); +$helper->log('Title: ' . $workbookTitle); + +/* Read the workbook description property * */ +$description = $spreadsheet->getProperties()->getDescription(); +$helper->log('Description: ' . $description); + +/* Read the workbook subject property * */ +$subject = $spreadsheet->getProperties()->getSubject(); +$helper->log('Subject: ' . $subject); + +/* Read the workbook keywords property * */ +$keywords = $spreadsheet->getProperties()->getKeywords(); +$helper->log('Keywords: ' . $keywords); + +/* Read the workbook category property * */ +$category = $spreadsheet->getProperties()->getCategory(); +$helper->log('Category: ' . $category); + +/* Read the workbook company property * */ +$company = $spreadsheet->getProperties()->getCompany(); +$helper->log('Company: ' . $company); + +/* Read the workbook manager property * */ +$manager = $spreadsheet->getProperties()->getManager(); +$helper->log('Manager: ' . $manager); +$s = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); diff --git a/samples/Reading_workbook_data/Worksheet_count_and_names.php b/samples/Reading_workbook_data/Worksheet_count_and_names.php new file mode 100644 index 00000000..03f7508c --- /dev/null +++ b/samples/Reading_workbook_data/Worksheet_count_and_names.php @@ -0,0 +1,24 @@ +load($inputFileName); + +/* Use the PhpSpreadsheet object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */ +$sheetCount = $spreadsheet->getSheetCount(); +$helper->log('There ' . (($sheetCount == 1) ? 'is' : 'are') . ' ' . $sheetCount . ' WorkSheet' . (($sheetCount == 1) ? '' : 's') . ' in the WorkBook'); + +$helper->log('Reading the names of Worksheets in the WorkBook'); +/* Use the PhpSpreadsheet object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */ +$sheetNames = $spreadsheet->getSheetNames(); +foreach ($sheetNames as $sheetIndex => $sheetName) { + $helper->log('WorkSheet #' . $sheetIndex . ' is named "' . $sheetName . '"'); +} diff --git a/docs/Examples/Reading WorkBook Data/sampleData/example1.xls b/samples/Reading_workbook_data/sampleData/example1.xls similarity index 100% rename from docs/Examples/Reading WorkBook Data/sampleData/example1.xls rename to samples/Reading_workbook_data/sampleData/example1.xls diff --git a/docs/Examples/Reading WorkBook Data/sampleData/example1.xlsx b/samples/Reading_workbook_data/sampleData/example1.xlsx similarity index 100% rename from docs/Examples/Reading WorkBook Data/sampleData/example1.xlsx rename to samples/Reading_workbook_data/sampleData/example1.xlsx diff --git a/docs/Examples/Reading WorkBook Data/sampleData/example2.xls b/samples/Reading_workbook_data/sampleData/example2.xls similarity index 100% rename from docs/Examples/Reading WorkBook Data/sampleData/example2.xls rename to samples/Reading_workbook_data/sampleData/example2.xls diff --git a/samples/index.php b/samples/index.php index 6dc6fd6c..9ff53f51 100644 --- a/samples/index.php +++ b/samples/index.php @@ -23,7 +23,7 @@ if (!$helper->isCli()) {

Requirement check:'; + echo '

Requirement check

'; echo '