diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..2557290f --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,29 @@ +This is: + +- [ ] a bug report +- [ ] a feature request +- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet) + +### What is the expected behavior? + + +### What is the current behavior? + + +### What are the steps to reproduce? + +Please provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) of code that exhibits the issue without relying on an external Excel file or a web server: + +```php +migrate(); diff --git a/docs/Examples/Calculations/Database/DAVERAGE.php b/docs/Examples/Calculations/Database/DAVERAGE.php index b54a7d1d..be87d3ef 100644 --- a/docs/Examples/Calculations/Database/DAVERAGE.php +++ b/docs/Examples/Calculations/Database/DAVERAGE.php @@ -1,79 +1,78 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DAVERAGE

-

Returns the average of selected database entries.

-DAVERAGE +

Returns the average of selected database entries.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$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 '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index 2cd0661d..4387d8fa 100644 --- a/docs/Examples/Calculations/Database/DCOUNT.php +++ b/docs/Examples/Calculations/Database/DCOUNT.php @@ -1,79 +1,78 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DCOUNT

-

Counts the cells that contain numbers in a database.

-DCOUNT +

Counts the cells that contain numbers in a database.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard'); -$worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)'); + echo '
'; -echo '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index d64b1d6e..59dd9529 100644 --- a/docs/Examples/Calculations/Database/DGET.php +++ b/docs/Examples/Calculations/Database/DGET.php @@ -1,75 +1,74 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DGET

-

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

-DGET +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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)'); -$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 '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

'; + echo 'ALL' . '

'; -echo 'ALL' . '

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

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index 58d2f039..bc0af306 100644 --- a/docs/Examples/Calculations/Database/DMAX.php +++ b/docs/Examples/Calculations/Database/DMAX.php @@ -1,78 +1,77 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DMAX

-

Returns the maximum value from selected database entries.

-DMAX +

Returns the maximum value from selected database entries.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard'); -$worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)'); + echo '
'; -echo '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

'; + echo 'ALL' . '

'; -echo 'ALL' . '

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

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index e4fb7658..9f36786a 100644 --- a/docs/Examples/Calculations/Database/DMIN.php +++ b/docs/Examples/Calculations/Database/DMIN.php @@ -1,78 +1,77 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DMIN

-

Returns the minimum value from selected database entries.

-DMIN +

Returns the minimum value from selected database entries.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard'); -$worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)'); + echo '
'; -echo '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

'; + echo 'ALL' . '

'; -echo 'ALL' . '

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

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index 382227df..92efcf08 100644 --- a/docs/Examples/Calculations/Database/DPRODUCT.php +++ b/docs/Examples/Calculations/Database/DPRODUCT.php @@ -1,75 +1,74 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DPRODUCT

-

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

-DPRODUCT +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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)'); -$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 '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

'; + echo 'ALL' . '

'; -echo 'ALL' . '

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

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index e1273e5a..8eaf133e 100644 --- a/docs/Examples/Calculations/Database/DSTDEV.php +++ b/docs/Examples/Calculations/Database/DSTDEV.php @@ -1,79 +1,78 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DSTDEV

-

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

-DSTDEV +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$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 '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index 3af791bb..ea9a5345 100644 --- a/docs/Examples/Calculations/Database/DSTDEVP.php +++ b/docs/Examples/Calculations/Database/DSTDEVP.php @@ -1,79 +1,78 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DSTDEVP

-

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

-DSTDEVP +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$worksheet->setCellValue('A13', 'The standard deviation in height of Apple and Pear trees'); -$worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)'); + echo '
'; -echo '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index 44e63994..2349845e 100644 --- a/docs/Examples/Calculations/Database/DVAR.php +++ b/docs/Examples/Calculations/Database/DVAR.php @@ -1,79 +1,78 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DVAR

-

Estimates variance based on a sample from selected database entries.

-DVAR +

Estimates variance based on a sample from selected database entries.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$worksheet->setCellValue('A13', 'The estimated variance in height of Apple and Pear trees'); -$worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)'); + echo '
'; -echo '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index c630e731..a9b053a5 100644 --- a/docs/Examples/Calculations/Database/DVARP.php +++ b/docs/Examples/Calculations/Database/DVARP.php @@ -1,79 +1,78 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DVARP

-

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

-DVARP +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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], + ]; -// 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->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('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)'); -$worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees'); -$worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)'); + echo '
'; -echo '
'; + echo '

Database

'; -echo '

Database

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

Criteria

'; -// Test the formulae -echo '

Criteria

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

'; + echo '

Criteria

'; -echo '

Criteria

'; + $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); + var_dump($criteriaData); -$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(); - -?> - + 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 index 1af05e3e..33330c97 100644 --- a/docs/Examples/Calculations/DateTime/DATE.php +++ b/docs/Examples/Calculations/DateTime/DATE.php @@ -1,77 +1,77 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DATE

-

Returns the serial number of a particular date.

-DATE +

Returns the serial number of a particular date.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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); -// 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); -$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'); -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 '
'; -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(), '
- + // 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 index 42996a4e..535fdcce 100644 --- a/docs/Examples/Calculations/DateTime/DATEVALUE.php +++ b/docs/Examples/Calculations/DateTime/DATEVALUE.php @@ -1,70 +1,70 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

DATEVALUE

-

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

-DATEVALUE +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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); -// 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); + } -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'); -$worksheet->getStyle('C1:C' . $testDateCount) - ->getNumberFormat() - ->setFormatCode('yyyy-mmm-dd'); + echo '
'; -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(), '
- + // 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 index 9c206304..09641074 100644 --- a/docs/Examples/Calculations/DateTime/TIME.php +++ b/docs/Examples/Calculations/DateTime/TIME.php @@ -1,75 +1,75 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

TIME

-

Returns the serial number of a particular time.

-TIME +

Returns the serial number of a particular time.

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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); -// 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); -$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'); -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 '
'; -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(), '
- + // 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 index c5745cc2..4cf27c81 100644 --- a/docs/Examples/Calculations/DateTime/TIMEVALUE.php +++ b/docs/Examples/Calculations/DateTime/TIMEVALUE.php @@ -1,66 +1,66 @@ - - + + -PhpSpreadsheet Calculation Examples + PhpSpreadsheet Calculation Examples - - + + -

TIMEVALUE

-

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

-TIMEVALUE +

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

+ getActiveSheet(); -// Create new PhpSpreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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); -// 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); + } -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'); -$worksheet->getStyle('C1:C' . $testDateCount) - ->getNumberFormat() - ->setFormatCode('hh:mm:ss'); + echo '
'; -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(), '
- + // 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 index 5990ca23..ad03fe8e 100644 --- a/docs/Examples/Calculations/index.php +++ b/docs/Examples/Calculations/index.php @@ -1,49 +1,45 @@ - - + + -PhpSpreadsheet Calculation Function Examples + PhpSpreadsheet Calculation Function Examples - - + + -PhpSpreadsheet Calculation Function Examples'; -echo '

PhpSpreadsheet Calculation Function Examples

'; + $exampleTypeList = glob('./*', GLOB_ONLYDIR); -$exampleTypeList = glob('./*', GLOB_ONLYDIR); + foreach ($exampleTypeList as $exampleType) { + echo '

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

'; -foreach ($exampleTypeList as $exampleType) { - echo '

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

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

(.*?)

#'; + $h2Pattern = '#

(.*?)

#'; - $h1Pattern = '#

(.*?)

#'; - $h2Pattern = '#

(.*?)

#'; + if (preg_match($h1Pattern, $fileData, $out)) { + $h1Text = $out[1]; + $h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : ''; - if (preg_match($h1Pattern, $fileData, $out)) { - $h1Text = $out[1]; - $h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : ''; - - echo '',$h1Text,'
'; - if ($h2Text > '') { - echo $h2Text,'
'; + 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 index 9ef1f565..1e343e5d 100644 --- a/docs/Examples/Reader/exampleReader01.php +++ b/docs/Examples/Reader/exampleReader01.php @@ -1,35 +1,34 @@ - - + + -PhpSpreadsheet Reader Example #01 + PhpSpreadsheet Reader Example #01 - - + + -

PhpSpreadsheet Reader Example #01

-

Simple File Reader using \PhpOffice\PhpSpreadsheet\IOFactory::load()

-PhpSpreadsheet Reader Example #01 +

Simple File Reader using IOFactory::load()

+ '; + $spreadsheet = IOFactory::load($inputFileName); -$inputFileName = './sampleData/example1.xls'; -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format
'; -$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index b98b860d..c29e7993 100644 --- a/docs/Examples/Reader/exampleReader02.php +++ b/docs/Examples/Reader/exampleReader02.php @@ -1,43 +1,36 @@ - - + + -PhpSpreadsheet Reader Example #02 + PhpSpreadsheet Reader Example #02 - - + + -

PhpSpreadsheet Reader Example #02

-

Simple File Reader using a Specified Reader

-PhpSpreadsheet Reader Example #02 +

Simple File Reader using a Specified Reader

+ '; + $reader = new Xls(); + $spreadsheet = $reader->load($inputFileName); -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls
'; -$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls(); -// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); -// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xml(); -// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods(); -// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Slk(); -// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Gnumeric(); -// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv(); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index dbd584b4..750d52c2 100644 --- a/docs/Examples/Reader/exampleReader03.php +++ b/docs/Examples/Reader/exampleReader03.php @@ -1,44 +1,37 @@ - - + + -PhpSpreadsheet Reader Example #03 + PhpSpreadsheet Reader Example #03 - - + + -

PhpSpreadsheet Reader Example #03

-

Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Return a Reader

-PhpSpreadsheet Reader Example #03 +

Simple File Reader using the IOFactory to Return a Reader

+ '; + $reader = IOFactory::createReader($inputFileType); + $spreadsheet = $reader->load($inputFileName); -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index 2267a9df..7b8065d5 100644 --- a/docs/Examples/Reader/exampleReader04.php +++ b/docs/Examples/Reader/exampleReader04.php @@ -1,40 +1,39 @@ - - + + -PhpSpreadsheet Reader Example #04 + PhpSpreadsheet Reader Example #04 - - + + -

PhpSpreadsheet Reader Example #04

-

Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Identify a Reader to Use

-PhpSpreadsheet Reader Example #04 +

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

+ '; -$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName); -echo 'File ',pathinfo($inputFileName, PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file
'; + echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with the identified reader type
'; + $reader = IOFactory::createReader($inputFileType); + $spreadsheet = $reader->load($inputFileName); -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with the identified reader type
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index 807e910d..2b06e8ac 100644 --- a/docs/Examples/Reader/exampleReader05.php +++ b/docs/Examples/Reader/exampleReader05.php @@ -1,44 +1,39 @@ - - + + -PhpSpreadsheet Reader Example #05 + PhpSpreadsheet Reader Example #05 - - + + -

PhpSpreadsheet Reader Example #05

-

Simple File Reader using the "Read Data Only" Option

-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 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -echo 'Turning Formatting off for Load
'; -$reader->setReadDataOnly(true); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index 84675c17..04e6b94e 100644 --- a/docs/Examples/Reader/exampleReader06.php +++ b/docs/Examples/Reader/exampleReader06.php @@ -1,47 +1,42 @@ - - + + -PhpSpreadsheet Reader Example #06 + PhpSpreadsheet Reader Example #06 - - + + -

PhpSpreadsheet Reader Example #06

-

Simple File Reader Loading All WorkSheets

-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 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -echo 'Loading all WorkSheets
'; -$reader->setLoadAllSheets(); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded

'; -$loadedSheetNames = $spreadsheet->getSheetNames(); -foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo $sheetIndex, ' -> ', $loadedSheetName, '
'; -} - -?> - + 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 index 0463f37b..7beabc82 100644 --- a/docs/Examples/Reader/exampleReader07.php +++ b/docs/Examples/Reader/exampleReader07.php @@ -1,48 +1,43 @@ - - + + -PhpSpreadsheet Reader Example #07 + PhpSpreadsheet Reader Example #07 - - + + -

PhpSpreadsheet Reader Example #07

-

Simple File Reader Loading a Single Named WorkSheet

-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 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -echo 'Loading Sheet "',$sheetname,'" only
'; -$reader->setLoadSheetsOnly($sheetname); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -echo $spreadsheet->getSheetCount(),' worksheet',(($spreadsheet->getSheetCount() == 1) ? '' : 's'),' loaded

'; -$loadedSheetNames = $spreadsheet->getSheetNames(); -foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo $sheetIndex,' -> ',$loadedSheetName,'
'; -} - -?> - + 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 index c5e9b39d..c9e574b9 100644 --- a/docs/Examples/Reader/exampleReader08.php +++ b/docs/Examples/Reader/exampleReader08.php @@ -1,48 +1,43 @@ - - + + -PhpSpreadsheet Reader Example #08 + PhpSpreadsheet Reader Example #08 - - + + -

PhpSpreadsheet Reader Example #08

-

Simple File Reader Loading Several Named WorkSheets

-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 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only
'; -$reader->setLoadSheetsOnly($sheetnames); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -echo $spreadsheet->getSheetCount(),' worksheet',(($spreadsheet->getSheetCount() == 1) ? '' : 's'),' loaded

'; -$loadedSheetNames = $spreadsheet->getSheetNames(); -foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { - echo $sheetIndex,' -> ',$loadedSheetName,'
'; -} - -?> - + 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 index e2464447..1c5c4147 100644 --- a/docs/Examples/Reader/exampleReader09.php +++ b/docs/Examples/Reader/exampleReader09.php @@ -1,64 +1,61 @@ - - + + -PhpSpreadsheet Reader Example #09 + PhpSpreadsheet Reader Example #09 - - + + -

PhpSpreadsheet Reader Example #09

-

Simple File Reader Using a Read Filter

-PhpSpreadsheet Reader Example #09 +

Simple File Reader Using a Read Filter

+ = 1 && $row <= 7) { + if (in_array($column, range('A', 'E'))) { + return true; + } + } -class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter -{ - public function readCell($column, $row, $worksheetName = '') - { - // Read rows 1 to 7 and columns A to E only - if ($row >= 1 && $row <= 7) { - if (in_array($column, range('A', 'E'))) { - return true; + return false; } + } - return false; - } -} + $filterSubset = new MyReadFilter(); -$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 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -echo 'Loading Sheet "',$sheetname,'" only
'; -$reader->setLoadSheetsOnly($sheetname); -echo 'Loading Sheet using filter
'; -$reader->setReadFilter($filterSubset); -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index 965a1bb2..6d4517eb 100644 --- a/docs/Examples/Reader/exampleReader10.php +++ b/docs/Examples/Reader/exampleReader10.php @@ -1,76 +1,72 @@ - - + + -PhpSpreadsheet Reader Example #10 + PhpSpreadsheet Reader Example #10 - - + + -

PhpSpreadsheet Reader Example #10

-

Simple File Reader Using a Configurable Read Filter

-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; + public function __construct($startRow, $endRow, $columns) + { + $this->_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; + } + } - return false; - } -} + $filterSubset = new MyReadFilter(9, 15, range('G', 'K')); -$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 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\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 '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index 5435629a..67c9ec4d 100644 --- a/docs/Examples/Reader/exampleReader11.php +++ b/docs/Examples/Reader/exampleReader11.php @@ -1,89 +1,86 @@ - - + + -PhpSpreadsheet Reader Example #11 + PhpSpreadsheet Reader Example #11 - - + + -

PhpSpreadsheet Reader Example #11

-

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

-PhpSpreadsheet Reader Example #11 +

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

+ _startRow = $startRow; + $this->_endRow = $startRow + $chunkSize; + } - /** - * We expect a list of the rows that we want to read to be passed into the constructor. - * - * @param mixed $startRow - * @param mixed $chunkSize - */ - public function __construct($startRow, $chunkSize) - { - $this->_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; + } - 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 '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 = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + echo '
'; -echo '
'; + /* Define how many rows we want for each "chunk" * */ + $chunkSize = 20; -/* 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); -/* 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 - // Do some processing here - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - echo '

'; -} - -?> - + $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 index 673b2f14..f9055ae1 100644 --- a/docs/Examples/Reader/exampleReader12.php +++ b/docs/Examples/Reader/exampleReader12.php @@ -1,92 +1,89 @@ - - + + -PhpSpreadsheet Reader Example #12 + PhpSpreadsheet Reader Example #12 - - + + -

PhpSpreadsheet Reader Example #12

-

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

-PhpSpreadsheet Reader Example #12 +

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

+ _startRow = $startRow; + $this->_endRow = $startRow + $chunkSize; + } - /** - * Set the list of rows that we want to read. - * - * @param mixed $startRow - * @param mixed $chunkSize - */ - public function setRows($startRow, $chunkSize) - { - $this->_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; + } - 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 '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 = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + echo '
'; -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(); -/* 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); -/* 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); -/* 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 - // Do some processing here - - $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - var_dump($sheetData); - echo '

'; -} - -?> - + $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 index 9977a83c..e13f1801 100644 --- a/docs/Examples/Reader/exampleReader13.php +++ b/docs/Examples/Reader/exampleReader13.php @@ -1,53 +1,52 @@ - - + + -PhpSpreadsheet Reader Example #13 + PhpSpreadsheet Reader Example #13 - - + + -

PhpSpreadsheet Reader Example #13

-

Simple File Reader for Multiple CSV Files

-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)); + } -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -$inputFileName = array_shift($inputFileNames); -echo '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) { - 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 '
'; - -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 '

'; -} - -?> - + 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 index 933be4ac..98ab0b65 100644 --- a/docs/Examples/Reader/exampleReader14.php +++ b/docs/Examples/Reader/exampleReader14.php @@ -1,108 +1,110 @@ - - + + -PhpSpreadsheet Reader Example #14 + PhpSpreadsheet Reader Example #14 - - + + -

PhpSpreadsheet Reader Example #14

-

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

-PhpSpreadsheet Reader Example #14 +

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

+ _startRow = $startRow; + $this->_endRow = $startRow + $chunkSize; + } - /** - * Set the list of rows that we want to read. - * - * @param mixed $startRow - * @param mixed $chunkSize - */ - public function setRows($startRow, $chunkSize) - { - $this->_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; + } - 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 '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 = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + echo '
'; -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(); -/* 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); -/* 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(); -/* Instantiate a new PhpSpreadsheet object manually **/ -$spreadsheet = new \PhpOffice\PhpSpreadsheet\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); -/* 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)); + } - /* 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 '
'; - -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 '
'; -} - -?> - + 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 index a04a1adc..be913444 100644 --- a/docs/Examples/Reader/exampleReader15.php +++ b/docs/Examples/Reader/exampleReader15.php @@ -1,69 +1,69 @@ - - + + -PhpSpreadsheet Reader Example #15 + PhpSpreadsheet Reader Example #15 - - + + -

PhpSpreadsheet Reader Example #15

-

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

-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)); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -echo '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)); + echo '
'; -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 $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 '
'; -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 '
'; + } -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 '
'; -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 '
'; -} - -?> - + 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 index 6e6a7583..aa4bc469 100644 --- a/docs/Examples/Reader/exampleReader16.php +++ b/docs/Examples/Reader/exampleReader16.php @@ -1,39 +1,39 @@ - - + + -PhpSpreadsheet Reader Example #16 + PhpSpreadsheet Reader Example #16 - - + + -

PhpSpreadsheet Reader Example #16

-

Handling Loader Exceptions using Try/Catch

-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()); + } -$inputFileName = './sampleData/example_1.xls'; -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format
'; -try { - $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); -} catch (\InvalidArgumentException $e) { - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); -} + echo '
'; -echo '
'; - -$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); -var_dump($sheetData); - -?> - + $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 index f76994e9..3c6ebf30 100644 --- a/docs/Examples/Reader/exampleReader17.php +++ b/docs/Examples/Reader/exampleReader17.php @@ -1,45 +1,40 @@ - - + + -PhpSpreadsheet Reader Example #17 + PhpSpreadsheet Reader Example #17 - - + + -

PhpSpreadsheet Reader Example #17

-

Simple File Reader Loading Several Named WorkSheets

-PhpSpreadsheet Reader Example #17 +

Simple File Reader Loading Several Named WorkSheets

+ '; + $reader = IOFactory::createReader($inputFileType); -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; -$reader = \PhpOffice\PhpSpreadsheet\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); -/* 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,'
'; -} - -?> - + 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 index 6688e481..68a478bb 100644 --- a/docs/Examples/Reader/exampleReader18.php +++ b/docs/Examples/Reader/exampleReader18.php @@ -1,45 +1,40 @@ - - + + -PhpSpreadsheet Reader Example #18 + PhpSpreadsheet Reader Example #18 - - + + -

PhpSpreadsheet Reader Example #18

-

Reading list of WorkSheets without loading entire file

-PhpSpreadsheet Reader Example #18 +

Reading list of WorkSheets without loading entire file

+ '; -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'
'; + $reader = IOFactory::createReader($inputFileType); + $worksheetNames = $reader->listWorksheetNames($inputFileName); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -$worksheetNames = $reader->listWorksheetNames($inputFileName); - -echo '

Worksheet Names

'; -echo '
    '; -foreach ($worksheetNames as $worksheetName) { - echo '
  1. ', $worksheetName, '
  2. '; -} -echo '
'; - -?> - + 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 index 5ad3e5ba..dea2dd06 100644 --- a/docs/Examples/Reader/exampleReader19.php +++ b/docs/Examples/Reader/exampleReader19.php @@ -1,48 +1,43 @@ - - + + -PhpSpreadsheet Reader Example #19 + PhpSpreadsheet Reader Example #19 - - + + -

PhpSpreadsheet Reader Example #19

-

Reading WorkSheet information without loading entire file

-PhpSpreadsheet Reader Example #19 +

Reading WorkSheet information without loading entire file

+ '; -echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'
'; + $reader = IOFactory::createReader($inputFileType); + $worksheetData = $reader->listWorksheetInfo($inputFileName); -$reader = \PhpOffice\PhpSpreadsheet\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 '
'; - -?> - + 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 index aa9bddd7..9085b394 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php @@ -1,86 +1,85 @@ - - + + -PhpSpreadsheet Reading WorkBook Data Example #01 + PhpSpreadsheet Reading WorkBook Data Example #01 - - + + -

PhpSpreadsheet Reading WorkBook Data Example #01

-

Read the WorkBook Properties

-PhpSpreadsheet Reading WorkBook Data Example #01 +

Read the WorkBook Properties

+ load($inputFileName); -/* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -/* Load $inputFileName to a PhpSpreadsheet Object **/ -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; + /* Read the document's creator property * */ + $creator = $spreadsheet->getProperties()->getCreator(); + echo 'Document Creator: ', $creator, '
'; -/* 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 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 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 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 title property **/ -$workbookTitle = $spreadsheet->getProperties()->getTitle(); -echo 'Title: ',$workbookTitle,'
'; + /* Read the workbook description property * */ + $description = $spreadsheet->getProperties()->getDescription(); + echo 'Description: ', $description, '
'; -/* 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 subject property **/ -$subject = $spreadsheet->getProperties()->getSubject(); -echo 'Subject: ',$subject,'
'; + /* Read the workbook keywords property * */ + $keywords = $spreadsheet->getProperties()->getKeywords(); + echo 'Keywords: ', $keywords, '
'; -/* 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 category property **/ -$category = $spreadsheet->getProperties()->getCategory(); -echo 'Category: ',$category,'
'; + /* Read the workbook company property * */ + $company = $spreadsheet->getProperties()->getCompany(); + echo 'Company: ', $company, '
'; -/* Read the workbook company property **/ -$company = $spreadsheet->getProperties()->getCompany(); -echo 'Company: ',$company,'
'; - -/* Read the workbook manager property **/ -$manager = $spreadsheet->getProperties()->getManager(); -echo 'Manager: ',$manager,'
'; - -?> - + /* 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 index c021728c..b643f74b 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php @@ -1,44 +1,43 @@ - - + + -PhpSpreadsheet Reading WorkBook Data Example #02 + PhpSpreadsheet Reading WorkBook Data Example #02 - - + + -

PhpSpreadsheet Reading WorkBook Data Example #02

-

Read a list of Custom Properties for a WorkBook

-PhpSpreadsheet Reading WorkBook Data Example #02 +

Read a list of Custom Properties for a WorkBook

+ load($inputFileName); -/* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -/* Load $inputFileName to a PhpSpreadsheet Object **/ -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; + /* Read an array list of any custom properties for this document * */ + $customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); -/* 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, '
'; -} - -?> - + 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 index c02f51bd..432099aa 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php @@ -1,72 +1,71 @@ - - + + -PhpSpreadsheet Reading WorkBook Data Example #03 + PhpSpreadsheet Reading WorkBook Data Example #03 - - + + -

PhpSpreadsheet Reading WorkBook Data Example #03

-

Read Custom Property Values for a WorkBook

-PhpSpreadsheet Reading WorkBook Data Example #03 +

Read Custom Property Values for a WorkBook

+ load($inputFileName); -/* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -/* Load $inputFileName to a PhpSpreadsheet Object **/ -$spreadsheet = $reader->load($inputFileName); + echo '
'; -echo '
'; + /* Read an array list of any custom properties for this document * */ + $customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); -/* 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); -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; + } - /* 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, ')
'; -} - -?> - + echo $propertyValue, ' (', $propertyType, ')
'; + } + ?> + diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php index 88c7f9e0..7299e783 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php @@ -1,48 +1,47 @@ - - + + -PhpSpreadsheet Reading WorkBook Data Example #04 + PhpSpreadsheet Reading WorkBook Data Example #04 - - + + -

PhpSpreadsheet Reading WorkBook Data Example #04

-

Get a List of the Worksheets in a WorkBook

-PhpSpreadsheet Reading WorkBook Data Example #04 +

Get a List of the Worksheets in a WorkBook

+ load($inputFileName); -/* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); -/* Load $inputFileName to a PhpSpreadsheet Object **/ -$spreadsheet = $reader->load($inputFileName); + echo '
'; -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 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,'"
'; -} - -?> - + 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 index a2c51879..9ff0929d 100644 --- a/docs/Examples/index.php +++ b/docs/Examples/index.php @@ -1,48 +1,44 @@ - - + + -PhpSpreadsheet Examples + PhpSpreadsheet Examples - - + + -PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples'; -foreach ($exampleTypeList as $exampleType) { - echo '

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

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

(.*?)

#'; + $h2Pattern = '#

(.*?)

#'; - $h1Pattern = '#

(.*?)

#'; - $h2Pattern = '#

(.*?)

#'; + if (preg_match($h1Pattern, $fileData, $out)) { + $h1Text = $out[1]; + $h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : ''; - 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, '
'; + echo '', $h1Text, '
'; + if (($h2Text > '') && + (pathinfo($exampleType, PATHINFO_BASENAME) != 'Calculations')) { + echo $h2Text, '
'; + } + } } } - } -} - -?> - + ?> + \ No newline at end of file diff --git a/docs/extra/extra.css b/docs/extra/extra.css new file mode 100644 index 00000000..2addeb79 --- /dev/null +++ b/docs/extra/extra.css @@ -0,0 +1,8 @@ +/* Make the huge table always visible */ +table.features-cross-reference { + overflow: visible !important; +} +.rst-content table.features-cross-reference.docutils th, +.rst-content table.features-cross-reference.docutils td { + background-color: white; +} diff --git a/docs/extra/extra.js b/docs/extra/extra.js new file mode 100644 index 00000000..fdef958f --- /dev/null +++ b/docs/extra/extra.js @@ -0,0 +1,57 @@ +var nodemcu = nodemcu || {}; +(function () { + 'use strict'; + + $(document).ready(function () { + fixSearch(); + }); + + /* + * RTD messes up MkDocs' search feature by tinkering with the search box defined in the theme, see + * https://github.com/rtfd/readthedocs.org/issues/1088. This function sets up a DOM4 MutationObserver + * to react to changes to the search form (triggered by RTD on doc ready). It then reverts everything + * the RTD JS code modified. + */ + function fixSearch() { + var target = document.getElementById('rtd-search-form'); + var config = {attributes: true, childList: true}; + + var observer = new MutationObserver(function (mutations) { + // if it isn't disconnected it'll loop infinitely because the observed element is modified + observer.disconnect(); + var form = $('#rtd-search-form'); + form.empty(); + form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html'); + $('').attr({ + type: "text", + name: "q", + placeholder: "Search docs" + }).appendTo(form); + }); + + if (window.location.origin.indexOf('readthedocs') > -1) { + observer.observe(target, config); + } + } + + /** + * Analyzes the URL of the current page to find out what the selected GitHub branch is. It's usually + * part of the location path. The code needs to distinguish between running MkDocs standalone + * and docs served from RTD. If no valid branch could be determined 'dev' returned. + * + * @returns GitHub branch name + */ + function determineSelectedBranch() { + var branch = 'dev', path = window.location.pathname; + if (window.location.origin.indexOf('readthedocs') > -1) { + // path is like /en///build/ -> extract 'lang' + // split[0] is an '' because the path starts with the separator + var thirdPathSegment = path.split('/')[2]; + // 'latest' is an alias on RTD for the 'dev' branch - which is the default for 'branch' here + if (thirdPathSegment !== 'latest') { + branch = thirdPathSegment; + } + } + return branch; + } +}()); \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 30043595..402059b6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,6 +6,21 @@ PhpSpreadsheet is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc. +## File formats supported + +|Format |Reading|Writing| +|--------------------------------------------|:-----:|:-----:| +|Open Document Format/OASIS (.ods) | ✓ | ✓ | +|Office Open XML (.xlsx) Excel 2007 and above| ✓ | ✓ | +|BIFF 8 (.xls) Excel 97 and above | ✓ | ✓ | +|BIFF 5 (.xls) Excel 95 | ✓ | | +|SpreadsheetML (.xml) Excel 2003 | ✓ | | +|Gnumeric | ✓ | | +|HTML | ✓ | ✓ | +|SYLK | ✓ | | +|CSV | ✓ | ✓ | +|PDF (using either the tcPDF, DomPDF or mPDF libraries, which need to be installed separately)| | ✓ | + # Getting started ## Software requirements @@ -17,6 +32,10 @@ The following software is required to develop using PhpSpreadsheet: - PHP extension php\_xml enabled - PHP extension php\_gd2 enabled (if not compiled in) +### PHP version support + +Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version + ## Installation Use [composer](https://getcomposer.org/) to install PhpSpreadsheet into your project: diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md index cdca7001..7ab9d068 100644 --- a/docs/references/features-cross-reference.md +++ b/docs/references/features-cross-reference.md @@ -5,7 +5,7 @@ - Not supported - N/A Cannot be supported - +
@@ -906,7 +906,7 @@ - + diff --git a/docs/topics/calculation-engine.md b/docs/topics/calculation-engine.md index 1480e13f..94fa3a10 100644 --- a/docs/topics/calculation-engine.md +++ b/docs/topics/calculation-engine.md @@ -90,7 +90,7 @@ calculated values, or force recalculation in Excel2003. ### Excel functions that return a Date and Time value Any of the Date and Time functions that return a date value in Excel can -return either an Excel timestamp or a PHP timestamp or date object. +return either an Excel timestamp or a PHP timestamp or `DateTime` object. It is possible for scripts to change the data type used for returning date values by calling the @@ -103,9 +103,9 @@ method: where the following constants can be used for `$returnDateType`: -- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC` -- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_OBJECT` -- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL` +- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC` +- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_OBJECT` +- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL` The method will return a Boolean True on success, False on failure (e.g. if an invalid value is passed in for the return date type). @@ -117,11 +117,11 @@ method can be used to determine the current value of this setting: $returnDateType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(); ``` -The default is RETURNDATE\_PHP\_NUMERIC. +The default is `RETURNDATE_PHP_NUMERIC`. #### PHP Timestamps -If RETURNDATE\_PHP\_NUMERIC is set for the Return Date Type, then any +If `RETURNDATE_PHP_NUMERIC` is set for the Return Date Type, then any date value returned to the calling script by any access to the Date and Time functions in Excel will be an integer value that represents the number of seconds from the PHP/Unix base date. The PHP/Unix base date @@ -131,15 +131,15 @@ while a value of +3600 would be 01:00 hrs on 1st January 1970. This gives PHP a date range of between 14th December 1901 and 19th January 2038. -#### PHP DateTime Objects +#### PHP `DateTime` Objects -If the Return Date Type is set for RETURNDATE\_PHP\_NUMERIC, then any +If the Return Date Type is set for `RETURNDATE_PHP_OBJECT`, then any date value returned to the calling script by any access to the Date and -Time functions in Excel will be a PHP date/time object. +Time functions in Excel will be a PHP `DateTime` object. #### Excel Timestamps -If RETURNDATE\_EXCEL is set for the Return Date Type, then the returned +If `RETURNDATE_EXCEL` is set for the Return Date Type, then the returned date value by any access to the Date and Time functions in Excel will be a floating point value that represents a number of days from the Excel base date. The Excel base date is determined by which calendar Excel @@ -157,8 +157,8 @@ Excel date values by calling the where the following constants can be used for `$baseDate`: -- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_WINDOWS\_1900 -- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_MAC\_1904 +- `\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900` +- `\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904` The method will return a Boolean True on success, False on failure (e.g. if an invalid value is passed in). @@ -170,31 +170,31 @@ be used to determine the current value of this setting: $baseDate = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar(); ``` -The default is CALENDAR\_WINDOWS\_1900. +The default is `CALENDAR_WINDOWS_1900`. #### Functions that return a Date/Time Value -- DATE -- DATEVALUE -- EDATE -- EOMONTH -- NOW -- TIME -- TIMEVALUE -- TODAY +- DATE +- DATEVALUE +- EDATE +- EOMONTH +- NOW +- TIME +- TIMEVALUE +- TODAY ### Excel functions that accept Date and Time values as parameters Date values passed in as parameters to a function can be an Excel -timestamp or a PHP timestamp; or date object; or a string containing a +timestamp or a PHP timestamp; or `DateTime` object; or a string containing a date value (e.g. '1-Jan-2009'). PhpSpreadsheet will attempt to identify their type based on the PHP datatype: An integer numeric value will be treated as a PHP/Unix timestamp. A real (floating point) numeric value will be treated as an Excel -date/timestamp. Any PHP DateTime object will be treated as a DateTime +date/timestamp. Any PHP `DateTime` object will be treated as a `DateTime` object. Any string value (even one containing straight numeric data) -will be converted to a date/time object for validation as a date value +will be converted to a `DateTime` object for validation as a date value based on the server locale settings, so passing through an ambiguous value of '07/08/2008' will be treated as 7th August 2008 if your server settings are UK, but as 8th July 2008 if your server settings are US. @@ -202,7 +202,7 @@ However, if you pass through a value such as '31/12/2008' that would be considered an error by a US-based server, but which is not ambiguous, then PhpSpreadsheet will attempt to correct this to 31st December 2008. If the content of the string doesn’t match any of the formats recognised -by the php date/time object implementation of `strtotime()` (which can +by the php `DateTime` object implementation of `strtotime()` (which can handle a wider range of formats than the normal `strtotime()` function), then the function will return a `#VALUE` error. However, Excel recommends that you should always use date/timestamps for your date @@ -213,28 +213,28 @@ The same principle applies when data is being written to Excel. Cells containing date actual values (rather than Excel functions that return a date value) are always written as Excel dates, converting where necessary. If a cell formatted as a date contains an integer or -date/time object value, then it is converted to an Excel value for +`DateTime` object value, then it is converted to an Excel value for writing: if a cell formatted as a date contains a real value, then no conversion is required. Note that string values are written as strings rather than converted to Excel date timestamp values. #### Functions that expect a Date/Time Value -- DATEDIF -- DAY -- DAYS360 -- EDATE -- EOMONTH -- HOUR -- MINUTE -- MONTH -- NETWORKDAYS -- SECOND -- WEEKDAY -- WEEKNUM -- WORKDAY -- YEAR -- YEARFRAC +- DATEDIF +- DAY +- DAYS360 +- EDATE +- EOMONTH +- HOUR +- MINUTE +- MONTH +- NETWORKDAYS +- SECOND +- WEEKDAY +- WEEKNUM +- WORKDAY +- YEAR +- YEARFRAC ### Helper Methods @@ -243,7 +243,7 @@ number of other methods are available in the \PhpOffice\PhpSpreadsheet\Shared\Date class that can help when working with dates: -#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHP($excelDate) +#### \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($excelDate) Converts a date/time from an Excel date timestamp to return a PHP serialized date/timestamp. @@ -251,17 +251,17 @@ serialized date/timestamp. Note that this method does not trap for Excel dates that fall outside of the valid range for a PHP date timestamp. -#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHPObject($excelDate) +#### \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($excelDate) -Converts a date from an Excel date/timestamp to return a PHP DateTime +Converts a date from an Excel date/timestamp to return a PHP `DateTime` object. #### \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDate) -Converts a PHP serialized date/timestamp or a PHP DateTime object to +Converts a PHP serialized date/timestamp or a PHP `DateTime` object to return an Excel date timestamp. -#### \PhpOffice\PhpSpreadsheet\Shared\Date::FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) +#### \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) Takes year, month and day values (and optional hour, minute and second values) and returns an Excel date timestamp value. @@ -979,7 +979,7 @@ Excel and in PHP. #### DATE -The DATE function returns an Excel timestamp or a PHP timestamp or date +The DATE function returns an Excel timestamp or a PHP timestamp or `DateTime` object representing the date that is referenced by the parameters. ##### Syntax @@ -1025,7 +1025,7 @@ February 27, 2008. **mixed** A date/time stamp that corresponds to the given date. -This could be a PHP timestamp value (integer), a PHP date/time object, +This could be a PHP timestamp value (integer), a PHP `DateTime` object, or an Excel timestamp value (real), depending on the value of \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(). @@ -1093,12 +1093,12 @@ variety of different intervals, such number of years, months, or days. **date1** First Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **date2** Second Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **unit** The interval type to use for the calculation @@ -1230,7 +1230,7 @@ A string, representing a date value. **mixed** A date/time stamp that corresponds to the given date. -This could be a PHP timestamp value (integer), a PHP date/time object, +This could be a PHP timestamp value (integer), a PHP `DateTime` object, or an Excel timestamp value (real), depending on the value of \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(). @@ -1290,7 +1290,7 @@ $retVal = call_user_func_array( ##### Notes -DATEVALUE uses the php date/time object implementation of `strtotime()` +DATEVALUE uses the php `DateTime` object implementation of `strtotime()` (which can handle a wider range of formats than the normal `strtotime()` function), and it is also called for any date parameter passed to other date functions (such as DATEDIF) when the parameter value is a string. @@ -1317,7 +1317,7 @@ integer ranging from 1 to 31. **datetime** Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. ##### Return Value @@ -1371,12 +1371,12 @@ accounting systems. **date1** First Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **date2** Second Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **method** A boolean flag (TRUE or FALSE) @@ -1453,7 +1453,7 @@ Excel `TRUE()` and `FALSE()` functions are used instead. #### EDATE -The EDATE function returns an Excel timestamp or a PHP timestamp or date +The EDATE function returns an Excel timestamp or a PHP timestamp or `DateTime` object representing the date that is the indicated number of months before or after a specified date (the start\_date). Use EDATE to calculate maturity dates or due dates that fall on the same day of the @@ -1467,7 +1467,7 @@ month as the date of issue. **baseDate** Start Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **months** Number of months to add. @@ -1480,7 +1480,7 @@ value yields a past date. **mixed** A date/time stamp that corresponds to the basedate + months. -This could be a PHP timestamp value (integer), a PHP date/time object, +This could be a PHP timestamp value (integer), a PHP `DateTime` object, or an Excel timestamp value (real), depending on the value of \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(). @@ -1526,7 +1526,7 @@ the Analysis ToolPak. #### EOMONTH The EOMONTH function returns an Excel timestamp or a PHP timestamp or -date object representing the date of the last day of the month that is +`DateTime` object representing the date of the last day of the month that is the indicated number of months before or after a specified date (the start\_date). Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month. @@ -1539,7 +1539,7 @@ fall on the last day of the month. **baseDate** Start Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **months** Number of months to add. @@ -1553,7 +1553,7 @@ value yields a past date. **mixed** A date/time stamp that corresponds to the last day of basedate + months. -This could be a PHP timestamp value (integer), a PHP date/time object, +This could be a PHP timestamp value (integer), a PHP `DateTime` object, or an Excel timestamp value (real), depending on the value of \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(). @@ -1607,7 +1607,7 @@ an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.). **datetime** Time. -An Excel date/time value, PHP date timestamp, PHP date object, or a +An Excel date/time value, PHP date timestamp, PHP `DateTime` object, or a date/time represented as a string. ##### Return Value @@ -1665,7 +1665,7 @@ given as an integer, ranging from 0 to 59. **datetime** Time. -An Excel date/time value, PHP date timestamp, PHP date object, or a +An Excel date/time value, PHP date timestamp, PHP `DateTime` object, or a date/time represented as a string. ##### Return Value @@ -1723,7 +1723,7 @@ integer ranging from 1 to 12. **datetime** Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. ##### Return Value @@ -1779,12 +1779,12 @@ a specific term. **startDate** Start Date of the period. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **endDate** End Date of the period. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **holidays** Optional array of Holiday dates. @@ -1831,7 +1831,7 @@ There are no parameters for the `NOW()` function. **mixed** A date/time stamp that corresponds to the current date and time. -This could be a PHP timestamp value (integer), a PHP date/time object, +This could be a PHP timestamp value (integer), a PHP `DateTime` object, or an Excel timestamp value (real), depending on the value of \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(). @@ -1862,7 +1862,7 @@ given as an integer, ranging from 0 to 59. **datetime** Time. -An Excel date/time value, PHP date timestamp, PHP date object, or a +An Excel date/time value, PHP date timestamp, PHP `DateTime` object, or a date/time represented as a string. ##### Return Value @@ -1934,7 +1934,7 @@ modified to return a value between 0 and 6. **datetime** Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. **method** An integer flag (values 0, 1 or 2) @@ -2012,7 +2012,7 @@ The YEAR function returns the year of a date. **datetime** Date. -An Excel date value, PHP date timestamp, PHP date object, or a date +An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date represented as a string. ##### Return Value diff --git a/docs/topics/migration-from-PHPExcel.md b/docs/topics/migration-from-PHPExcel.md index c34fba7f..04374959 100644 --- a/docs/topics/migration-from-PHPExcel.md +++ b/docs/topics/migration-from-PHPExcel.md @@ -192,3 +192,74 @@ $cell = $worksheet->setCellValue('A1', 'value', true); // After $cell = $worksheet->getCell('A1')->setValue('value'); ``` + +## Standardized keys for styling + +Array keys used for styling have been standardized for a more coherent experience. +It now uses the same wording and casing as the getter and setter: + +```php +// Before +$style = [ + 'numberformat' => [ + 'code' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE, + ], + 'font' => [ + 'strike' => true, + 'superScript' => true, + 'subScript' => true, + ], + 'alignment' => [ + 'rotation' => 90, + 'readorder' => Alignment::READORDER_RTL, + 'wrap' => true, + ], + 'borders' => [ + 'diagonaldirection' => Borders::DIAGONAL_BOTH, + 'allborders' => [ + 'style' => Border::BORDER_THIN, + ], + ], + 'fill' => [ + 'type' => Fill::FILL_GRADIENT_LINEAR, + 'startcolor' => [ + 'argb' => 'FFA0A0A0', + ], + 'endcolor' => [ + 'argb' => 'FFFFFFFF', + ], + ], +]; + +// After +$style = [ + 'numberFormat' => [ + 'formatCode' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE, + ], + 'font' => [ + 'strikethrough' => true, + 'superscript' => true, + 'subscript' => true, + ], + 'alignment' => [ + 'textRotation' => 90, + 'readOrder' => Alignment::READORDER_RTL, + 'wrapText' => true, + ], + 'borders' => [ + 'diagonalDirection' => Borders::DIAGONAL_BOTH, + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, + ], + ], + 'fill' => [ + 'fillType' => Fill::FILL_GRADIENT_LINEAR, + 'startColor' => [ + 'argb' => 'FFA0A0A0', + ], + 'endColor' => [ + 'argb' => 'FFFFFFFF', + ], + ], +]; +``` diff --git a/docs/topics/recipes.md b/docs/topics/recipes.md index db2fa417..e094e2c5 100644 --- a/docs/topics/recipes.md +++ b/docs/topics/recipes.md @@ -558,16 +558,16 @@ $styleArray = array( ), 'borders' => array( 'top' => array( - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, ), ), 'fill' => array( - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR, + 'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, - 'startcolor' => array( + 'startColor' => array( 'argb' => 'FFA0A0A0', ), - 'endcolor' => array( + 'endColor' => array( 'argb' => 'FFFFFFFF', ), ), @@ -693,7 +693,7 @@ B2:G8. $styleArray = array( 'borders' => array( 'outline' => array( - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK, + 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK, 'color' => array('argb' => 'FFFF0000'), ), ), @@ -721,7 +721,7 @@ operating on a single cell at a time: Additional shortcut borders come in handy like in the example above. These are the shortcut borders available: -- allborders +- allBorders - outline - inside - vertical @@ -731,10 +731,10 @@ An overview of all border shortcuts can be seen in the following image: ![08-styling-border-options.png](./images/08-styling-border-options.png) -If you simultaneously set e.g. allborders and vertical, then we have +If you simultaneously set e.g. allBorders and vertical, then we have "overlapping" borders, and one of the components has to win over the other where there is border overlap. In PhpSpreadsheet, from weakest to -strongest borders, the list is as follows: allborders, outline/inside, +strongest borders, the list is as follows: allBorders, outline/inside, vertical/horizontal, left/right/top/bottom/diagonal. This border hierarchy can be utilized to achieve various effects in an @@ -757,17 +757,17 @@ fill | getFill() font | getFont() borders | getBorders() alignment | getAlignment() -numberformat | getNumberFormat() +numberFormat | getNumberFormat() protection | getProtection() **\PhpOffice\PhpSpreadsheet\Style\Fill** Array key | Maps to property -----------|------------------- -type | setFillType() +fillType | setFillType() rotation | setRotation() -startcolor | getStartColor() -endcolor | getEndColor() +startColor | getStartColor() +endColor | getEndColor() color | getStartColor() @@ -779,17 +779,17 @@ name | setName() bold | setBold() italic | setItalic() underline | setUnderline() -strike | setStrikethrough() +strikethrough | setStrikethrough() color | getColor() size | setSize() -superScript | setSuperScript() -subScript | setSubScript() +superscript | setSuperscript() +subscript | setSubscript() **\PhpOffice\PhpSpreadsheet\Style\Borders** Array key | Maps to property ------------------|------------------- -allborders | getLeft(); getRight(); getTop(); getBottom() +allBorders | getLeft(); getRight(); getTop(); getBottom() left | getLeft() right | getRight() top | getTop() @@ -797,7 +797,7 @@ bottom | getBottom() diagonal | getDiagonal() vertical | getVertical() horizontal | getHorizontal() -diagonaldirection | setDiagonalDirection() +diagonalDirection | setDiagonalDirection() outline | setOutline() **\PhpOffice\PhpSpreadsheet\Style\Border** @@ -813,8 +813,8 @@ Array key | Maps to property ------------|------------------- horizontal | setHorizontal() vertical | setVertical() -rotation | setTextRotation() -wrap | setWrapText() +textRotation| setTextRotation() +wrapText | setWrapText() shrinkToFit | setShrinkToFit() indent | setIndent() @@ -822,7 +822,7 @@ indent | setIndent() Array key | Maps to property ----------|------------------- -code | setFormatCode() +formatCode | setFormatCode() **\PhpOffice\PhpSpreadsheet\Style\Protection** @@ -910,15 +910,18 @@ practice... ## Setting security on a spreadsheet -Excel offers 3 levels of "protection": document security, sheet security -and cell security. +Excel offers 3 levels of "protection": -Document security allows you to set a password on a complete +- Document: allows you to set a password on a complete spreadsheet, allowing changes to be made only when that password is -entered.Worksheet security offers other security options: you can -disallow inserting rows on a specific sheet, disallow sorting, ... Cell -security offers the option to lock/unlock a cell as well as show/hide -the internal formulaAn example on setting document security: +entered. +- Worksheet: offers other security options: you can +disallow inserting rows on a specific sheet, disallow sorting, ... +- Cell: offers the option to lock/unlock a cell as well as show/hide +the internal formula. + + +An example on setting document security: ``` php $spreadsheet->getSecurity()->setLockWindows(true); diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 00000000..00620004 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,11 @@ +site_name: PhpSpreadsheet Documentation +repo_url: https://github.com/PHPOffice/phpspreadsheet +edit_uri: edit/develop/docs/ + +theme: readthedocs +extra_css: + - extra/extra.css + +extra_javascript: + - extra/extra.js + \ No newline at end of file diff --git a/samples/01_Simple.php b/samples/01_Simple.php index d21de72e..3ba6ba05 100644 --- a/samples/01_Simple.php +++ b/samples/01_Simple.php @@ -1,10 +1,12 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); diff --git a/samples/01_Simple_download_ods.php b/samples/01_Simple_download_ods.php index 8e76e8cf..4031eec6 100644 --- a/samples/01_Simple_download_ods.php +++ b/samples/01_Simple_download_ods.php @@ -1,8 +1,12 @@ isCli()) { echo 'This example should only be run from a Web Browser' . PHP_EOL; @@ -10,7 +14,7 @@ if ($helper->isCli()) { } // Create new Spreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Maarten Balliauw') @@ -52,6 +56,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Ods'); +$writer = IOFactory::createWriter($spreadsheet, 'Ods'); $writer->save('php://output'); exit; diff --git a/samples/01_Simple_download_pdf.php b/samples/01_Simple_download_pdf.php index dc23daa0..04c91a18 100644 --- a/samples/01_Simple_download_pdf.php +++ b/samples/01_Simple_download_pdf.php @@ -1,8 +1,13 @@ isCli()) { echo 'This example should only be run from a Web Browser' . PHP_EOL; @@ -12,11 +17,11 @@ if ($helper->isCli()) { // Change these values to select the Rendering library that you wish to use // and its directory location on your server //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF; -$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF; +$rendererName = Settings::PDF_RENDERER_MPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF; // Create new Spreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Maarten Balliauw') @@ -46,13 +51,13 @@ $spreadsheet->getActiveSheet()->setShowGridLines(false); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $spreadsheet->setActiveSheetIndex(0); -\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); +Settings::setPdfRendererName($rendererName); // Redirect output to a client’s web browser (PDF) header('Content-Type: application/pdf'); header('Content-Disposition: attachment;filename="01simple.pdf"'); header('Cache-Control: max-age=0'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf'); +$writer = IOFactory::createWriter($spreadsheet, 'Pdf'); $writer->save('php://output'); exit; diff --git a/samples/01_Simple_download_xls.php b/samples/01_Simple_download_xls.php index 7bfd5cc6..71fcbc7e 100644 --- a/samples/01_Simple_download_xls.php +++ b/samples/01_Simple_download_xls.php @@ -1,8 +1,12 @@ isCli()) { echo 'This example should only be run from a Web Browser' . PHP_EOL; @@ -10,7 +14,7 @@ if ($helper->isCli()) { } // Create new Spreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Maarten Balliauw') @@ -52,6 +56,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); +$writer = IOFactory::createWriter($spreadsheet, 'Xls'); $writer->save('php://output'); exit; diff --git a/samples/01_Simple_download_xlsx.php b/samples/01_Simple_download_xlsx.php index 3881d4cc..45ba9bc3 100644 --- a/samples/01_Simple_download_xlsx.php +++ b/samples/01_Simple_download_xlsx.php @@ -1,15 +1,19 @@ isCli()) { echo 'This example should only be run from a Web Browser' . PHP_EOL; return; } // Create new Spreadsheet object -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Maarten Balliauw') @@ -51,6 +55,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); exit; diff --git a/samples/02_Types.php b/samples/02_Types.php index 5fef248d..84bc5002 100644 --- a/samples/02_Types.php +++ b/samples/02_Types.php @@ -1,10 +1,16 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -70,41 +76,41 @@ $dateTimeNow = time(); $spreadsheet->getActiveSheet() ->setCellValue('A9', 'Date/Time') ->setCellValue('B9', 'Date') - ->setCellValue('C9', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow)); + ->setCellValue('C9', Date::PHPToExcel($dateTimeNow)); $spreadsheet->getActiveSheet() ->getStyle('C9') ->getNumberFormat() - ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); + ->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2); $spreadsheet->getActiveSheet() ->setCellValue('A10', 'Date/Time') ->setCellValue('B10', 'Time') - ->setCellValue('C10', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow)); + ->setCellValue('C10', Date::PHPToExcel($dateTimeNow)); $spreadsheet->getActiveSheet() ->getStyle('C10') ->getNumberFormat() - ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4); + ->setFormatCode(NumberFormat::FORMAT_DATE_TIME4); $spreadsheet->getActiveSheet() ->setCellValue('A11', 'Date/Time') ->setCellValue('B11', 'Date and Time') - ->setCellValue('C11', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow)); + ->setCellValue('C11', Date::PHPToExcel($dateTimeNow)); $spreadsheet->getActiveSheet() ->getStyle('C11') ->getNumberFormat() - ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME); + ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); $spreadsheet->getActiveSheet() ->setCellValue('A12', 'NULL') ->setCellValue('C12', null); -$richText = new \PhpOffice\PhpSpreadsheet\RichText(); +$richText = new RichText(); $richText->createText('你好 '); $payable = $richText->createTextRun('你 好 吗?'); $payable->getFont()->setBold(true); $payable->getFont()->setItalic(true); -$payable->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN)); +$payable->getFont()->setColor(new Color(Color::COLOR_DARKGREEN)); $richText->createText(', unless specified otherwise on the invoice.'); @@ -112,11 +118,11 @@ $spreadsheet->getActiveSheet() ->setCellValue('A13', 'Rich Text') ->setCellValue('C13', $richText); -$richText2 = new \PhpOffice\PhpSpreadsheet\RichText(); +$richText2 = new RichText(); $richText2->createText("black text\n"); $red = $richText2->createTextRun('red text'); -$red->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED)); +$red->getFont()->setColor(new Color(Color::COLOR_RED)); $spreadsheet->getActiveSheet() ->getCell('C14') diff --git a/samples/03_Formulas.php b/samples/03_Formulas.php index 8896253c..752b99c8 100644 --- a/samples/03_Formulas.php +++ b/samples/03_Formulas.php @@ -1,10 +1,12 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); diff --git a/samples/04_Printing.php b/samples/04_Printing.php index 4434b2f5..e8854821 100644 --- a/samples/04_Printing.php +++ b/samples/04_Printing.php @@ -1,10 +1,15 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -34,22 +39,22 @@ $spreadsheet->getActiveSheet() // Add a drawing to the header $helper->log('Add a drawing to the header'); -$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing(); +$drawing = new HeaderFooterDrawing(); $drawing->setName('PhpSpreadsheet logo'); $drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png'); $drawing->setHeight(36); $spreadsheet->getActiveSheet() ->getHeaderFooter() - ->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT); + ->addImage($drawing, HeaderFooter::IMAGE_HEADER_LEFT); // Set page orientation and size $helper->log('Set page orientation and size'); $spreadsheet->getActiveSheet() ->getPageSetup() - ->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); + ->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); $spreadsheet->getActiveSheet() ->getPageSetup() - ->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); + ->setPaperSize(PageSetup::PAPERSIZE_A4); // Rename worksheet $helper->log('Rename worksheet'); diff --git a/samples/07_Reader.php b/samples/07_Reader.php index 2e7b9610..05186521 100644 --- a/samples/07_Reader.php +++ b/samples/07_Reader.php @@ -1,15 +1,18 @@ getTemporaryFilename(); -$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); +$writer = new Xlsx($sampleSpreadsheet); $writer->save($filename); $callStartTime = microtime(true); -$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); +$spreadsheet = IOFactory::load($filename); $helper->logRead('Xlsx', $filename, $callStartTime); // Save diff --git a/samples/08_Conditional_formatting.php b/samples/08_Conditional_formatting.php index 86019305..36c3aaee 100644 --- a/samples/08_Conditional_formatting.php +++ b/samples/08_Conditional_formatting.php @@ -1,10 +1,16 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -47,30 +53,30 @@ $spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(12); // Add conditional formatting $helper->log('Add conditional formatting'); -$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); -$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) - ->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BETWEEN) +$conditional1 = new Conditional(); +$conditional1->setConditionType(Conditional::CONDITION_CELLIS) + ->setOperatorType(Conditional::OPERATOR_BETWEEN) ->addCondition('200') ->addCondition('400'); -$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_YELLOW); +$conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_YELLOW); $conditional1->getStyle()->getFont()->setBold(true); -$conditional1->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); +$conditional1->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); -$conditional2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); -$conditional2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) - ->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN) +$conditional2 = new Conditional(); +$conditional2->setConditionType(Conditional::CONDITION_CELLIS) + ->setOperatorType(Conditional::OPERATOR_LESSTHAN) ->addCondition('0'); -$conditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED); +$conditional2->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED); $conditional2->getStyle()->getFont()->setItalic(true); -$conditional2->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); +$conditional2->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); -$conditional3 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); -$conditional3->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) - ->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL) +$conditional3 = new Conditional(); +$conditional3->setConditionType(Conditional::CONDITION_CELLIS) + ->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL) ->addCondition('0'); -$conditional3->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN); +$conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN); $conditional3->getStyle()->getFont()->setItalic(true); -$conditional3->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); +$conditional3->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles(); array_push($conditionalStyles, $conditional1); @@ -98,8 +104,8 @@ $spreadsheet->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $spread // Set page orientation and size $helper->log('Set page orientation and size'); -$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT); -$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); +$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_PORTRAIT); +$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4); // Rename worksheet $helper->log('Rename worksheet'); diff --git a/samples/08_Conditional_formatting_2.php b/samples/08_Conditional_formatting_2.php index 87bd2851..07d2361d 100644 --- a/samples/08_Conditional_formatting_2.php +++ b/samples/08_Conditional_formatting_2.php @@ -1,10 +1,15 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -32,22 +37,22 @@ $spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()->getStyle('A1:A8') ->getNumberFormat() ->setFormatCode( - \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00 + NumberFormat::FORMAT_PERCENTAGE_00 ); // Add conditional formatting $helper->log('Add conditional formatting'); -$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); -$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) - ->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN) +$conditional1 = new Conditional(); +$conditional1->setConditionType(Conditional::CONDITION_CELLIS) + ->setOperatorType(Conditional::OPERATOR_LESSTHAN) ->addCondition('0'); -$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED); +$conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED); -$conditional3 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); -$conditional3->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) - ->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL) +$conditional3 = new Conditional(); +$conditional3->setConditionType(Conditional::CONDITION_CELLIS) + ->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL) ->addCondition('1'); -$conditional3->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN); +$conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1')->getConditionalStyles(); array_push($conditionalStyles, $conditional1); diff --git a/samples/09_Pagebreaks.php b/samples/09_Pagebreaks.php index 9b91d2f0..c4cf33af 100644 --- a/samples/09_Pagebreaks.php +++ b/samples/09_Pagebreaks.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -36,7 +39,7 @@ for ($i = 2; $i <= 50; ++$i) { // Add page breaks every 10 rows if ($i % 10 == 0) { // Add a page break - $spreadsheet->getActiveSheet()->setBreak('A' . $i, \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_ROW); + $spreadsheet->getActiveSheet()->setBreak('A' . $i, Worksheet::BREAK_ROW); } } diff --git a/samples/10_Autofilter.php b/samples/10_Autofilter.php index 45955a8c..7058e6a5 100644 --- a/samples/10_Autofilter.php +++ b/samples/10_Autofilter.php @@ -1,10 +1,12 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); diff --git a/samples/10_Autofilter_selection_1.php b/samples/10_Autofilter_selection_1.php index 6f74f483..1b34b019 100644 --- a/samples/10_Autofilter_selection_1.php +++ b/samples/10_Autofilter_selection_1.php @@ -1,10 +1,16 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -48,7 +54,7 @@ foreach ($years as $year) { foreach ($countries as $country) { $endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); for ($i = 1; $i <= $endDays; ++$i) { - $eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( + $eDate = Date::formattedPHPToExcel( $year, $period, $i @@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); -$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); -$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); +$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2); +$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14); $spreadsheet->getActiveSheet()->freezePane('A2'); @@ -104,45 +110,45 @@ $helper->log('Set active filters'); // Filter the Country column on a filter value of countries beginning with the letter U (or Japan) // We use * as a wildcard, so specify as U* and using a wildcard requires customFilter $autoFilter->getColumn('C') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, 'u*' ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); $autoFilter->getColumn('C') ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, 'japan' ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); // Filter the Date column on a filter value of the first day of every period of the current year // We us a dateGroup ruletype for this, although it is still a standard filter foreach ($periods as $period) { $endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear)); $autoFilter->getColumn('D') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, [ 'year' => $currentYear, 'month' => $period, 'day' => $endDate, ] ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_DATEGROUP); } // Display only sales values that are blank // Standard filter, operator equals, and value of NULL $autoFilter->getColumn('E') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, '' ); diff --git a/samples/10_Autofilter_selection_2.php b/samples/10_Autofilter_selection_2.php index 1802d0ea..9bfb254a 100644 --- a/samples/10_Autofilter_selection_2.php +++ b/samples/10_Autofilter_selection_2.php @@ -1,10 +1,16 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -48,7 +54,7 @@ foreach ($years as $year) { foreach ($countries as $country) { $endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); for ($i = 1; $i <= $endDays; ++$i) { - $eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( + $eDate = Date::formattedPHPToExcel( $year, $period, $i @@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); -$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); -$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); +$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2); +$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14); $spreadsheet->getActiveSheet()->freezePane('A2'); @@ -104,39 +110,39 @@ $helper->log('Set active filters'); // Filter the Country column on a filter value of Germany // As it's just a simple value filter, we can use FILTERTYPE_FILTER $autoFilter->getColumn('C') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, 'Germany' ); // Filter the Date column on a filter value of the year to date $autoFilter->getColumn('D') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, null, - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE + Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER); // Display only sales values that are between 400 and 600 $autoFilter->getColumn('E') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL, + Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL, 400 ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); $autoFilter->getColumn('E') - ->setJoin(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND) + ->setJoin(Column::AUTOFILTER_COLUMN_JOIN_AND) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL, + Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL, 600 ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); // Save $helper->write($spreadsheet, __FILE__); diff --git a/samples/10_Autofilter_selection_display.php b/samples/10_Autofilter_selection_display.php index 0f431e66..2be654d3 100644 --- a/samples/10_Autofilter_selection_display.php +++ b/samples/10_Autofilter_selection_display.php @@ -1,10 +1,16 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -48,7 +54,7 @@ foreach ($years as $year) { foreach ($countries as $country) { $endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); for ($i = 1; $i <= $endDays; ++$i) { - $eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( + $eDate = Date::formattedPHPToExcel( $year, $period, $i @@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); -$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); -$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); +$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2); +$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14); $spreadsheet->getActiveSheet()->freezePane('A2'); @@ -104,45 +110,45 @@ $helper->log('Set active filters'); // Filter the Country column on a filter value of countries beginning with the letter U (or Japan) // We use * as a wildcard, so specify as U* and using a wildcard requires customFilter $autoFilter->getColumn('C') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, 'u*' ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); $autoFilter->getColumn('C') ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, 'japan' ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); // Filter the Date column on a filter value of the first day of every period of the current year // We us a dateGroup ruletype for this, although it is still a standard filter foreach ($periods as $period) { $endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear)); $autoFilter->getColumn('D') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, [ 'year' => $currentYear, 'month' => $period, 'day' => $endDate, ] ) - ->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP); + ->setRuleType(Rule::AUTOFILTER_RULETYPE_DATEGROUP); } // Display only sales values that are blank // Standard filter, operator equals, and value of NULL $autoFilter->getColumn('E') - ->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) + ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER) ->createRule() ->setRule( - \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + Rule::AUTOFILTER_COLUMN_RULE_EQUAL, '' ); diff --git a/samples/11_Documentsecurity.php b/samples/11_Documentsecurity.php index 2224808a..0298e7ee 100644 --- a/samples/11_Documentsecurity.php +++ b/samples/11_Documentsecurity.php @@ -1,10 +1,12 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); diff --git a/samples/12_CellProtection.php b/samples/12_CellProtection.php index 4ef97b01..a84bb8a5 100644 --- a/samples/12_CellProtection.php +++ b/samples/12_CellProtection.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -37,7 +40,7 @@ $spreadsheet->getActiveSheet()->getProtection()->setSheet(true); $spreadsheet->getActiveSheet() ->getStyle('A2:B2') ->getProtection()->setLocked( - \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED + Protection::PROTECTION_UNPROTECTED ); // Save diff --git a/samples/13_Calculation.php b/samples/13_Calculation.php index d620a6f2..e143e9ab 100644 --- a/samples/13_Calculation.php +++ b/samples/13_Calculation.php @@ -1,17 +1,20 @@ log('List implemented functions'); -$calc = \PhpOffice\PhpSpreadsheet\Calculation::getInstance(); +$calc = Calculation::getInstance(); print_r($calc->getImplementedFunctionNames()); // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Add some data, we will use some formulas here $helper->log('Add some data and formulas'); diff --git a/samples/13_CalculationCyclicFormulae.php b/samples/13_CalculationCyclicFormulae.php index ea1be404..968c467c 100644 --- a/samples/13_CalculationCyclicFormulae.php +++ b/samples/13_CalculationCyclicFormulae.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Add some data, we will use some formulas here $helper->log('Add some data and formulas'); @@ -13,7 +16,7 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', '=B1') ->setCellValue('B1', '=A1+1') ->setCellValue('B2', '=A2'); -\PhpOffice\PhpSpreadsheet\Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 100; +Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 100; // Calculated data $helper->log('Calculated data'); diff --git a/samples/14_Xls.php b/samples/14_Xls.php index 86d125b9..03a38d28 100644 --- a/samples/14_Xls.php +++ b/samples/14_Xls.php @@ -1,10 +1,12 @@ getFilename(__FILE__, 'xls'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); +$writer = IOFactory::createWriter($spreadsheet, 'Xls'); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/15_Datavalidation.php b/samples/15_Datavalidation.php index bd7299d6..416a102a 100644 --- a/samples/15_Datavalidation.php +++ b/samples/15_Datavalidation.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -35,8 +38,8 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', 'Cell B3 and B5 contain data // Set data validation $helper->log('Set data validation'); $validation = $spreadsheet->getActiveSheet()->getCell('B3')->getDataValidation(); -$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE); -$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP); +$validation->setType(DataValidation::TYPE_WHOLE); +$validation->setErrorStyle(DataValidation::STYLE_STOP); $validation->setAllowBlank(true); $validation->setShowInputMessage(true); $validation->setShowErrorMessage(true); @@ -48,8 +51,8 @@ $validation->setFormula1(10); $validation->setFormula2(20); $validation = $spreadsheet->getActiveSheet()->getCell('B5')->getDataValidation(); -$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST); -$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION); +$validation->setType(DataValidation::TYPE_LIST); +$validation->setErrorStyle(DataValidation::STYLE_INFORMATION); $validation->setAllowBlank(false); $validation->setShowInputMessage(true); $validation->setShowErrorMessage(true); @@ -61,8 +64,8 @@ $validation->setPrompt('Please pick a value from the drop-down list.'); $validation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!! $validation = $spreadsheet->getActiveSheet()->getCell('B7')->getDataValidation(); -$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST); -$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION); +$validation->setType(DataValidation::TYPE_LIST); +$validation->setErrorStyle(DataValidation::STYLE_INFORMATION); $validation->setAllowBlank(false); $validation->setShowInputMessage(true); $validation->setShowErrorMessage(true); diff --git a/samples/16_Csv.php b/samples/16_Csv.php index 63cbd53e..0c1db51d 100644 --- a/samples/16_Csv.php +++ b/samples/16_Csv.php @@ -1,10 +1,12 @@ log('Write to CSV format'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',') +$writer = IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',') ->setEnclosure('"') ->setSheetIndex(0); @@ -15,7 +17,7 @@ $helper->logWrite($writer, $filename, $callStartTime); $helper->log('Read from CSV format'); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Csv')->setDelimiter(',') +$reader = IOFactory::createReader('Csv')->setDelimiter(',') ->setEnclosure('"') ->setSheetIndex(0); @@ -28,7 +30,7 @@ $helper->write($spreadsheetFromCSV, __FILE__, ['Xlsx']); // Write CSV $filenameCSV = $helper->getFilename(__FILE__, 'csv'); -$writerCSV = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheetFromCSV, 'Csv'); +$writerCSV = IOFactory::createWriter($spreadsheetFromCSV, 'Csv'); $writerCSV->setExcelCompatibility(true); $callStartTime = microtime(true); diff --git a/samples/17_Html.php b/samples/17_Html.php index d3dfd5b0..9ea9f0bd 100644 --- a/samples/17_Html.php +++ b/samples/17_Html.php @@ -1,10 +1,12 @@ getFilename(__FILE__, 'html'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html'); +$writer = IOFactory::createWriter($spreadsheet, 'Html'); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/18_Extendedcalculation.php b/samples/18_Extendedcalculation.php index b7d45b33..e459e9d3 100644 --- a/samples/18_Extendedcalculation.php +++ b/samples/18_Extendedcalculation.php @@ -1,16 +1,18 @@ log('List implemented functions'); -$calc = \PhpOffice\PhpSpreadsheet\Calculation::getInstance(); +$calc = Calculation::getInstance(); print_r($calc->getImplementedFunctionNames()); // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Add some data, we will use some formulas here $helper->log('Add some data'); diff --git a/samples/19_Namedrange.php b/samples/19_Namedrange.php index ea39a335..53c25660 100644 --- a/samples/19_Namedrange.php +++ b/samples/19_Namedrange.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -28,8 +31,8 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', 'Firstname:') // Define named ranges $helper->log('Define named ranges'); -$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('PersonName', $spreadsheet->getActiveSheet(), 'B1')); -$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('PersonLN', $spreadsheet->getActiveSheet(), 'B2')); +$spreadsheet->addNamedRange(new NamedRange('PersonName', $spreadsheet->getActiveSheet(), 'B1')); +$spreadsheet->addNamedRange(new NamedRange('PersonLN', $spreadsheet->getActiveSheet(), 'B2')); // Rename named ranges $helper->log('Rename named ranges'); diff --git a/samples/20_Read_Excel2003XML.php b/samples/20_Read_Excel2003XML.php index e6c1a797..6e2f464d 100644 --- a/samples/20_Read_Excel2003XML.php +++ b/samples/20_Read_Excel2003XML.php @@ -1,10 +1,12 @@ logRead('Xml', $filename, $callStartTime); // Save diff --git a/samples/20_Read_Gnumeric.php b/samples/20_Read_Gnumeric.php index d390dc14..d2c598c4 100644 --- a/samples/20_Read_Gnumeric.php +++ b/samples/20_Read_Gnumeric.php @@ -1,10 +1,12 @@ logRead('Gnumeric', $filename, $callStartTime); // Save diff --git a/samples/20_Read_Ods.php b/samples/20_Read_Ods.php index 37f7d4f7..10a8275c 100644 --- a/samples/20_Read_Ods.php +++ b/samples/20_Read_Ods.php @@ -1,10 +1,12 @@ logRead('Ods', $filename, $callStartTime); // Save diff --git a/samples/20_Read_Sylk.php b/samples/20_Read_Sylk.php index b3baa5a5..c07c9647 100644 --- a/samples/20_Read_Sylk.php +++ b/samples/20_Read_Sylk.php @@ -1,10 +1,12 @@ logRead('Slk', $filename, $callStartTime); // Save diff --git a/samples/20_Read_Xls.php b/samples/20_Read_Xls.php index ef8b1eda..542f96a2 100644 --- a/samples/20_Read_Xls.php +++ b/samples/20_Read_Xls.php @@ -1,19 +1,21 @@ getTemporaryFilename('xls'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); +$writer = IOFactory::createWriter($spreadsheet, 'Xls'); $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); // Read Xls file $callStartTime = microtime(true); -$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); +$spreadsheet = IOFactory::load($filename); $helper->logRead('Xls', $filename, $callStartTime); // Save diff --git a/samples/21_Pdf_Domdf.php b/samples/21_Pdf_Domdf.php index bc891d6f..f13ca72c 100644 --- a/samples/21_Pdf_Domdf.php +++ b/samples/21_Pdf_Domdf.php @@ -1,5 +1,8 @@ log('Hide grid lines'); $spreadsheet->getActiveSheet()->setShowGridLines(false); $helper->log('Set orientation to landscape'); -$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); +$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); -$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF; +$rendererName = Settings::PDF_RENDERER_DOMPDF; $helper->log("Write to PDF format using {$rendererName}"); -\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); +Settings::setPdfRendererName($rendererName); // Save $helper->write($spreadsheet, __FILE__, ['Pdf']); diff --git a/samples/21_Pdf_TCPDF.php b/samples/21_Pdf_TCPDF.php index 980069fc..1bf75c84 100644 --- a/samples/21_Pdf_TCPDF.php +++ b/samples/21_Pdf_TCPDF.php @@ -1,5 +1,8 @@ log('Hide grid lines'); $spreadsheet->getActiveSheet()->setShowGridLines(false); $helper->log('Set orientation to landscape'); -$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); +$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); -$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF; +$rendererName = Settings::PDF_RENDERER_TCPDF; $helper->log("Write to PDF format using {$rendererName}"); -\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); +Settings::setPdfRendererName($rendererName); // Save $helper->write($spreadsheet, __FILE__, ['Pdf']); diff --git a/samples/21_Pdf_mPDF.php b/samples/21_Pdf_mPDF.php index b5327a61..8e46f838 100644 --- a/samples/21_Pdf_mPDF.php +++ b/samples/21_Pdf_mPDF.php @@ -1,5 +1,8 @@ log('Hide grid lines'); $spreadsheet->getActiveSheet()->setShowGridLines(false); $helper->log('Set orientation to landscape'); -$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); +$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); -$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF; +$rendererName = Settings::PDF_RENDERER_MPDF; $helper->log("Write to PDF format using {$rendererName}"); -\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); +Settings::setPdfRendererName($rendererName); // Save $helper->write($spreadsheet, __FILE__, ['Pdf']); diff --git a/samples/22_Heavily_formatted.php b/samples/22_Heavily_formatted.php index 541f3149..feb2d957 100644 --- a/samples/22_Heavily_formatted.php +++ b/samples/22_Heavily_formatted.php @@ -1,10 +1,14 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -22,19 +26,19 @@ $spreadsheet->setActiveSheetIndex(0); $spreadsheet->getActiveSheet()->getStyle('A1:T100')->applyFromArray( ['fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, + 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFCCFFCC'], ], 'borders' => [ - 'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], - 'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], + 'bottom' => ['borderStyle' => Border::BORDER_THIN], + 'right' => ['borderStyle' => Border::BORDER_MEDIUM], ], ] ); $spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray( ['fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, + 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFFFFF00'], ], ] diff --git a/samples/23_Sharedstyles.php b/samples/23_Sharedstyles.php index 48ffb1ad..1405431c 100644 --- a/samples/23_Sharedstyles.php +++ b/samples/23_Sharedstyles.php @@ -1,10 +1,15 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -20,29 +25,29 @@ $spreadsheet->getProperties()->setCreator('Maarten Balliauw') $helper->log('Add some data'); $spreadsheet->setActiveSheetIndex(0); -$sharedStyle1 = new \PhpOffice\PhpSpreadsheet\Style(); -$sharedStyle2 = new \PhpOffice\PhpSpreadsheet\Style(); +$sharedStyle1 = new Style(); +$sharedStyle2 = new Style(); $sharedStyle1->applyFromArray( ['fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, + 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFCCFFCC'], ], 'borders' => [ - 'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], - 'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], + 'bottom' => ['borderStyle' => Border::BORDER_THIN], + 'right' => ['borderStyle' => Border::BORDER_MEDIUM], ], ] ); $sharedStyle2->applyFromArray( ['fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, + 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFFFFF00'], ], 'borders' => [ - 'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], - 'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], + 'bottom' => ['borderStyle' => Border::BORDER_THIN], + 'right' => ['borderStyle' => Border::BORDER_MEDIUM], ], ] ); diff --git a/samples/24_Readfilter.php b/samples/24_Readfilter.php index 17912705..f5258604 100644 --- a/samples/24_Readfilter.php +++ b/samples/24_Readfilter.php @@ -2,17 +2,20 @@ namespace PhpOffice\PhpSpreadsheet; +use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; + require __DIR__ . '/Header.php'; // Write temporary file $largeSpreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php'; -$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($largeSpreadsheet); +$writer = new Xlsx($largeSpreadsheet); $filename = $helper->getTemporaryFilename(); $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); -class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter +class MyReadFilter implements IReadFilter { public function readCell($column, $row, $worksheetName = '') { @@ -26,7 +29,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter } $helper->log('Load from Xlsx file'); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); +$reader = IOFactory::createReader('Xlsx'); $reader->setReadFilter(new MyReadFilter()); $callStartTime = microtime(true); $spreadsheet = $reader->load($filename); diff --git a/samples/25_In_memory_image.php b/samples/25_In_memory_image.php index aef166f1..5756bd3e 100644 --- a/samples/25_In_memory_image.php +++ b/samples/25_In_memory_image.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -24,12 +27,12 @@ imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor); // Add a drawing to the worksheet $helper->log('Add a drawing to the worksheet'); -$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing(); +$drawing = new MemoryDrawing(); $drawing->setName('Sample image'); $drawing->setDescription('Sample image'); $drawing->setImageResource($gdImage); -$drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG); -$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT); +$drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG); +$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT); $drawing->setHeight(36); $drawing->setWorksheet($spreadsheet->getActiveSheet()); diff --git a/samples/26_Utf8.php b/samples/26_Utf8.php index 105b0f94..790640a0 100644 --- a/samples/26_Utf8.php +++ b/samples/26_Utf8.php @@ -1,16 +1,19 @@ log('Load Xlsx template file'); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); +$reader = IOFactory::createReader('Xlsx'); $spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx'); /* at this point, we could do some manipulations with the template, but we skip this step */ @@ -18,7 +21,7 @@ $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']); // Export to PDF (.pdf) $helper->log('Write to PDF format'); -\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); +Settings::setPdfRendererName($rendererName); $helper->write($spreadsheet, __FILE__, ['Pdf']); // Remove first two rows with field headers before exporting to CSV @@ -28,7 +31,7 @@ $worksheet->removeRow(1, 2); // Export to CSV (.csv) $helper->log('Write to CSV format'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv'); +$writer = IOFactory::createWriter($spreadsheet, 'Csv'); $filename = $helper->getFilename(__FILE__, 'csv'); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/27_Images_Xls.php b/samples/27_Images_Xls.php index 8fc7bf2b..4923efe2 100644 --- a/samples/27_Images_Xls.php +++ b/samples/27_Images_Xls.php @@ -1,10 +1,12 @@ log('Load Xlsx template file'); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls'); +$reader = IOFactory::createReader('Xls'); $spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls'); // Save diff --git a/samples/28_Iterator.php b/samples/28_Iterator.php index 95bed125..5dbb49e4 100644 --- a/samples/28_Iterator.php +++ b/samples/28_Iterator.php @@ -1,16 +1,19 @@ getTemporaryFilename(); -$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); +$writer = new Xlsx($sampleSpreadsheet); $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); $callStartTime = microtime(true); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); +$reader = IOFactory::createReader('Xlsx'); $spreadsheet = $reader->load($filename); $helper->logRead('Xlsx', $filename, $callStartTime); $helper->log('Iterate worksheets'); diff --git a/samples/29_Advanced_value_binder.php b/samples/29_Advanced_value_binder.php index 260a612b..7f22c8f0 100644 --- a/samples/29_Advanced_value_binder.php +++ b/samples/29_Advanced_value_binder.php @@ -1,5 +1,7 @@ log('Set value binder'); -\PhpOffice\PhpSpreadsheet\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder()); +Cell::setValueBinder(new Cell\AdvancedValueBinder()); // Create new Spreadsheet object $helper->log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); diff --git a/samples/30_Template.php b/samples/30_Template.php index ed6f588e..4c6d867b 100644 --- a/samples/30_Template.php +++ b/samples/30_Template.php @@ -1,9 +1,12 @@ log('Load from Xls template'); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls'); +$reader = IOFactory::createReader('Xls'); $spreadsheet = $reader->load(__DIR__ . '/templates/30template.xls'); $helper->log('Add new data to the template'); @@ -21,7 +24,7 @@ $data = [['title' => 'Excel for dummies', ], ]; -$spreadsheet->getActiveSheet()->setCellValue('D1', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(time())); +$spreadsheet->getActiveSheet()->setCellValue('D1', Date::PHPToExcel(time())); $baseRow = 5; foreach ($data as $r => $dataRow) { diff --git a/samples/31_Document_properties_write.php b/samples/31_Document_properties_write.php index 76aeaa62..15936ffa 100644 --- a/samples/31_Document_properties_write.php +++ b/samples/31_Document_properties_write.php @@ -1,11 +1,14 @@ load($inputFileName); $helper->logRead($inputFileType, $inputFileName, $callStartTime); @@ -18,7 +21,7 @@ $spreadsheet->getProperties()->setTitle('Office 2007 XLSX Test Document') // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); @@ -28,7 +31,7 @@ $helper->logEndingNotes(); // Reread File $helper->log('Reread Xlsx file'); -$spreadsheetRead = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); +$spreadsheetRead = IOFactory::load($filename); // Set properties $helper->log('Get properties'); @@ -53,9 +56,9 @@ $customProperties = $spreadsheet->getProperties()->getCustomProperties(); foreach ($customProperties as $customProperty) { $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty); $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty); - if ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE) { + if ($propertyType == Properties::PROPERTY_TYPE_DATE) { $formattedValue = date('d-M-Y H:i:s', $propertyValue); - } elseif ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN) { + } elseif ($propertyType == Properties::PROPERTY_TYPE_BOOLEAN) { $formattedValue = $propertyValue ? 'TRUE' : 'FALSE'; } else { $formattedValue = $propertyValue; diff --git a/samples/31_Document_properties_write_xls.php b/samples/31_Document_properties_write_xls.php index 38f15354..a427be18 100644 --- a/samples/31_Document_properties_write_xls.php +++ b/samples/31_Document_properties_write_xls.php @@ -1,11 +1,14 @@ load($inputFileName); $helper->logRead($inputFileType, $inputFileName, $callStartTime); @@ -18,7 +21,7 @@ $spreadsheet->getProperties()->setTitle('Office 95 XLS Test Document') // Save Excel 95 file $filename = $helper->getFilename(__FILE__, 'xls'); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); +$writer = IOFactory::createWriter($spreadsheet, 'Xls'); $callStartTime = microtime(true); $writer->save($filename); $helper->logWrite($writer, $filename, $callStartTime); @@ -28,7 +31,7 @@ $helper->logEndingNotes(); // Reread File $helper->log('Reread Xls file'); -$spreadsheetRead = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); +$spreadsheetRead = IOFactory::load($filename); // Set properties $helper->log('Get properties'); @@ -53,9 +56,9 @@ $customProperties = $spreadsheet->getProperties()->getCustomProperties(); foreach ($customProperties as $customProperty) { $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty); $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty); - if ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE) { + if ($propertyType == Properties::PROPERTY_TYPE_DATE) { $formattedValue = date('d-M-Y H:i:s', $propertyValue); - } elseif ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN) { + } elseif ($propertyType == Properties::PROPERTY_TYPE_BOOLEAN) { $formattedValue = $propertyValue ? 'TRUE' : 'FALSE'; } else { $formattedValue = $propertyValue; diff --git a/samples/32_Chart_read_write.php b/samples/32_Chart_read_write.php index 2ae0b8ae..6668280c 100644 --- a/samples/32_Chart_read_write.php +++ b/samples/32_Chart_read_write.php @@ -1,5 +1,7 @@ log('File ' . $inputFileNameShort . ' does not exist'); continue; } - $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + $reader = IOFactory::createReader($inputFileType); $reader->setIncludeCharts(true); $callStartTime = microtime(true); $spreadsheet = $reader->load($inputFileName); @@ -69,7 +71,7 @@ foreach ($inputFileNames as $inputFileName) { } $outputFileName = $helper->getFilename($inputFileName); - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); + $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($outputFileName); diff --git a/samples/32_Chart_read_write_HTML.php b/samples/32_Chart_read_write_HTML.php index aa697efd..ac2d1e1b 100644 --- a/samples/32_Chart_read_write_HTML.php +++ b/samples/32_Chart_read_write_HTML.php @@ -1,14 +1,17 @@ log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure'); return; @@ -35,7 +38,7 @@ foreach ($inputFileNames as $inputFileName) { $helper->log("Load Test from $inputFileType file " . $inputFileNameShort); - $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + $reader = IOFactory::createReader($inputFileType); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($inputFileName); @@ -83,7 +86,7 @@ foreach ($inputFileNames as $inputFileName) { // Save $filename = $helper->getFilename($inputFileName); - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html'); + $writer = IOFactory::createWriter($spreadsheet, 'Html'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/32_Chart_read_write_PDF.php b/samples/32_Chart_read_write_PDF.php index d41f6728..ffd4ba40 100644 --- a/samples/32_Chart_read_write_PDF.php +++ b/samples/32_Chart_read_write_PDF.php @@ -1,22 +1,25 @@ log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure'); return; @@ -43,7 +46,7 @@ foreach ($inputFileNames as $inputFileName) { $helper->log("Load Test from $inputFileType file " . $inputFileNameShort); - $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + $reader = IOFactory::createReader($inputFileType); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($inputFileName); @@ -91,7 +94,7 @@ foreach ($inputFileNames as $inputFileName) { // Save $filename = $helper->getFilename($inputFileName); - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf'); + $writer = IOFactory::createWriter($spreadsheet, 'Pdf'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_area.php b/samples/33_Chart_create_area.php index 550f8133..2fba7ca7 100644 --- a/samples/33_Chart_create_area.php +++ b/samples/33_Chart_create_area.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,9 +31,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -35,7 +43,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -45,15 +53,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_AREACHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping +$series = new DataSeries( + DataSeries::TYPE_AREACHART, // plotType + DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory @@ -61,15 +69,15 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); +$legend = new Legend(Legend::POSITION_TOPRIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test %age-Stacked Area Chart'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test %age-Stacked Area Chart'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -89,7 +97,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_bar.php b/samples/33_Chart_create_bar.php index 6889956b..96ac5ef7 100644 --- a/samples/33_Chart_create_bar.php +++ b/samples/33_Chart_create_bar.php @@ -1,5 +1,6 @@ getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_bar_stacked.php b/samples/33_Chart_create_bar_stacked.php index f4bb87bc..86178d79 100644 --- a/samples/33_Chart_create_bar_stacked.php +++ b/samples/33_Chart_create_bar_stacked.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,9 +31,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -35,7 +43,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -45,15 +53,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STACKED, // plotGrouping +$series = new DataSeries( + DataSeries::TYPE_BARCHART, // plotType + DataSeries::GROUPING_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory @@ -61,18 +69,18 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set additional dataseries parameters // Make it a horizontal bar rather than a vertical column graph -$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_BAR); +$series->setPlotDirection(DataSeries::DIRECTION_BAR); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend = new Legend(Legend::POSITION_RIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Chart'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test Chart'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -92,7 +100,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_column.php b/samples/33_Chart_create_column.php index 1d4023cf..49d65c75 100644 --- a/samples/33_Chart_create_column.php +++ b/samples/33_Chart_create_column.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,9 +31,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -35,7 +43,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -45,15 +53,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping +$series = new DataSeries( + DataSeries::TYPE_BARCHART, // plotType + DataSeries::GROUPING_STANDARD, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory @@ -61,18 +69,18 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set additional dataseries parameters // Make it a vertical column rather than a horizontal bar graph -$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); +$series->setPlotDirection(DataSeries::DIRECTION_COL); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend = new Legend(Legend::POSITION_RIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Column Chart'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test Column Chart'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -92,7 +100,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_column_2.php b/samples/33_Chart_create_column_2.php index d459dd5b..f4afcedb 100644 --- a/samples/33_Chart_create_column_2.php +++ b/samples/33_Chart_create_column_2.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -31,9 +39,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 'Budget' - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 'Forecast' - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$E$1', null, 1), // 'Actual' + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 'Budget' + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 'Forecast' + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$E$1', null, 1), // 'Actual' ]; // Set the X-Axis Labels // Datatype @@ -43,7 +51,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$B$13', null, 12), // Q1 to Q4 for 2010 to 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$B$13', null, 12), // Q1 to Q4 for 2010 to 2012 ]; // Set the Data values for each data series we want to plot // Datatype @@ -53,15 +61,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$E$2:$E$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$E$2:$E$13', null, 12), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_CLUSTERED, // plotGrouping +$series = new DataSeries( + DataSeries::TYPE_BARCHART, // plotType + DataSeries::GROUPING_CLUSTERED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory @@ -69,19 +77,19 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set additional dataseries parameters // Make it a vertical column rather than a horizontal bar graph -$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); +$series->setPlotDirection(DataSeries::DIRECTION_COL); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_BOTTOM, null, false); +$legend = new Legend(Legend::POSITION_BOTTOM, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Grouped Column Chart'); -$xAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Financial Period'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test Grouped Column Chart'); +$xAxisLabel = new Title('Financial Period'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -101,7 +109,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_composite.php b/samples/33_Chart_create_composite.php index 57abd991..692209f8 100644 --- a/samples/33_Chart_create_composite.php +++ b/samples/33_Chart_create_composite.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -31,13 +39,13 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // Temperature + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // Temperature ]; $dataSeriesLabels2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // Rainfall + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // Rainfall ]; $dataSeriesLabels3 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // Humidity + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // Humidity ]; // Set the X-Axis Labels @@ -48,7 +56,7 @@ $dataSeriesLabels3 = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec ]; // Set the Data values for each data series we want to plot @@ -59,13 +67,13 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$13', null, 12), ]; // Build the dataseries -$series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_CLUSTERED, // plotGrouping +$series1 = new DataSeries( + DataSeries::TYPE_BARCHART, // plotType + DataSeries::GROUPING_CLUSTERED, // plotGrouping range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel $xAxisTickValues, // plotCategory @@ -73,7 +81,7 @@ $series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set additional dataseries parameters // Make it a vertical column rather than a horizontal bar graph -$series1->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); +$series1->setPlotDirection(DataSeries::DIRECTION_COL); // Set the Data values for each data series we want to plot // Datatype @@ -83,13 +91,13 @@ $series1->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION // Data values // Data Marker $dataSeriesValues2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$13', null, 12), ]; // Build the dataseries -$series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_LINECHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping +$series2 = new DataSeries( + DataSeries::TYPE_LINECHART, // plotType + DataSeries::GROUPING_STANDARD, // plotGrouping range(0, count($dataSeriesValues2) - 1), // plotOrder $dataSeriesLabels2, // plotLabel null, // plotCategory @@ -104,13 +112,13 @@ $series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( // Data values // Data Marker $dataSeriesValues3 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$13', null, 12), ]; // Build the dataseries -$series3 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_AREACHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping +$series3 = new DataSeries( + DataSeries::TYPE_AREACHART, // plotType + DataSeries::GROUPING_STANDARD, // plotGrouping range(0, count($dataSeriesValues2) - 1), // plotOrder $dataSeriesLabels3, // plotLabel null, // plotCategory @@ -118,14 +126,14 @@ $series3 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series1, $series2, $series3]); +$plotArea = new PlotArea(null, [$series1, $series2, $series3]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend = new Legend(Legend::POSITION_RIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Average Weather Chart for Crete'); +$title = new Title('Average Weather Chart for Crete'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -145,7 +153,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_line.php b/samples/33_Chart_create_line.php index 556f9530..0f1184f6 100644 --- a/samples/33_Chart_create_line.php +++ b/samples/33_Chart_create_line.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,9 +31,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -35,7 +43,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -45,15 +53,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_LINECHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STACKED, // plotGrouping +$series = new DataSeries( + DataSeries::TYPE_LINECHART, // plotType + DataSeries::GROUPING_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory @@ -61,15 +69,15 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); +$legend = new Legend(Legend::POSITION_TOPRIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Stacked Line Chart'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test Stacked Line Chart'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -89,7 +97,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_multiple_charts.php b/samples/33_Chart_create_multiple_charts.php index d8ce1a20..bd2cf606 100644 --- a/samples/33_Chart_create_multiple_charts.php +++ b/samples/33_Chart_create_multiple_charts.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,9 +31,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -35,7 +43,7 @@ $dataSeriesLabels1 = [ // Data values // Data Marker $xAxisTickValues1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -45,15 +53,15 @@ $xAxisTickValues1 = [ // Data values // Data Marker $dataSeriesValues1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_AREACHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping +$series1 = new DataSeries( + DataSeries::TYPE_AREACHART, // plotType + DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel $xAxisTickValues1, // plotCategory @@ -61,15 +69,15 @@ $series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set the series in the plot area -$plotArea1 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series1]); +$plotArea1 = new PlotArea(null, [$series1]); // Set the chart legend -$legend1 = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); +$legend1 = new Legend(Legend::POSITION_TOPRIGHT, null, false); -$title1 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test %age-Stacked Area Chart'); -$yAxisLabel1 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title1 = new Title('Test %age-Stacked Area Chart'); +$yAxisLabel1 = new Title('Value ($k)'); // Create the chart -$chart1 = new \PhpOffice\PhpSpreadsheet\Chart( +$chart1 = new Chart( 'chart1', // name $title1, // title $legend1, // legend @@ -95,9 +103,9 @@ $worksheet->addChart($chart1); // Data values // Data Marker $dataSeriesLabels2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -107,7 +115,7 @@ $dataSeriesLabels2 = [ // Data values // Data Marker $xAxisTickValues2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -117,15 +125,15 @@ $xAxisTickValues2 = [ // Data values // Data Marker $dataSeriesValues2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping +$series2 = new DataSeries( + DataSeries::TYPE_BARCHART, // plotType + DataSeries::GROUPING_STANDARD, // plotGrouping range(0, count($dataSeriesValues2) - 1), // plotOrder $dataSeriesLabels2, // plotLabel $xAxisTickValues2, // plotCategory @@ -133,18 +141,18 @@ $series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set additional dataseries parameters // Make it a vertical column rather than a horizontal bar graph -$series2->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); +$series2->setPlotDirection(DataSeries::DIRECTION_COL); // Set the series in the plot area -$plotArea2 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series2]); +$plotArea2 = new PlotArea(null, [$series2]); // Set the chart legend -$legend2 = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend2 = new Legend(Legend::POSITION_RIGHT, null, false); -$title2 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Column Chart'); -$yAxisLabel2 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title2 = new Title('Test Column Chart'); +$yAxisLabel2 = new Title('Value ($k)'); // Create the chart -$chart2 = new \PhpOffice\PhpSpreadsheet\Chart( +$chart2 = new Chart( 'chart2', // name $title2, // title $legend2, // legend @@ -164,7 +172,7 @@ $worksheet->addChart($chart2); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_pie.php b/samples/33_Chart_create_pie.php index c8a23909..3b5ea810 100644 --- a/samples/33_Chart_create_pie.php +++ b/samples/33_Chart_create_pie.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,7 +31,7 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 ]; // Set the X-Axis Labels // Datatype @@ -33,7 +41,7 @@ $dataSeriesLabels1 = [ // Data values // Data Marker $xAxisTickValues1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -43,12 +51,12 @@ $xAxisTickValues1 = [ // Data values // Data Marker $dataSeriesValues1 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), ]; // Build the dataseries -$series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_PIECHART, // plotType +$series1 = new DataSeries( + DataSeries::TYPE_PIECHART, // plotType null, // plotGrouping (Pie charts don't have any grouping) range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel @@ -57,19 +65,19 @@ $series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set up a layout object for the Pie chart -$layout1 = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); +$layout1 = new Chart\Layout(); $layout1->setShowVal(true); $layout1->setShowPercent(true); // Set the series in the plot area -$plotArea1 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($layout1, [$series1]); +$plotArea1 = new PlotArea($layout1, [$series1]); // Set the chart legend -$legend1 = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend1 = new Legend(Legend::POSITION_RIGHT, null, false); -$title1 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Pie Chart'); +$title1 = new Title('Test Pie Chart'); // Create the chart -$chart1 = new \PhpOffice\PhpSpreadsheet\Chart( +$chart1 = new Chart( 'chart1', // name $title1, // title $legend1, // legend @@ -95,7 +103,7 @@ $worksheet->addChart($chart1); // Data values // Data Marker $dataSeriesLabels2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 ]; // Set the X-Axis Labels // Datatype @@ -105,7 +113,7 @@ $dataSeriesLabels2 = [ // Data values // Data Marker $xAxisTickValues2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -115,12 +123,12 @@ $xAxisTickValues2 = [ // Data values // Data Marker $dataSeriesValues2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), ]; // Build the dataseries -$series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_DONUTCHART, // plotType +$series2 = new DataSeries( + DataSeries::TYPE_DONUTCHART, // plotType null, // plotGrouping (Donut charts don't have any grouping) range(0, count($dataSeriesValues2) - 1), // plotOrder $dataSeriesLabels2, // plotLabel @@ -129,17 +137,17 @@ $series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set up a layout object for the Pie chart -$layout2 = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); +$layout2 = new Chart\Layout(); $layout2->setShowVal(true); $layout2->setShowCatName(true); // Set the series in the plot area -$plotArea2 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($layout2, [$series2]); +$plotArea2 = new PlotArea($layout2, [$series2]); -$title2 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Donut Chart'); +$title2 = new Title('Test Donut Chart'); // Create the chart -$chart2 = new \PhpOffice\PhpSpreadsheet\Chart( +$chart2 = new Chart( 'chart2', // name $title2, // title null, // legend @@ -159,7 +167,7 @@ $worksheet->addChart($chart2); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_radar.php b/samples/33_Chart_create_radar.php index 2a978792..49053c95 100644 --- a/samples/33_Chart_create_radar.php +++ b/samples/33_Chart_create_radar.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -31,8 +39,8 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -42,8 +50,8 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec ]; // Set the Data values for each data series we want to plot // Datatype @@ -53,13 +61,13 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$13', null, 12), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$13', null, 12), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_RADARCHART, // plotType +$series = new DataSeries( + DataSeries::TYPE_RADARCHART, // plotType null, // plotGrouping (Radar charts don't have any grouping) range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel @@ -67,21 +75,21 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $dataSeriesValues, // plotValues null, // plotDirection null, // smooth line - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::STYLE_MARKER // plotStyle + DataSeries::STYLE_MARKER // plotStyle ); // Set up a layout object for the Pie chart -$layout = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); +$layout = new Chart\Layout(); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($layout, [$series]); +$plotArea = new PlotArea($layout, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend = new Legend(Legend::POSITION_RIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Radar Chart'); +$title = new Title('Test Radar Chart'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -101,7 +109,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_scatter.php b/samples/33_Chart_create_scatter.php index 205113ab..f756c5a9 100644 --- a/samples/33_Chart_create_scatter.php +++ b/samples/33_Chart_create_scatter.php @@ -1,9 +1,17 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -23,13 +31,13 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -39,14 +47,14 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_SCATTERCHART, // plotType +$series = new DataSeries( + DataSeries::TYPE_SCATTERCHART, // plotType null, // plotGrouping (Scatter charts don't have any grouping) range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel @@ -54,19 +62,19 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $dataSeriesValues, // plotValues null, // plotDirection null, // smooth line - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::STYLE_LINEMARKER // plotStyle + DataSeries::STYLE_LINEMARKER // plotStyle ); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); +$legend = new Legend(Legend::POSITION_TOPRIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Scatter Chart'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test Scatter Chart'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend @@ -86,7 +94,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/33_Chart_create_stock.php b/samples/33_Chart_create_stock.php index eea2a430..30c876b5 100644 --- a/samples/33_Chart_create_stock.php +++ b/samples/33_Chart_create_stock.php @@ -1,9 +1,18 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -18,7 +27,7 @@ $worksheet->fromArray( 'A1', true ); -$worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_00); +$worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_00); // Set the Labels for each data series we want to plot // Datatype @@ -28,10 +37,10 @@ $worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSp // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), //Max / Open - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), //Min / Close - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), //Min Threshold / Min - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$E$1', null, 1), //Max Threshold / Max + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), //Max / Open + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), //Min / Close + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), //Min Threshold / Min + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$E$1', null, 1), //Max Threshold / Max ]; // Set the X-Axis Labels // Datatype @@ -41,7 +50,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$6', null, 5), // Counts + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$6', null, 5), // Counts ]; // Set the Data values for each data series we want to plot // Datatype @@ -51,15 +60,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$6', null, 5), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$6', null, 5), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$6', null, 5), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$E$2:$E$6', null, 5), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$6', null, 5), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$6', null, 5), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$6', null, 5), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$E$2:$E$6', null, 5), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_STOCKCHART, // plotType +$series = new DataSeries( + DataSeries::TYPE_STOCKCHART, // plotType null, // plotGrouping - if we set this to not null, then xlsx throws error range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel @@ -68,16 +77,16 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend = new Legend(Legend::POSITION_RIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Stock Chart'); -$xAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Counts'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Values'); +$title = new Title('Test Stock Chart'); +$xAxisLabel = new Title('Counts'); +$yAxisLabel = new Title('Values'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'stock-chart', // name $title, // title $legend, // legend @@ -97,7 +106,7 @@ $worksheet->addChart($chart); // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/34_Chart_update.php b/samples/34_Chart_update.php index 0a3c6e5a..bed5241d 100644 --- a/samples/34_Chart_update.php +++ b/samples/34_Chart_update.php @@ -1,16 +1,18 @@ getTemporaryFilename(); -$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); +$writer = new Xlsx($sampleSpreadsheet); $writer->save($filename); $helper->log('Load from Xlsx file'); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); +$reader = IOFactory::createReader('Xlsx'); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($filename); @@ -29,7 +31,7 @@ $worksheet->fromArray( // Save Excel 2007 file $filename = $helper->getFilename(__FILE__); -$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->setIncludeCharts(true); $callStartTime = microtime(true); $writer->save($filename); diff --git a/samples/35_Chart_render.php b/samples/35_Chart_render.php index b472f206..a63b28ef 100644 --- a/samples/35_Chart_render.php +++ b/samples/35_Chart_render.php @@ -1,14 +1,17 @@ log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure'); return; @@ -35,7 +38,7 @@ foreach ($inputFileNames as $inputFileName) { $helper->log("Load Test from $inputFileType file ", $inputFileNameShort); - $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); + $reader = IOFactory::createReader($inputFileType); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($inputFileName); diff --git a/samples/37_Page_layout_view.php b/samples/37_Page_layout_view.php index 42cc1beb..2cdb3e12 100644 --- a/samples/37_Page_layout_view.php +++ b/samples/37_Page_layout_view.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -23,7 +26,7 @@ $spreadsheet->setActiveSheetIndex(0) ->setCellValue('B2', 'world!'); // Set the page layout view as page layout -$spreadsheet->getActiveSheet()->getSheetView()->setView(\PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_LAYOUT); +$spreadsheet->getActiveSheet()->getSheetView()->setView(SheetView::SHEETVIEW_PAGE_LAYOUT); // Save $helper->write($spreadsheet, __FILE__); diff --git a/samples/38_Clone_worksheet.php b/samples/38_Clone_worksheet.php index aa555c39..b55b9025 100644 --- a/samples/38_Clone_worksheet.php +++ b/samples/38_Clone_worksheet.php @@ -1,10 +1,12 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); diff --git a/samples/39_Dropdown.php b/samples/39_Dropdown.php index d4c0306e..bb68c3e9 100644 --- a/samples/39_Dropdown.php +++ b/samples/39_Dropdown.php @@ -1,10 +1,14 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -39,7 +43,7 @@ foreach ($continents as $key => $filename) { $spreadsheet->getActiveSheet() ->fromArray($countries, null, $column . '1'); $spreadsheet->addNamedRange( - new \PhpOffice\PhpSpreadsheet\NamedRange( + new NamedRange( $continent, $spreadsheet->getActiveSheet(), $column . '1:' . $column . $countryCount @@ -61,7 +65,7 @@ $spreadsheet->getActiveSheet() ->setVisible(false); $spreadsheet->addNamedRange( - new \PhpOffice\PhpSpreadsheet\NamedRange( + new NamedRange( 'Continents', $spreadsheet->getActiveSheet(), $continentColumn . '1:' . $continentColumn . count($continents) @@ -85,8 +89,8 @@ $spreadsheet->getActiveSheet() $validation = $spreadsheet->getActiveSheet() ->getCell('B1') ->getDataValidation(); -$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST) - ->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION) +$validation->setType(DataValidation::TYPE_LIST) + ->setErrorStyle(DataValidation::STYLE_INFORMATION) ->setAllowBlank(false) ->setShowInputMessage(true) ->setShowErrorMessage(true) @@ -106,8 +110,8 @@ $spreadsheet->getActiveSheet() $validation = $spreadsheet->getActiveSheet() ->getCell('B3') ->getDataValidation(); -$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST) - ->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION) +$validation->setType(DataValidation::TYPE_LIST) + ->setErrorStyle(DataValidation::STYLE_INFORMATION) ->setAllowBlank(false) ->setShowInputMessage(true) ->setShowErrorMessage(true) diff --git a/samples/40_Duplicate_style.php b/samples/40_Duplicate_style.php index dca84817..4a006f90 100644 --- a/samples/40_Duplicate_style.php +++ b/samples/40_Duplicate_style.php @@ -1,15 +1,19 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $helper->log('Create styles array'); $styles = []; for ($i = 0; $i < 10; ++$i) { - $style = new \PhpOffice\PhpSpreadsheet\Style(); + $style = new Style(); $style->getFont()->setSize($i + 4); $styles[] = $style; } @@ -20,7 +24,7 @@ for ($col = 0; $col < 50; ++$col) { for ($row = 0; $row < 100; ++$row) { $str = ($row + $col); $style = $styles[$row % 10]; - $coord = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col) . ($row + 1); + $coord = Cell::stringFromColumnIndex($col) . ($row + 1); $worksheet->setCellValue($coord, $str); $worksheet->duplicateStyle($style, $coord); } diff --git a/samples/42_RichText.php b/samples/42_RichText.php index 53b1c573..88db805c 100644 --- a/samples/42_RichText.php +++ b/samples/42_RichText.php @@ -1,10 +1,13 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -48,7 +51,7 @@ $html4 = 'H2SO4 is the chemical formula for Sulphuric acid $html5 = 'bold, italic, bold+italic'; -$wizard = new \PhpOffice\PhpSpreadsheet\Helper\Html(); +$wizard = new HtmlHelper(); $richText = $wizard->toRichTextObject($html1); $spreadsheet->getActiveSheet() diff --git a/samples/43_Merge_workbooks.php b/samples/43_Merge_workbooks.php index 6173a2d5..57721a4a 100644 --- a/samples/43_Merge_workbooks.php +++ b/samples/43_Merge_workbooks.php @@ -1,17 +1,19 @@ log('Load MergeBook1 from Xlsx file'); $filename1 = __DIR__ . '/templates/43mergeBook1.xlsx'; $callStartTime = microtime(true); -$spreadsheet1 = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename1); +$spreadsheet1 = IOFactory::load($filename1); $helper->logRead('Xlsx', $filename1, $callStartTime); $helper->log('Load MergeBook2 from Xlsx file'); $filename2 = __DIR__ . '/templates/43mergeBook2.xlsx'; $callStartTime = microtime(true); -$spreadsheet2 = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename2); +$spreadsheet2 = IOFactory::load($filename2); $helper->logRead('Xlsx', $filename2, $callStartTime); foreach ($spreadsheet2->getSheetNames() as $sheetName) { diff --git a/samples/44_Worksheet_info.php b/samples/44_Worksheet_info.php index 71849ca4..cacb9ae6 100644 --- a/samples/44_Worksheet_info.php +++ b/samples/44_Worksheet_info.php @@ -1,15 +1,18 @@ getTemporaryFilename(); -$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); +$writer = new Xlsx($sampleSpreadsheet); $writer->save($filename); -$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($filename); -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$inputFileType = IOFactory::identify($filename); +$reader = IOFactory::createReader($inputFileType); $sheetList = $reader->listWorksheetNames($filename); $sheetInfo = $reader->listWorksheetInfo($filename); diff --git a/samples/45_Quadratic_equation_solver.php b/samples/45_Quadratic_equation_solver.php index f5e11e47..39f6685d 100644 --- a/samples/45_Quadratic_equation_solver.php +++ b/samples/45_Quadratic_equation_solver.php @@ -1,4 +1,6 @@ @@ -28,13 +30,13 @@ if (isset($_POST['submit'])) { echo '
Roots:
'; $discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')'; - $discriminant = \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->calculateFormula($discriminantFormula); + $discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula); $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 \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->calculateFormula($r1Formula) . '
'; - echo \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->calculateFormula($r2Formula) . '
'; + echo Calculation::getInstance()->calculateFormula($r1Formula) . '
'; + echo Calculation::getInstance()->calculateFormula($r2Formula) . '
'; $callEndTime = microtime(true); $helper->logEndingNotes(); } diff --git a/samples/46_ReadHtml.php b/samples/46_ReadHtml.php new file mode 100644 index 00000000..838d2868 --- /dev/null +++ b/samples/46_ReadHtml.php @@ -0,0 +1,19 @@ +load($html); + +$helper->logRead('Html', $html, $callStartTime); + +// Save +$helper->write($objPHPExcel, __FILE__); diff --git a/samples/Header.php b/samples/Header.php index b406ba1b..759ff1a8 100644 --- a/samples/Header.php +++ b/samples/Header.php @@ -2,11 +2,13 @@ /** * Header file. */ +use PhpOffice\PhpSpreadsheet\Helper\Sample; + error_reporting(E_ALL); require_once __DIR__ . '/../src/Bootstrap.php'; -$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); +$helper = new Sample(); if (!defined('EOL')) { define('EOL', $helper->isCli() ? PHP_EOL : '
'); } @@ -52,7 +54,7 @@ if ($helper->isCli()) { diff --git a/samples/index.php b/samples/index.php index 4b7dbe7a..6dc6fd6c 100644 --- a/samples/index.php +++ b/samples/index.php @@ -19,7 +19,7 @@ if (!$helper->isCli()) {

 

Fork us on Github! - Read the Docs + Read the Docs

+ + + + Competency List + + +
Readers
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Color NameHEXColor
Black#000000 
Blue#0000FF 
Green#008000 
Cyan#00FFFF 
Purple#800080 
Grey#808080 
SkyBlue#87CEEB 
Brown#A52A2A 
Silver#C0C0C0 
Chocolate#D2691E 
Tan#D2B48C 
Violet#EE82EE 
Red#FF0000 
Pink#FFC0CB 
Gold#FFD700 
Yellow#FFFF00 
LightYellow#FFFFE0 
White#FFFFFF 
+ + diff --git a/samples/templates/chartSpreadsheet.php b/samples/templates/chartSpreadsheet.php index f6fb8b00..7406e4be 100644 --- a/samples/templates/chartSpreadsheet.php +++ b/samples/templates/chartSpreadsheet.php @@ -1,6 +1,14 @@ getActiveSheet(); $worksheet->fromArray( [ @@ -20,9 +28,9 @@ $worksheet->fromArray( // Data values // Data Marker $dataSeriesLabels = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype @@ -32,7 +40,7 @@ $dataSeriesLabels = [ // Data values // Data Marker $xAxisTickValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype @@ -42,15 +50,15 @@ $xAxisTickValues = [ // Data values // Data Marker $dataSeriesValues = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries -$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType - \PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_CLUSTERED, // plotGrouping +$series = new DataSeries( + DataSeries::TYPE_BARCHART, // plotType + DataSeries::GROUPING_CLUSTERED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory @@ -58,18 +66,18 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( ); // Set additional dataseries parameters // Make it a horizontal bar rather than a vertical column graph -$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_BAR); +$series->setPlotDirection(DataSeries::DIRECTION_BAR); // Set the series in the plot area -$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); +$plotArea = new PlotArea(null, [$series]); // Set the chart legend -$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); +$legend = new Legend(Legend::POSITION_RIGHT, null, false); -$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Bar Chart'); -$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); +$title = new Title('Test Bar Chart'); +$yAxisLabel = new Title('Value ($k)'); // Create the chart -$chart = new \PhpOffice\PhpSpreadsheet\Chart( +$chart = new Chart( 'chart1', // name $title, // title $legend, // legend diff --git a/samples/templates/largeSpreadsheet.php b/samples/templates/largeSpreadsheet.php index 76ecb5d0..2205bf6f 100644 --- a/samples/templates/largeSpreadsheet.php +++ b/samples/templates/largeSpreadsheet.php @@ -1,8 +1,10 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set properties'); diff --git a/samples/templates/sampleSpreadsheet.php b/samples/templates/sampleSpreadsheet.php index 67bd9fd9..3a6c02d8 100644 --- a/samples/templates/sampleSpreadsheet.php +++ b/samples/templates/sampleSpreadsheet.php @@ -1,8 +1,21 @@ log('Create new Spreadsheet object'); -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); // Set document properties $helper->log('Set document properties'); @@ -18,8 +31,8 @@ $spreadsheet->getProperties()->setCreator('Maarten Balliauw') $helper->log('Add some data'); $spreadsheet->setActiveSheetIndex(0); $spreadsheet->getActiveSheet()->setCellValue('B1', 'Invoice'); -$spreadsheet->getActiveSheet()->setCellValue('D1', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(gmmktime(0, 0, 0, date('m'), date('d'), date('Y')))); -$spreadsheet->getActiveSheet()->getStyle('D1')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX15); +$spreadsheet->getActiveSheet()->setCellValue('D1', Date::PHPToExcel(gmmktime(0, 0, 0, date('m'), date('d'), date('Y')))); +$spreadsheet->getActiveSheet()->getStyle('D1')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_XLSX15); $spreadsheet->getActiveSheet()->setCellValue('E1', '#12566'); $spreadsheet->getActiveSheet()->setCellValue('A3', 'Product Id'); @@ -81,13 +94,13 @@ $spreadsheet->getActiveSheet()->getComment('E13')->getFillColor()->setRGB('EEEEE // Add rich-text string $helper->log('Add rich-text string'); -$richText = new \PhpOffice\PhpSpreadsheet\RichText(); +$richText = new RichText(); $richText->createText('This invoice is '); $payable = $richText->createTextRun('payable within thirty days after the end of the month'); $payable->getFont()->setBold(true); $payable->getFont()->setItalic(true); -$payable->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN)); +$payable->getFont()->setColor(new Color(Color::COLOR_DARKGREEN)); $richText->createText(', unless specified otherwise on the invoice.'); @@ -105,7 +118,7 @@ $spreadsheet->getActiveSheet()->protectCells('A3:E13', 'PhpSpreadsheet'); // Set cell number formats $helper->log('Set cell number formats'); -$spreadsheet->getActiveSheet()->getStyle('E4:E13')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); +$spreadsheet->getActiveSheet()->getStyle('E4:E13')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); // Set column widths $helper->log('Set column widths'); @@ -118,23 +131,23 @@ $helper->log('Set fonts'); $spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setName('Candara'); $spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setSize(20); $spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setBold(true); -$spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); -$spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE); +$spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->setUnderline(Font::UNDERLINE_SINGLE); +$spreadsheet->getActiveSheet()->getStyle('B1')->getFont()->getColor()->setARGB(Color::COLOR_WHITE); -$spreadsheet->getActiveSheet()->getStyle('D1')->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE); -$spreadsheet->getActiveSheet()->getStyle('E1')->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE); +$spreadsheet->getActiveSheet()->getStyle('D1')->getFont()->getColor()->setARGB(Color::COLOR_WHITE); +$spreadsheet->getActiveSheet()->getStyle('E1')->getFont()->getColor()->setARGB(Color::COLOR_WHITE); $spreadsheet->getActiveSheet()->getStyle('D13')->getFont()->setBold(true); $spreadsheet->getActiveSheet()->getStyle('E13')->getFont()->setBold(true); // Set alignments $helper->log('Set alignments'); -$spreadsheet->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT); -$spreadsheet->getActiveSheet()->getStyle('D12')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT); -$spreadsheet->getActiveSheet()->getStyle('D13')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT); +$spreadsheet->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT); +$spreadsheet->getActiveSheet()->getStyle('D12')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT); +$spreadsheet->getActiveSheet()->getStyle('D13')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT); -$spreadsheet->getActiveSheet()->getStyle('A18')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY); -$spreadsheet->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); +$spreadsheet->getActiveSheet()->getStyle('A18')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_JUSTIFY); +$spreadsheet->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); $spreadsheet->getActiveSheet()->getStyle('B5')->getAlignment()->setShrinkToFit(true); @@ -143,7 +156,7 @@ $helper->log('Set thin black border outline around column'); $styleThinBlackBorderOutline = [ 'borders' => [ 'outline' => [ - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'borderStyle' => Border::BORDER_THIN, 'color' => ['argb' => 'FF000000'], ], ], @@ -155,7 +168,7 @@ $helper->log('Set thick brown border outline around Total'); $styleThickBrownBorderOutline = [ 'borders' => [ 'outline' => [ - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK, + 'borderStyle' => Border::BORDER_THICK, 'color' => ['argb' => 'FF993300'], ], ], @@ -164,7 +177,7 @@ $spreadsheet->getActiveSheet()->getStyle('D13:E13')->applyFromArray($styleThickB // Set fills $helper->log('Set fills'); -$spreadsheet->getActiveSheet()->getStyle('A1:E1')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID); +$spreadsheet->getActiveSheet()->getStyle('A1:E1')->getFill()->setFillType(Fill::FILL_SOLID); $spreadsheet->getActiveSheet()->getStyle('A1:E1')->getFill()->getStartColor()->setARGB('FF808080'); // Set style for header row using alternative method @@ -175,20 +188,20 @@ $spreadsheet->getActiveSheet()->getStyle('A3:E3')->applyFromArray( 'bold' => true, ], 'alignment' => [ - 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT, + 'horizontal' => Alignment::HORIZONTAL_RIGHT, ], 'borders' => [ 'top' => [ - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'borderStyle' => Border::BORDER_THIN, ], ], 'fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR, + 'fillType' => Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, - 'startcolor' => [ + 'startColor' => [ 'argb' => 'FFA0A0A0', ], - 'endcolor' => [ + 'endColor' => [ 'argb' => 'FFFFFFFF', ], ], @@ -198,11 +211,11 @@ $spreadsheet->getActiveSheet()->getStyle('A3:E3')->applyFromArray( $spreadsheet->getActiveSheet()->getStyle('A3')->applyFromArray( [ 'alignment' => [ - 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT, + 'horizontal' => Alignment::HORIZONTAL_LEFT, ], 'borders' => [ 'left' => [ - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'borderStyle' => Border::BORDER_THIN, ], ], ] @@ -211,7 +224,7 @@ $spreadsheet->getActiveSheet()->getStyle('A3')->applyFromArray( $spreadsheet->getActiveSheet()->getStyle('B3')->applyFromArray( [ 'alignment' => [ - 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT, + 'horizontal' => Alignment::HORIZONTAL_LEFT, ], ] ); @@ -220,7 +233,7 @@ $spreadsheet->getActiveSheet()->getStyle('E3')->applyFromArray( [ 'borders' => [ 'right' => [ - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'borderStyle' => Border::BORDER_THIN, ], ], ] @@ -228,24 +241,24 @@ $spreadsheet->getActiveSheet()->getStyle('E3')->applyFromArray( // Unprotect a cell $helper->log('Unprotect a cell'); -$spreadsheet->getActiveSheet()->getStyle('B1')->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED); +$spreadsheet->getActiveSheet()->getStyle('B1')->getProtection()->setLocked(Protection::PROTECTION_UNPROTECTED); // Add a hyperlink to the sheet $helper->log('Add a hyperlink to an external website'); $spreadsheet->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net'); $spreadsheet->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl('http://www.phpexcel.net'); $spreadsheet->getActiveSheet()->getCell('E26')->getHyperlink()->setTooltip('Navigate to website'); -$spreadsheet->getActiveSheet()->getStyle('E26')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT); +$spreadsheet->getActiveSheet()->getStyle('E26')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT); $helper->log('Add a hyperlink to another cell on a different worksheet within the workbook'); $spreadsheet->getActiveSheet()->setCellValue('E27', 'Terms and conditions'); $spreadsheet->getActiveSheet()->getCell('E27')->getHyperlink()->setUrl("sheet://'Terms and conditions'!A1"); $spreadsheet->getActiveSheet()->getCell('E27')->getHyperlink()->setTooltip('Review terms and conditions'); -$spreadsheet->getActiveSheet()->getStyle('E27')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT); +$spreadsheet->getActiveSheet()->getStyle('E27')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT); // Add a drawing to the worksheet $helper->log('Add a drawing to the worksheet'); -$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); +$drawing = new Drawing(); $drawing->setName('Logo'); $drawing->setDescription('Logo'); $drawing->setPath(__DIR__ . '/../images/officelogo.jpg'); @@ -254,7 +267,7 @@ $drawing->setWorksheet($spreadsheet->getActiveSheet()); // Add a drawing to the worksheet $helper->log('Add a drawing to the worksheet'); -$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); +$drawing = new Drawing(); $drawing->setName('Paid'); $drawing->setDescription('Paid'); $drawing->setPath(__DIR__ . '/../images/paid.png'); @@ -267,7 +280,7 @@ $drawing->setWorksheet($spreadsheet->getActiveSheet()); // Add a drawing to the worksheet $helper->log('Add a drawing to the worksheet'); -$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); +$drawing = new Drawing(); $drawing->setName('PhpSpreadsheet logo'); $drawing->setDescription('PhpSpreadsheet logo'); $drawing->setPath(__DIR__ . '/../images/PhpSpreadsheet_logo.png'); @@ -290,8 +303,8 @@ $spreadsheet->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $spread // Set page orientation and size $helper->log('Set page orientation and size'); -$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT); -$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); +$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_PORTRAIT); +$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4); // Rename first worksheet $helper->log('Rename first worksheet'); @@ -330,13 +343,13 @@ $helper->log('Set fonts'); $spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->setName('Candara'); $spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->setSize(20); $spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); -$spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); +$spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->setUnderline(Font::UNDERLINE_SINGLE); $spreadsheet->getActiveSheet()->getStyle('A3:A6')->getFont()->setSize(8); // Add a drawing to the worksheet $helper->log('Add a drawing to the worksheet'); -$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); +$drawing = new Drawing(); $drawing->setName('Terms and conditions'); $drawing->setDescription('Terms and conditions'); $drawing->setPath(__DIR__ . '/../images/termsconditions.jpg'); @@ -345,8 +358,8 @@ $drawing->setWorksheet($spreadsheet->getActiveSheet()); // Set page orientation and size $helper->log('Set page orientation and size'); -$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); -$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); +$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); +$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4); // Rename second worksheet $helper->log('Rename second worksheet'); diff --git a/src/Bootstrap.php b/src/Bootstrap.php index b7062b5a..455999fc 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -26,6 +26,7 @@ */ // This sucks, but we have to try to find the composer autoloader + $paths = [ __DIR__ . '/../vendor/autoload.php', // In case PhpSpreadsheet is cloned directly __DIR__ . '/../../../autoload.php', // In case PhpSpreadsheet is a composer dependency. diff --git a/src/PhpSpreadsheet/Calculation.php b/src/PhpSpreadsheet/Calculation.php index d3554ceb..27ad8a13 100644 --- a/src/PhpSpreadsheet/Calculation.php +++ b/src/PhpSpreadsheet/Calculation.php @@ -13,21 +13,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Calculation\Statistical; use PhpOffice\PhpSpreadsheet\Calculation\TextData; - -if (!defined('CALCULATION_REGEXP_CELLREF')) { - // Test for support of \P (multibyte options) in PCRE - if (defined('PREG_BAD_UTF8_ERROR')) { - // Cell reference (cell or range of cells, with or without a sheet reference) - define('CALCULATION_REGEXP_CELLREF', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})'); - // Named Range of cells - define('CALCULATION_REGEXP_NAMEDRANGE', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)'); - } else { - // Cell reference (cell or range of cells, with or without a sheet reference) - define('CALCULATION_REGEXP_CELLREF', '(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)'); - // Named Range of cells - define('CALCULATION_REGEXP_NAMEDRANGE', '(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)'); - } -} +use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -64,9 +50,9 @@ class Calculation // Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it) const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\('; // Cell reference (cell or range of cells, with or without a sheet reference) - const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF; + const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})'; // Named Range of cells - const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE; + const CALCULATION_REGEXP_NAMEDRANGE = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)'; // Error const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?'; @@ -2067,7 +2053,7 @@ class Calculation } if (!isset(self::$instance) || (self::$instance === null)) { - self::$instance = new \PhpOffice\PhpSpreadsheet\Calculation(); + self::$instance = new self(); } return self::$instance; @@ -2075,8 +2061,6 @@ class Calculation /** * Unset an instance of this class. - * - * @param Spreadsheet $spreadsheet Injected spreadsheet identifying the instance to unset */ public function __destruct() { @@ -2085,7 +2069,7 @@ class Calculation /** * Flush the calculation cache for any existing instance of this class - * but only if a \PhpOffice\PhpSpreadsheet\Calculation instance exists. + * but only if a Calculation instance exists. */ public function flushInstance() { @@ -2330,6 +2314,14 @@ class Calculation return false; } + /** + * @param string $fromSeparator + * @param string $toSeparator + * @param string $formula + * @param bool $inBraces + * + * @return string + */ public static function translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces) { $strlen = mb_strlen($formula); @@ -2673,6 +2665,12 @@ class Calculation return $result; } + /** + * @param string $cellReference + * @param mixed $cellValue + * + * @return bool + */ public function getValueFromCache($cellReference, &$cellValue) { // Is calculation cacheing enabled? @@ -3001,6 +2999,11 @@ class Calculation } } + /** + * @param string $formula + * + * @return string + */ private function convertMatrixReferences($formula) { static $matrixReplaceFrom = ['{', ';', '}']; @@ -3089,6 +3092,13 @@ class Calculation ]; // Convert infix to postfix notation + + /** + * @param string $formula + * @param Cell|null $pCell + * + * @return bool + */ private function _parseFormula($formula, Cell $pCell = null) { if (($formula = $this->convertMatrixReferences(trim($formula))) === false) { @@ -3110,7 +3120,7 @@ class Calculation // Start with initialisation $index = 0; - $stack = new Calculation\Token\Stack(); + $stack = new Stack(); $output = []; $expectingOperator = false; // We use this test in syntax-checking the expression to determine when a // - is a negation or + is a positive operator rather than an operation @@ -3417,8 +3427,11 @@ class Calculation // evaluate postfix notation /** - * @param string $cellID * @param mixed $tokens + * @param string|null $cellID + * @param Cell|null $pCell + * + * @return bool */ private function processTokenStack($tokens, $cellID = null, Cell $pCell = null) { @@ -3430,7 +3443,7 @@ class Calculation // so we store the parent cell collection so that we can re-attach it when necessary $pCellWorksheet = ($pCell !== null) ? $pCell->getWorksheet() : null; $pCellParent = ($pCell !== null) ? $pCell->getParent() : null; - $stack = new Calculation\Token\Stack(); + $stack = new Stack(); // Loop through each token in turn foreach ($tokens as $tokenData) { @@ -3786,9 +3799,6 @@ class Calculation $output = $stack->pop(); $output = $output['value']; -// if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) { -// return array_shift(Calculation\Functions::flattenArray($output)); -// } return $output; } @@ -3830,7 +3840,17 @@ class Calculation return true; } - private function executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays = false) + /** + * @param string|null $cellID + * @param mixed $operand1 + * @param mixed $operand2 + * @param string $operation + * @param Stack $stack + * @param bool $recursingArrays + * + * @return bool + */ + private function executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, Stack &$stack, $recursingArrays = false) { // If we're dealing with matrix operations, we want a matrix result if ((is_array($operand1)) || (is_array($operand2))) { @@ -3970,7 +3990,7 @@ class Calculation /** * @param string $matrixFunction - * @param mixed $cellID + * @param string|null $cellID * @param mixed $operand1 * @param mixed $operand2 * @param mixed $operation diff --git a/src/PhpSpreadsheet/Calculation/Database.php b/src/PhpSpreadsheet/Calculation/Database.php index 72e2a88e..b490dc00 100644 --- a/src/PhpSpreadsheet/Calculation/Database.php +++ b/src/PhpSpreadsheet/Calculation/Database.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -116,12 +118,12 @@ class Database $k = array_search($criteriaName, $fieldNames); if (isset($dataValues[$k])) { $dataValue = $dataValues[$k]; - $dataValue = (is_string($dataValue)) ? \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($dataValue)) : $dataValue; + $dataValue = (is_string($dataValue)) ? Calculation::wrapResult(strtoupper($dataValue)) : $dataValue; $testConditionList = str_replace('[:' . $criteriaName . ']', $dataValue, $testConditionList); } } // evaluate the criteria against the row data - $result = \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue('=' . $testConditionList); + $result = Calculation::getInstance()->_calculateFormulaValue('=' . $testConditionList); // If the row failed to meet the criteria, remove it from the database if (!$result) { unset($database[$dataRow]); diff --git a/src/PhpSpreadsheet/Calculation/DateTime.php b/src/PhpSpreadsheet/Calculation/DateTime.php index 782b0828..1c9317b8 100644 --- a/src/PhpSpreadsheet/Calculation/DateTime.php +++ b/src/PhpSpreadsheet/Calculation/DateTime.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -90,7 +93,7 @@ class DateTime return Functions::VALUE(); } if ((is_object($dateValue)) && ($dateValue instanceof \DateTime)) { - $dateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateValue); + $dateValue = Date::PHPToExcel($dateValue); } else { $saveReturnDateType = Functions::getReturnDateType(); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); @@ -122,7 +125,7 @@ class DateTime private static function adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0) { // Execute function - $PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue); + $PHPDateObject = Date::excelToDateTimeObject($dateValue); $oMonth = (int) $PHPDateObject->format('m'); $oYear = (int) $PHPDateObject->format('Y'); @@ -172,7 +175,7 @@ class DateTime $retValue = false; switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: - $retValue = (float) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(time()); + $retValue = (float) Date::PHPToExcel(time()); break; case Functions::RETURNDATE_PHP_NUMERIC: $retValue = (int) time(); @@ -210,16 +213,16 @@ class DateTime $saveTimeZone = date_default_timezone_get(); date_default_timezone_set('UTC'); $retValue = false; - $excelDateTime = floor(\PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(time())); + $excelDateTime = floor(Date::PHPToExcel(time())); switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: $retValue = (float) $excelDateTime; break; case Functions::RETURNDATE_PHP_NUMERIC: - $retValue = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($excelDateTime); + $retValue = (int) Date::excelToTimestamp($excelDateTime); break; case Functions::RETURNDATE_PHP_OBJECT: - $retValue = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($excelDateTime); + $retValue = Date::excelToDateTimeObject($excelDateTime); break; } date_default_timezone_set($saveTimeZone); @@ -285,16 +288,16 @@ class DateTime $day = Functions::flattenSingleValue($day); if (($month !== null) && (!is_numeric($month))) { - $month = \PhpOffice\PhpSpreadsheet\Shared\Date::monthStringToNumber($month); + $month = Date::monthStringToNumber($month); } if (($day !== null) && (!is_numeric($day))) { - $day = \PhpOffice\PhpSpreadsheet\Shared\Date::dayStringToNumber($day); + $day = Date::dayStringToNumber($day); } - $year = ($year !== null) ? \PhpOffice\PhpSpreadsheet\Shared\StringHelper::testStringAsNumeric($year) : 0; - $month = ($month !== null) ? \PhpOffice\PhpSpreadsheet\Shared\StringHelper::testStringAsNumeric($month) : 0; - $day = ($day !== null) ? \PhpOffice\PhpSpreadsheet\Shared\StringHelper::testStringAsNumeric($day) : 0; + $year = ($year !== null) ? StringHelper::testStringAsNumeric($year) : 0; + $month = ($month !== null) ? StringHelper::testStringAsNumeric($month) : 0; + $day = ($day !== null) ? StringHelper::testStringAsNumeric($day) : 0; if ((!is_numeric($year)) || (!is_numeric($month)) || (!is_numeric($day))) { @@ -304,7 +307,7 @@ class DateTime $month = (int) $month; $day = (int) $day; - $baseYear = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar(); + $baseYear = Date::getExcelCalendar(); // Validate parameters if ($year < ($baseYear - 1900)) { return Functions::NAN(); @@ -334,14 +337,14 @@ class DateTime } // Execute function - $excelDateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($year, $month, $day); + $excelDateValue = Date::formattedPHPToExcel($year, $month, $day); switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: return (float) $excelDateValue; case Functions::RETURNDATE_PHP_NUMERIC: - return (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($excelDateValue); + return (int) Date::excelToTimestamp($excelDateValue); case Functions::RETURNDATE_PHP_OBJECT: - return \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($excelDateValue); + return Date::excelToDateTimeObject($excelDateValue); } } @@ -427,14 +430,14 @@ class DateTime switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: $date = 0; - $calendar = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar(); - if ($calendar != \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900) { + $calendar = Date::getExcelCalendar(); + if ($calendar != Date::CALENDAR_WINDOWS_1900) { $date = 1; } - return (float) \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second); + return (float) Date::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second); case Functions::RETURNDATE_PHP_NUMERIC: - return (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp(\PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600 + return (int) Date::excelToTimestamp(Date::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600 case Functions::RETURNDATE_PHP_OBJECT: $dayAdjust = 0; if ($hour < 0) { @@ -490,7 +493,7 @@ class DateTime // Strip any ordinals because they're allowed in Excel (English only) $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue); // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany) - $dateValue = str_replace(['/', '.', '-', ' '], [' ', ' ', ' ', ' '], $dateValue); + $dateValue = str_replace(['/', '.', '-', ' '], ' ', $dateValue); $yearFound = false; $t1 = explode(' ', $dateValue); @@ -517,7 +520,7 @@ class DateTime $t1[1] += 1900; array_unshift($t1, 1); } else { - array_push($t1, date('Y')); + $t1[] = date('Y'); } } } @@ -570,7 +573,7 @@ class DateTime return Functions::VALUE(); } $excelDateValue = floor( - \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( + Date::formattedPHPToExcel( $PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], @@ -583,7 +586,7 @@ class DateTime case Functions::RETURNDATE_EXCEL: return (float) $excelDateValue; case Functions::RETURNDATE_PHP_NUMERIC: - return (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($excelDateValue); + return (int) Date::excelToTimestamp($excelDateValue); case Functions::RETURNDATE_PHP_OBJECT: return new \DateTime($PHPDateArray['year'] . '-' . $PHPDateArray['month'] . '-' . $PHPDateArray['day'] . ' 00:00:00'); } @@ -618,7 +621,7 @@ class DateTime public static function TIMEVALUE($timeValue) { $timeValue = trim(Functions::flattenSingleValue($timeValue), '"'); - $timeValue = str_replace(['/', '.'], ['-', '-'], $timeValue); + $timeValue = str_replace(['/', '.'], '-', $timeValue); $arraySplit = preg_split('/[\/:\-\s]/', $timeValue); if ((count($arraySplit) == 2 || count($arraySplit) == 3) && $arraySplit[0] > 24) { @@ -629,7 +632,7 @@ class DateTime $PHPDateArray = date_parse($timeValue); if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) { if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) { - $excelDateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( + $excelDateValue = Date::formattedPHPToExcel( $PHPDateArray['year'], $PHPDateArray['month'], $PHPDateArray['day'], @@ -638,14 +641,14 @@ class DateTime $PHPDateArray['second'] ); } else { - $excelDateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1; + $excelDateValue = Date::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1; } switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: return (float) $excelDateValue; case Functions::RETURNDATE_PHP_NUMERIC: - return (int) $phpDateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($excelDateValue + 25569) - 3600; + return (int) $phpDateValue = Date::excelToTimestamp($excelDateValue + 25569) - 3600; case Functions::RETURNDATE_PHP_OBJECT: return new \DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']); } @@ -686,12 +689,12 @@ class DateTime // Execute function $difference = $endDate - $startDate; - $PHPStartDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($startDate); + $PHPStartDateObject = Date::excelToDateTimeObject($startDate); $startDays = $PHPStartDateObject->format('j'); $startMonths = $PHPStartDateObject->format('n'); $startYears = $PHPStartDateObject->format('Y'); - $PHPEndDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($endDate); + $PHPEndDateObject = Date::excelToDateTimeObject($endDate); $endDays = $PHPEndDateObject->format('j'); $endMonths = $PHPEndDateObject->format('n'); $endYears = $PHPEndDateObject->format('Y'); @@ -818,12 +821,12 @@ class DateTime } // Execute function - $PHPStartDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($startDate); + $PHPStartDateObject = Date::excelToDateTimeObject($startDate); $startDay = $PHPStartDateObject->format('j'); $startMonth = $PHPStartDateObject->format('n'); $startYear = $PHPStartDateObject->format('Y'); - $PHPEndDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($endDate); + $PHPEndDateObject = Date::excelToDateTimeObject($endDate); $endDay = $PHPEndDateObject->format('j'); $endMonth = $PHPEndDateObject->format('n'); $endYear = $PHPEndDateObject->format('Y'); @@ -1116,9 +1119,9 @@ class DateTime case Functions::RETURNDATE_EXCEL: return (float) $endDate; case Functions::RETURNDATE_PHP_NUMERIC: - return (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($endDate); + return (int) Date::excelToTimestamp($endDate); case Functions::RETURNDATE_PHP_OBJECT: - return \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($endDate); + return Date::excelToDateTimeObject($endDate); } } @@ -1151,7 +1154,7 @@ class DateTime } // Execute function - $PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue); + $PHPDateObject = Date::excelToDateTimeObject($dateValue); return (int) $PHPDateObject->format('j'); } @@ -1195,7 +1198,7 @@ class DateTime } // Execute function - $PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue); + $PHPDateObject = Date::excelToDateTimeObject($dateValue); $DoW = $PHPDateObject->format('w'); $firstDay = 1; @@ -1271,7 +1274,7 @@ class DateTime } // Execute function - $PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue); + $PHPDateObject = Date::excelToDateTimeObject($dateValue); $dayOfYear = $PHPDateObject->format('z'); $PHPDateObject->modify('-' . $dayOfYear . ' days'); $firstDayOfFirstWeek = $PHPDateObject->format('w'); @@ -1314,7 +1317,7 @@ class DateTime } // Execute function - $PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue); + $PHPDateObject = Date::excelToDateTimeObject($dateValue); return (int) $PHPDateObject->format('n'); } @@ -1346,7 +1349,7 @@ class DateTime } // Execute function - $PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue); + $PHPDateObject = Date::excelToDateTimeObject($dateValue); return (int) $PHPDateObject->format('Y'); } @@ -1387,7 +1390,7 @@ class DateTime } elseif ($timeValue < 0.0) { return Functions::NAN(); } - $timeValue = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($timeValue); + $timeValue = Date::excelToTimestamp($timeValue); return (int) gmdate('G', $timeValue); } @@ -1428,7 +1431,7 @@ class DateTime } elseif ($timeValue < 0.0) { return Functions::NAN(); } - $timeValue = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($timeValue); + $timeValue = Date::excelToTimestamp($timeValue); return (int) gmdate('i', $timeValue); } @@ -1469,7 +1472,7 @@ class DateTime } elseif ($timeValue < 0.0) { return Functions::NAN(); } - $timeValue = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($timeValue); + $timeValue = Date::excelToTimestamp($timeValue); return (int) gmdate('s', $timeValue); } @@ -1513,9 +1516,9 @@ class DateTime switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: - return (float) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDateObject); + return (float) Date::PHPToExcel($PHPDateObject); case Functions::RETURNDATE_PHP_NUMERIC: - return (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp(\PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDateObject)); + return (int) Date::excelToTimestamp(Date::PHPToExcel($PHPDateObject)); case Functions::RETURNDATE_PHP_OBJECT: return $PHPDateObject; } @@ -1562,9 +1565,9 @@ class DateTime switch (Functions::getReturnDateType()) { case Functions::RETURNDATE_EXCEL: - return (float) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDateObject); + return (float) Date::PHPToExcel($PHPDateObject); case Functions::RETURNDATE_PHP_NUMERIC: - return (int) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp(\PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDateObject)); + return (int) Date::excelToTimestamp(Date::PHPToExcel($PHPDateObject)); case Functions::RETURNDATE_PHP_OBJECT: return $PHPDateObject; } diff --git a/src/PhpSpreadsheet/Calculation/Engineering.php b/src/PhpSpreadsheet/Calculation/Engineering.php index 6fe07b39..8136fe68 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering.php +++ b/src/PhpSpreadsheet/Calculation/Engineering.php @@ -2,9 +2,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -/* EULER */ -define('EULER', 2.71828182845904523536); - /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,6 +26,11 @@ define('EULER', 2.71828182845904523536); */ class Engineering { + /** + * EULER. + */ + const EULER = 2.71828182845904523536; + /** * Details of the Units of measure that can be used in CONVERTUOM(). * @@ -944,7 +946,7 @@ class Engineering $f_PI_DIV_4 = M_PI / 4; $fXAbs = abs($x); - $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4); + $fResult = sqrt(Functions::M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4); if (($ord & 1) && ($x < 0)) { $fResult = -$fResult; } @@ -2103,7 +2105,7 @@ class Engineering return log10($parsedComplex['real']); } - return self::IMPRODUCT(log10(EULER), self::IMLN($complexNumber)); + return self::IMPRODUCT(log10(self::EULER), self::IMLN($complexNumber)); } /** @@ -2130,7 +2132,7 @@ class Engineering return log($parsedComplex['real'], 2); } - return self::IMPRODUCT(log(EULER, 2), self::IMLN($complexNumber)); + return self::IMPRODUCT(log(self::EULER, 2), self::IMLN($complexNumber)); } /** @@ -2291,7 +2293,7 @@ class Engineering * Excel Function: * IMSUM(complexNumber[,complexNumber[,...]]) * - * @param string $complexNumbers Series of complex numbers to add + * @param string ...$complexNumbers Series of complex numbers to add * * @return string */ @@ -2331,7 +2333,7 @@ class Engineering * Excel Function: * IMPRODUCT(complexNumber[,complexNumber[,...]]) * - * @param string $complexNumbers Series of complex numbers to multiply + * @param string ...$complexNumbers Series of complex numbers to multiply * * @return string */ @@ -2434,7 +2436,7 @@ class Engineering if ($sum == 0.0) { break; } - } while (abs($term / $sum) > PRECISION); + } while (abs($term / $sum) > Functions::PRECISION); return self::$twoSqrtPi * $sum; } @@ -2503,7 +2505,7 @@ class Engineering $n += 0.5; $q1 = $q2; $q2 = $b / $d; - } while ((abs($q1 - $q2) / $q2) > PRECISION); + } while ((abs($q1 - $q2) / $q2) > Functions::PRECISION); return self::$oneSqrtPi * exp(-$x * $x) * $q2; } diff --git a/src/PhpSpreadsheet/Calculation/Exception.php b/src/PhpSpreadsheet/Calculation/Exception.php index 6a9711fc..fa1b91c6 100644 --- a/src/PhpSpreadsheet/Calculation/Exception.php +++ b/src/PhpSpreadsheet/Calculation/Exception.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +26,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Exception extends \PhpOffice\PhpSpreadsheet\Exception +class Exception extends PhpSpreadsheetException { /** * Error handler callback. diff --git a/src/PhpSpreadsheet/Calculation/ExceptionHandler.php b/src/PhpSpreadsheet/Calculation/ExceptionHandler.php index a8b82405..fd2233c9 100644 --- a/src/PhpSpreadsheet/Calculation/ExceptionHandler.php +++ b/src/PhpSpreadsheet/Calculation/ExceptionHandler.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -31,7 +33,7 @@ class ExceptionHandler */ public function __construct() { - set_error_handler([\PhpOffice\PhpSpreadsheet\Calculation\Exception::class, 'errorHandlerCallback'], E_ALL); + set_error_handler([CalculationException::class, 'errorHandlerCallback'], E_ALL); } /** diff --git a/src/PhpSpreadsheet/Calculation/Financial.php b/src/PhpSpreadsheet/Calculation/Financial.php index 4c80a684..ea6dbce8 100644 --- a/src/PhpSpreadsheet/Calculation/Financial.php +++ b/src/PhpSpreadsheet/Calculation/Financial.php @@ -2,11 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -/* FINANCIAL_MAX_ITERATIONS */ -define('FINANCIAL_MAX_ITERATIONS', 128); - -/* FINANCIAL_PRECISION */ -define('FINANCIAL_PRECISION', 1.0e-08); +use PhpOffice\PhpSpreadsheet\Shared\Date; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -32,6 +28,10 @@ define('FINANCIAL_PRECISION', 1.0e-08); */ class Financial { + const FINANCIAL_MAX_ITERATIONS = 128; + + const FINANCIAL_PRECISION = 1.0e-08; + /** * isLastDayOfMonth. * @@ -64,10 +64,10 @@ class Financial { $months = 12 / $frequency; - $result = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($maturity); + $result = Date::excelToDateTimeObject($maturity); $eom = self::isLastDayOfMonth($result); - while ($settlement < \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($result)) { + while ($settlement < Date::PHPToExcel($result)) { $result->modify('-' . $months . ' months'); } if ($next) { @@ -78,7 +78,7 @@ class Financial $result->modify('-1 day'); } - return \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($result); + return Date::PHPToExcel($result); } private static function isValidFrequency($frequency) @@ -1426,7 +1426,7 @@ class Financial $x2 = $guess; $f1 = self::NPV($x1, $values); $f2 = self::NPV($x2, $values); - for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { + for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) { if (($f1 * $f2) < 0.0) { break; } @@ -1449,14 +1449,14 @@ class Financial $dx = $x1 - $x2; } - for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { + for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) { $dx *= 0.5; $x_mid = $rtb + $dx; $f_mid = self::NPV($x_mid, $values); if ($f_mid <= 0.0) { $rtb = $x_mid; } - if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) { + if ((abs($f_mid) < self::FINANCIAL_PRECISION) || (abs($dx) < self::FINANCIAL_PRECISION)) { return $x_mid; } } @@ -1963,7 +1963,7 @@ class Financial $guess = (is_null($guess)) ? 0.1 : Functions::flattenSingleValue($guess); $rate = $guess; - if (abs($rate) < FINANCIAL_PRECISION) { + if (abs($rate) < self::FINANCIAL_PRECISION) { $y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv; } else { $f = exp($nper * log(1 + $rate)); @@ -1975,14 +1975,14 @@ class Financial // find root by secant method $i = $x0 = 0.0; $x1 = $rate; - while ((abs($y0 - $y1) > FINANCIAL_PRECISION) && ($i < FINANCIAL_MAX_ITERATIONS)) { + while ((abs($y0 - $y1) > self::FINANCIAL_PRECISION) && ($i < self::FINANCIAL_MAX_ITERATIONS)) { $rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0); $x0 = $x1; $x1 = $rate; if (($nper * abs($pmt)) > ($pv - $fv)) { $x1 = abs($x1); } - if (abs($rate) < FINANCIAL_PRECISION) { + if (abs($rate) < self::FINANCIAL_PRECISION) { $y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv; } else { $f = exp($nper * log(1 + $rate)); @@ -2280,7 +2280,7 @@ class Financial $x2 = $guess; $f1 = self::XNPV($x1, $values, $dates); $f2 = self::XNPV($x2, $values, $dates); - for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { + for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) { if (($f1 * $f2) < 0.0) { break; } elseif (abs($f1) < abs($f2)) { @@ -2302,14 +2302,14 @@ class Financial $dx = $x1 - $x2; } - for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { + for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) { $dx *= 0.5; $x_mid = $rtb + $dx; $f_mid = self::XNPV($x_mid, $values, $dates); if ($f_mid <= 0.0) { $rtb = $x_mid; } - if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) { + if ((abs($f_mid) < self::FINANCIAL_PRECISION) || (abs($dx) < self::FINANCIAL_PRECISION)) { return $x_mid; } } diff --git a/src/PhpSpreadsheet/Calculation/FormulaParser.php b/src/PhpSpreadsheet/Calculation/FormulaParser.php index f37c4716..dbb94f29 100644 --- a/src/PhpSpreadsheet/Calculation/FormulaParser.php +++ b/src/PhpSpreadsheet/Calculation/FormulaParser.php @@ -253,7 +253,7 @@ class FormulaParser // establish state-dependent character evaluations if ($this->formula[$index] == self::QUOTE_DOUBLE) { - if (strlen($value > 0)) { + if (strlen($value) > 0) { // unexpected $tokens1[] = new FormulaToken($value, FormulaToken::TOKEN_TYPE_UNKNOWN); $value = ''; @@ -593,7 +593,7 @@ class FormulaParser if ($token->getTokenType() == FormulaToken::TOKEN_TYPE_OPERAND && $token->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_NOTHING) { if (!is_numeric($token->getValue())) { - if (strtoupper($token->getValue()) == 'TRUE' || strtoupper($token->getValue() == 'FALSE')) { + if (strtoupper($token->getValue()) == 'TRUE' || strtoupper($token->getValue()) == 'FALSE') { $token->setTokenSubType(FormulaToken::TOKEN_SUBTYPE_LOGICAL); } else { $token->setTokenSubType(FormulaToken::TOKEN_SUBTYPE_RANGE); @@ -607,7 +607,7 @@ class FormulaParser } if ($token->getTokenType() == FormulaToken::TOKEN_TYPE_FUNCTION) { - if (strlen($token->getValue() > 0)) { + if (strlen($token->getValue()) > 0) { if (substr($token->getValue(), 0, 1) == '@') { $token->setValue(substr($token->getValue(), 1)); } diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index 88346ed0..49ff4182 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -2,17 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -/* MAX_VALUE */ -define('MAX_VALUE', 1.2e308); - -/* 2 / PI */ -define('M_2DIVPI', 0.63661977236758134307553505349006); - -/* MAX_ITERATIONS */ -define('MAX_ITERATIONS', 256); - -/* PRECISION */ -define('PRECISION', 8.88E-016); +use PhpOffice\PhpSpreadsheet\Calculation; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -38,11 +28,17 @@ define('PRECISION', 8.88E-016); */ class Functions { + const PRECISION = 8.88E-016; + + /** + * 2 / PI. + */ + const M_2DIVPI = 0.63661977236758134307553505349006; + /** constants */ const COMPATIBILITY_EXCEL = 'Excel'; const COMPATIBILITY_GNUMERIC = 'Gnumeric'; const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc'; - const RETURNDATE_PHP_NUMERIC = 'P'; const RETURNDATE_PHP_OBJECT = 'O'; const RETURNDATE_EXCEL = 'E'; @@ -298,7 +294,7 @@ class Functions } if (!in_array($condition[0], ['>', '<', '='])) { if (!is_numeric($condition)) { - $condition = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($condition)); + $condition = Calculation::wrapResult(strtoupper($condition)); } return '=' . $condition; @@ -308,7 +304,7 @@ class Functions if (!is_numeric($operand)) { $operand = str_replace('"', '""', $operand); - $operand = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($operand)); + $operand = Calculation::wrapResult(strtoupper($operand)); } return $operator . $operand; diff --git a/src/PhpSpreadsheet/Calculation/Logical.php b/src/PhpSpreadsheet/Calculation/Logical.php index 25bacafc..4db10945 100644 --- a/src/PhpSpreadsheet/Calculation/Logical.php +++ b/src/PhpSpreadsheet/Calculation/Logical.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -78,7 +80,7 @@ class Logical * * @category Logical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return string|bool the logical AND of the arguments */ @@ -98,9 +100,9 @@ class Logical $returnValue = $returnValue && ($arg != 0); } elseif (is_string($arg)) { $arg = strtoupper($arg); - if (($arg == 'TRUE') || ($arg == \PhpOffice\PhpSpreadsheet\Calculation::getTRUE())) { + if (($arg == 'TRUE') || ($arg == Calculation::getTRUE())) { $arg = true; - } elseif (($arg == 'FALSE') || ($arg == \PhpOffice\PhpSpreadsheet\Calculation::getFALSE())) { + } elseif (($arg == 'FALSE') || ($arg == Calculation::getFALSE())) { $arg = false; } else { return Functions::VALUE(); @@ -155,9 +157,9 @@ class Logical $returnValue = $returnValue || ($arg != 0); } elseif (is_string($arg)) { $arg = strtoupper($arg); - if (($arg == 'TRUE') || ($arg == \PhpOffice\PhpSpreadsheet\Calculation::getTRUE())) { + if (($arg == 'TRUE') || ($arg == Calculation::getTRUE())) { $arg = true; - } elseif (($arg == 'FALSE') || ($arg == \PhpOffice\PhpSpreadsheet\Calculation::getFALSE())) { + } elseif (($arg == 'FALSE') || ($arg == Calculation::getFALSE())) { $arg = false; } else { return Functions::VALUE(); @@ -200,9 +202,9 @@ class Logical $logical = Functions::flattenSingleValue($logical); if (is_string($logical)) { $logical = strtoupper($logical); - if (($logical == 'TRUE') || ($logical == \PhpOffice\PhpSpreadsheet\Calculation::getTRUE())) { + if (($logical == 'TRUE') || ($logical == Calculation::getTRUE())) { return false; - } elseif (($logical == 'FALSE') || ($logical == \PhpOffice\PhpSpreadsheet\Calculation::getFALSE())) { + } elseif (($logical == 'FALSE') || ($logical == Calculation::getFALSE())) { return true; } diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php index 8359b0ba..9672a6da 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Cell; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -72,7 +75,7 @@ class LookupRef } if ((!is_bool($referenceStyle)) || $referenceStyle) { $rowRelative = $columnRelative = '$'; - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column - 1); + $column = Cell::stringFromColumnIndex($column - 1); if (($relativity == 2) || ($relativity == 4)) { $columnRelative = ''; } @@ -118,7 +121,7 @@ class LookupRef foreach ($cellAddress as $columnKey => $value) { $columnKey = preg_replace('/[^a-z]/i', '', $columnKey); - return (int) \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($columnKey); + return (int) Cell::columnIndexFromString($columnKey); } } else { if (strpos($cellAddress, '!') !== false) { @@ -130,14 +133,14 @@ class LookupRef $endAddress = preg_replace('/[^a-z]/i', '', $endAddress); $returnValue = []; do { - $returnValue[] = (int) \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($startAddress); + $returnValue[] = (int) Cell::columnIndexFromString($startAddress); } while ($startAddress++ != $endAddress); return $returnValue; } $cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress); - return (int) \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($cellAddress); + return (int) Cell::columnIndexFromString($cellAddress); } } @@ -164,7 +167,7 @@ class LookupRef reset($cellAddress); $isMatrix = (is_numeric(key($cellAddress))); - list($columns, $rows) = \PhpOffice\PhpSpreadsheet\Calculation::_getMatrixDimensions($cellAddress); + list($columns, $rows) = Calculation::_getMatrixDimensions($cellAddress); if ($isMatrix) { return $rows; @@ -198,7 +201,7 @@ class LookupRef if (is_array($cellAddress)) { foreach ($cellAddress as $columnKey => $rowValue) { foreach ($rowValue as $rowKey => $cellValue) { - return (int) preg_replace('/[^0-9]/i', '', $rowKey); + return (int) preg_replace('/[^0-9]/', '', $rowKey); } } } else { @@ -245,7 +248,7 @@ class LookupRef reset($cellAddress); $isMatrix = (is_numeric(key($cellAddress))); - list($columns, $rows) = \PhpOffice\PhpSpreadsheet\Calculation::_getMatrixDimensions($cellAddress); + list($columns, $rows) = Calculation::_getMatrixDimensions($cellAddress); if ($isMatrix) { return $columns; @@ -264,11 +267,11 @@ class LookupRef * * @param string $linkURL Value to check, is also the value returned when no error * @param string $displayName Value to return when testValue is an error condition - * @param \PhpOffice\PhpSpreadsheet\Cell $pCell The cell to set the hyperlink in + * @param Cell $pCell The cell to set the hyperlink in * * @return mixed The value of $displayName (or $linkURL if $displayName was blank) */ - public static function HYPERLINK($linkURL = '', $displayName = null, \PhpOffice\PhpSpreadsheet\Cell $pCell = null) + public static function HYPERLINK($linkURL = '', $displayName = null, Cell $pCell = null) { $linkURL = (is_null($linkURL)) ? '' : Functions::flattenSingleValue($linkURL); $displayName = (is_null($displayName)) ? '' : Functions::flattenSingleValue($displayName); @@ -299,13 +302,13 @@ class LookupRef * NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010 * * @param cellAddress $cellAddress The cell address of the current cell (containing this formula) - * @param \PhpOffice\PhpSpreadsheet\Cell $pCell The current cell (containing this formula) + * @param Cell $pCell The current cell (containing this formula) * * @return mixed The cells referenced by cellAddress * * @todo Support for the optional a1 parameter introduced in Excel 2010 */ - public static function INDIRECT($cellAddress = null, \PhpOffice\PhpSpreadsheet\Cell $pCell = null) + public static function INDIRECT($cellAddress = null, Cell $pCell = null) { $cellAddress = Functions::flattenSingleValue($cellAddress); if (is_null($cellAddress) || $cellAddress === '') { @@ -318,9 +321,9 @@ class LookupRef list($cellAddress1, $cellAddress2) = explode(':', $cellAddress); } - if ((!preg_match('/^' . \PhpOffice\PhpSpreadsheet\Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) || - ((!is_null($cellAddress2)) && (!preg_match('/^' . \PhpOffice\PhpSpreadsheet\Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress2, $matches)))) { - if (!preg_match('/^' . \PhpOffice\PhpSpreadsheet\Calculation::CALCULATION_REGEXP_NAMEDRANGE . '$/i', $cellAddress1, $matches)) { + if ((!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) || + ((!is_null($cellAddress2)) && (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress2, $matches)))) { + if (!preg_match('/^' . Calculation::CALCULATION_REGEXP_NAMEDRANGE . '$/i', $cellAddress1, $matches)) { return Functions::REF(); } @@ -332,7 +335,7 @@ class LookupRef $pSheet = $pCell->getWorksheet(); } - return \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, false); + return Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, false); } if (strpos($cellAddress, '!') !== false) { @@ -343,7 +346,7 @@ class LookupRef $pSheet = $pCell->getWorksheet(); } - return \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false); + return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false); } /** @@ -374,11 +377,11 @@ class LookupRef * @param mixed $columns * @param null|mixed $height * @param null|mixed $width - * @param \PhpOffice\PhpSpreadsheet\Cell $pCell + * @param Cell $pCell * * @return string A reference to a cell or range of cells */ - public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, \PhpOffice\PhpSpreadsheet\Cell $pCell = null) + public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, Cell $pCell = null) { $rows = Functions::flattenSingleValue($rows); $columns = Functions::flattenSingleValue($columns); @@ -402,23 +405,23 @@ class LookupRef } else { $startCell = $endCell = $cellAddress; } - list($startCellColumn, $startCellRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($startCell); - list($endCellColumn, $endCellRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($endCell); + list($startCellColumn, $startCellRow) = Cell::coordinateFromString($startCell); + list($endCellColumn, $endCellRow) = Cell::coordinateFromString($endCell); $startCellRow += $rows; - $startCellColumn = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($startCellColumn) - 1; + $startCellColumn = Cell::columnIndexFromString($startCellColumn) - 1; $startCellColumn += $columns; if (($startCellRow <= 0) || ($startCellColumn < 0)) { return Functions::REF(); } - $endCellColumn = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($endCellColumn) - 1; + $endCellColumn = Cell::columnIndexFromString($endCellColumn) - 1; if (($width != null) && (!is_object($width))) { $endCellColumn = $startCellColumn + $width - 1; } else { $endCellColumn += $columns; } - $startCellColumn = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($startCellColumn); + $startCellColumn = Cell::stringFromColumnIndex($startCellColumn); if (($height != null) && (!is_object($height))) { $endCellRow = $startCellRow + $height - 1; @@ -429,7 +432,7 @@ class LookupRef if (($endCellRow <= 0) || ($endCellColumn < 0)) { return Functions::REF(); } - $endCellColumn = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($endCellColumn); + $endCellColumn = Cell::stringFromColumnIndex($endCellColumn); $cellAddress = $startCellColumn . $startCellRow; if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) { @@ -442,7 +445,7 @@ class LookupRef $pSheet = $pCell->getWorksheet(); } - return \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false); + return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false); } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 2d7b6da8..89d5b6bc 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -343,7 +347,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return int Greatest Common Divisor */ @@ -452,7 +456,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return int Lowest Common Multiplier */ @@ -567,10 +571,10 @@ class MathTrig } try { - $matrix = new \PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix($matrixData); + $matrix = new Matrix($matrixData); return $matrix->det(); - } catch (\PhpOffice\PhpSpreadsheet\Exception $ex) { + } catch (PhpSpreadsheetException $ex) { return Functions::VALUE(); } } @@ -621,10 +625,10 @@ class MathTrig } try { - $matrix = new \PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix($matrixData); + $matrix = new Matrix($matrixData); return $matrix->inverse()->getArray(); - } catch (\PhpOffice\PhpSpreadsheet\Exception $ex) { + } catch (PhpSpreadsheetException $ex) { return Functions::VALUE(); } } @@ -663,7 +667,7 @@ class MathTrig } ++$rowA; } - $matrixA = new \PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix($matrixAData); + $matrixA = new Matrix($matrixAData); $rowB = 0; foreach ($matrixData2 as $matrixRow) { if (!is_array($matrixRow)) { @@ -679,14 +683,14 @@ class MathTrig } ++$rowB; } - $matrixB = new \PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix($matrixBData); + $matrixB = new Matrix($matrixBData); if ($columnA != $rowB) { return Functions::VALUE(); } return $matrixA->times($matrixB)->getArray(); - } catch (\PhpOffice\PhpSpreadsheet\Exception $ex) { + } catch (PhpSpreadsheetException $ex) { return Functions::VALUE(); } } @@ -855,7 +859,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -895,7 +899,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -1214,7 +1218,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -1264,11 +1268,11 @@ class MathTrig foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { $arg = str_replace('"', '""', $arg); - $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); + $arg = Calculation::wrapResult(strtoupper($arg)); } $testCondition = '=' . $arg . $condition; - if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { // Is it a value within our criteria $returnValue += $sumArgs[$key]; } @@ -1313,10 +1317,10 @@ class MathTrig // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { - $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); + $arg = Calculation::wrapResult(strtoupper($arg)); } $testCondition = '=' . $arg . $condition; - if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { // Is it a value within our criteria $returnValue += $sumArgs[$key]; } @@ -1335,7 +1339,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -1380,7 +1384,7 @@ class MathTrig * * @category Mathematical and Trigonometric Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 2f743e70..954dfe3c 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -2,17 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -/* LOG_GAMMA_X_MAX_VALUE */ -define('LOG_GAMMA_X_MAX_VALUE', 2.55e305); - -/* XMININ */ -define('XMININ', 2.23e-308); - -/* EPS */ -define('EPS', 2.22e-16); - -/* SQRT2PI */ -define('SQRT2PI', 2.5066282746310005024157652848110452530069867406099); +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -38,6 +29,13 @@ define('SQRT2PI', 2.5066282746310005024157652848110452530069867406099); */ class Statistical { + const LOG_GAMMA_X_MAX_VALUE = 2.55e305; + const XMININ = 2.23e-308; + const EPS = 2.22e-16; + const MAX_VALUE = 1.2e308; + const MAX_ITERATIONS = 256; + const SQRT2PI = 2.5066282746310005024157652848110452530069867406099; + private static function checkTrendArrays(&$array1, &$array2) { if (!is_array($array1)) { @@ -79,7 +77,7 @@ class Statistical */ private static function beta($p, $q) { - if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > LOG_GAMMA_X_MAX_VALUE) { + if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > self::LOG_GAMMA_X_MAX_VALUE) { return 0.0; } @@ -109,7 +107,7 @@ class Statistical return 0.0; } elseif ($x >= 1.0) { return 1.0; - } elseif (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) { + } elseif (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > self::LOG_GAMMA_X_MAX_VALUE)) { return 0.0; } $beta_gam = exp((0 - self::logBeta($p, $q)) + $p * log($x) + $q * log(1.0 - $x)); @@ -142,7 +140,7 @@ class Statistical if ($p != self::$logBetaCacheP || $q != self::$logBetaCacheQ) { self::$logBetaCacheP = $p; self::$logBetaCacheQ = $q; - if (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) { + if (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > self::LOG_GAMMA_X_MAX_VALUE)) { self::$logBetaCacheResult = 0.0; } else { self::$logBetaCacheResult = self::logGamma($p) + self::logGamma($q) - self::logGamma($p + $q); @@ -169,37 +167,37 @@ class Statistical $p_plus = $p + 1.0; $p_minus = $p - 1.0; $h = 1.0 - $sum_pq * $x / $p_plus; - if (abs($h) < XMININ) { - $h = XMININ; + if (abs($h) < self::XMININ) { + $h = self::XMININ; } $h = 1.0 / $h; $frac = $h; $m = 1; $delta = 0.0; - while ($m <= MAX_ITERATIONS && abs($delta - 1.0) > PRECISION) { + while ($m <= self::MAX_ITERATIONS && abs($delta - 1.0) > Functions::PRECISION) { $m2 = 2 * $m; // even index for d $d = $m * ($q - $m) * $x / (($p_minus + $m2) * ($p + $m2)); $h = 1.0 + $d * $h; - if (abs($h) < XMININ) { - $h = XMININ; + if (abs($h) < self::XMININ) { + $h = self::XMININ; } $h = 1.0 / $h; $c = 1.0 + $d / $c; - if (abs($c) < XMININ) { - $c = XMININ; + if (abs($c) < self::XMININ) { + $c = self::XMININ; } $frac *= $h * $c; // odd index for d $d = -($p + $m) * ($sum_pq + $m) * $x / (($p + $m2) * ($p_plus + $m2)); $h = 1.0 + $d * $h; - if (abs($h) < XMININ) { - $h = XMININ; + if (abs($h) < self::XMININ) { + $h = self::XMININ; } $h = 1.0 / $h; $c = 1.0 + $d / $c; - if (abs($c) < XMININ) { - $c = XMININ; + if (abs($c) < self::XMININ) { + $c = self::XMININ; } $delta = $h * $c; $frac *= $delta; @@ -343,8 +341,8 @@ class Statistical return self::$logGammaCacheResult; } $y = $x; - if ($y > 0.0 && $y <= LOG_GAMMA_X_MAX_VALUE) { - if ($y <= EPS) { + if ($y > 0.0 && $y <= self::LOG_GAMMA_X_MAX_VALUE) { + if ($y <= self::EPS) { $res = -log(y); } elseif ($y <= 1.5) { // --------------------- @@ -412,7 +410,7 @@ class Statistical } $res /= $y; $corr = log($y); - $res = $res + log(SQRT2PI) - 0.5 * $corr; + $res = $res + log(self::SQRT2PI) - 0.5 * $corr; $res += $y * ($corr - 1.0); } } @@ -420,7 +418,7 @@ class Statistical // -------------------------- // Return for bad arguments // -------------------------- - $res = MAX_VALUE; + $res = self::MAX_VALUE; } // ------------------------------ // Final adjustments and return @@ -477,7 +475,7 @@ class Statistical $summer += ($p[$j] / ++$y); } - return exp(0 - $tmp + log(SQRT2PI * $summer / $x)); + return exp(0 - $tmp + log(self::SQRT2PI * $summer / $x)); } /*************************************************************************** @@ -722,7 +720,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -773,7 +771,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -816,7 +814,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -883,10 +881,10 @@ class Statistical $aCount = 0; foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { - $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); + $arg = Calculation::wrapResult(strtoupper($arg)); } $testCondition = '=' . $arg . $condition; - if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { if ((is_null($returnValue)) || ($arg > $returnValue)) { $returnValue += $arg; ++$aCount; @@ -974,7 +972,7 @@ class Statistical $b = 2; $i = 0; - while ((($b - $a) > PRECISION) && ($i++ < MAX_ITERATIONS)) { + while ((($b - $a) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) { $guess = ($a + $b) / 2; $result = self::BETADIST($guess, $alpha, $beta); if (($result == $probability) || ($result == 0)) { @@ -985,7 +983,7 @@ class Statistical $a = $guess; } } - if ($i == MAX_ITERATIONS) { + if ($i == self::MAX_ITERATIONS) { return Functions::NA(); } @@ -1099,7 +1097,7 @@ class Statistical $dx = 1; $i = 0; - while ((abs($dx) > PRECISION) && ($i++ < MAX_ITERATIONS)) { + while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) { // Apply Newton-Raphson step $result = self::CHIDIST($x, $degrees); $error = $result - $probability; @@ -1124,7 +1122,7 @@ class Statistical } $x = $xNew; } - if ($i == MAX_ITERATIONS) { + if ($i == self::MAX_ITERATIONS) { return Functions::NA(); } @@ -1194,7 +1192,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getCorrelation(); } @@ -1209,7 +1207,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return int */ @@ -1243,7 +1241,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return int */ @@ -1273,7 +1271,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return int */ @@ -1317,10 +1315,10 @@ class Statistical // Loop through arguments foreach ($aArgs as $arg) { if (!is_numeric($arg)) { - $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); + $arg = Calculation::wrapResult(strtoupper($arg)); } $testCondition = '=' . $arg . $condition; - if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { // Is it a value within our criteria ++$returnValue; } @@ -1355,7 +1353,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getCovariance(); } @@ -1493,7 +1491,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -1649,7 +1647,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getValueOfYForX($xValue); } @@ -1718,7 +1716,7 @@ class Statistical $dx = 1024; $i = 0; - while ((abs($dx) > PRECISION) && ($i++ < MAX_ITERATIONS)) { + while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) { // Apply Newton-Raphson step $error = self::GAMMADIST($x, $alpha, $beta, true) - $probability; if ($error < 0.0) { @@ -1741,7 +1739,7 @@ class Statistical } $x = $xNew; } - if ($i == MAX_ITERATIONS) { + if ($i == self::MAX_ITERATIONS) { return Functions::NA(); } @@ -1787,7 +1785,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -1829,7 +1827,7 @@ class Statistical $newValues = Functions::flattenArray($newValues); $const = (is_null($const)) ? true : (bool) Functions::flattenSingleValue($const); - $bestFitExponential = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_EXPONENTIAL, $yValues, $xValues, $const); + $bestFitExponential = Trend::calculate(Trend::TREND_EXPONENTIAL, $yValues, $xValues, $const); if (empty($newValues)) { $newValues = $bestFitExponential->getXValues(); } @@ -1853,7 +1851,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -1956,7 +1954,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getIntersect(); } @@ -1969,7 +1967,7 @@ class Statistical * kurtosis indicates a relatively peaked distribution. Negative kurtosis indicates a * relatively flat distribution. * - * @param array Data Series + * @param array ...$args Data Series * * @return float */ @@ -2084,7 +2082,7 @@ class Statistical return 0; } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues, $const); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues, $const); if ($stats) { return [ [ @@ -2153,7 +2151,7 @@ class Statistical return 1; } - $bestFitExponential = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_EXPONENTIAL, $yValues, $xValues, $const); + $bestFitExponential = Trend::calculate(Trend::TREND_EXPONENTIAL, $yValues, $xValues, $const); if ($stats) { return [ [ @@ -2251,7 +2249,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -2287,7 +2285,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -2347,10 +2345,10 @@ class Statistical // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { - $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); + $arg = Calculation::wrapResult(strtoupper($arg)); } $testCondition = '=' . $arg . $condition; - if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { if ((is_null($returnValue)) || ($arg > $returnValue)) { $returnValue = $arg; } @@ -2370,7 +2368,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -2414,7 +2412,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -2450,7 +2448,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -2510,10 +2508,10 @@ class Statistical // Loop through arguments foreach ($aArgs as $key => $arg) { if (!is_numeric($arg)) { - $arg = \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($arg)); + $arg = Calculation::wrapResult(strtoupper($arg)); } $testCondition = '=' . $arg . $condition; - if (\PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { if ((is_null($returnValue)) || ($arg < $returnValue)) { $returnValue = $arg; } @@ -2570,7 +2568,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -2664,7 +2662,7 @@ class Statistical return 0.5 * (1 + Engineering::erfVal(($value - $mean) / ($stdDev * sqrt(2)))); } - return (1 / (SQRT2PI * $stdDev)) * exp(0 - (pow($value - $mean, 2) / (2 * ($stdDev * $stdDev)))); + return (1 / (self::SQRT2PI * $stdDev)) * exp(0 - (pow($value - $mean, 2) / (2 * ($stdDev * $stdDev)))); } } @@ -3005,7 +3003,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getGoodnessOfFit(); } @@ -3018,7 +3016,7 @@ class Statistical * asymmetric tail extending toward more positive values. Negative skewness indicates a * distribution with an asymmetric tail extending toward more negative values. * - * @param array Data Series + * @param array ...$args Data Series * * @return float */ @@ -3075,7 +3073,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getSlope(); } @@ -3163,7 +3161,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3212,7 +3210,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3264,7 +3262,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3311,7 +3309,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3379,7 +3377,7 @@ class Statistical return Functions::DIV0(); } - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues); return $bestFitLinear->getStdevOfResiduals(); } @@ -3436,7 +3434,7 @@ class Statistical } $tsum *= $ts; if (($degrees % 2) == 1) { - $tsum = M_2DIVPI * ($tsum + $ttheta); + $tsum = Functions::M_2DIVPI * ($tsum + $ttheta); } $tValue = 0.5 * (1 + $tsum); if ($tails == 1) { @@ -3472,7 +3470,7 @@ class Statistical $dx = 1; $i = 0; - while ((abs($dx) > PRECISION) && ($i++ < MAX_ITERATIONS)) { + while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) { // Apply Newton-Raphson step $result = self::TDIST($x, $degrees, 2); $error = $result - $probability; @@ -3497,7 +3495,7 @@ class Statistical } $x = $xNew; } - if ($i == MAX_ITERATIONS) { + if ($i == self::MAX_ITERATIONS) { return Functions::NA(); } @@ -3530,7 +3528,7 @@ class Statistical $newValues = Functions::flattenArray($newValues); $const = (is_null($const)) ? true : (bool) Functions::flattenSingleValue($const); - $bestFitLinear = \PhpOffice\PhpSpreadsheet\Shared\trend\trend::calculate(\PhpOffice\PhpSpreadsheet\Shared\trend\trend::TREND_LINEAR, $yValues, $xValues, $const); + $bestFitLinear = Trend::calculate(Trend::TREND_LINEAR, $yValues, $xValues, $const); if (empty($newValues)) { $newValues = $bestFitLinear->getXValues(); } @@ -3601,7 +3599,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3645,7 +3643,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3698,7 +3696,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ @@ -3743,7 +3741,7 @@ class Statistical * * @category Statistical Functions * - * @param mixed $args Data values + * @param mixed ...$args Data values * * @return float */ diff --git a/src/PhpSpreadsheet/Calculation/TextData.php b/src/PhpSpreadsheet/Calculation/TextData.php index fd9cd7a9..ed4b8b9c 100644 --- a/src/PhpSpreadsheet/Calculation/TextData.php +++ b/src/PhpSpreadsheet/Calculation/TextData.php @@ -2,6 +2,11 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -67,7 +72,7 @@ class TextData $stringValue = Functions::flattenSingleValue($stringValue); if (is_bool($stringValue)) { - return ($stringValue) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + return ($stringValue) ? Calculation::getTRUE() : Calculation::getFALSE(); } if (self::$invalidChars == null) { @@ -92,7 +97,7 @@ class TextData { $stringValue = Functions::flattenSingleValue($stringValue); if (is_bool($stringValue)) { - return ($stringValue) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + return ($stringValue) ? Calculation::getTRUE() : Calculation::getFALSE(); } if (is_string($stringValue) || is_numeric($stringValue)) { @@ -119,7 +124,7 @@ class TextData if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) { $characters = (int) $characters; } else { - $characters = ($characters) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $characters = ($characters) ? Calculation::getTRUE() : Calculation::getFALSE(); } } @@ -147,7 +152,7 @@ class TextData if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) { $arg = (int) $arg; } else { - $arg = ($arg) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE(); } } $returnValue .= $arg; @@ -191,7 +196,7 @@ class TextData $value = MathTrig::MROUND($value, $round); } - return \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString($value, $mask); + return NumberFormat::toFormattedString($value, $mask); } /** @@ -211,11 +216,11 @@ class TextData if (!is_bool($needle)) { if (is_bool($haystack)) { - $haystack = ($haystack) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $haystack = ($haystack) ? Calculation::getTRUE() : Calculation::getFALSE(); } - if (($offset > 0) && (\PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($haystack) > $offset)) { - if (\PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($needle) == 0) { + if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) { + if (StringHelper::countCharacters($needle) == 0) { return $offset; } @@ -246,11 +251,11 @@ class TextData if (!is_bool($needle)) { if (is_bool($haystack)) { - $haystack = ($haystack) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $haystack = ($haystack) ? Calculation::getTRUE() : Calculation::getFALSE(); } - if (($offset > 0) && (\PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($haystack) > $offset)) { - if (\PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($needle) == 0) { + if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) { + if (StringHelper::countCharacters($needle) == 0) { return $offset; } @@ -314,7 +319,7 @@ class TextData } if (is_bool($value)) { - $value = ($value) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); } return mb_substr($value, 0, $chars, 'UTF-8'); @@ -340,7 +345,7 @@ class TextData } if (is_bool($value)) { - $value = ($value) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); } if (empty($chars)) { @@ -368,7 +373,7 @@ class TextData } if (is_bool($value)) { - $value = ($value) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); } return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8'); @@ -386,7 +391,7 @@ class TextData $value = Functions::flattenSingleValue($value); if (is_bool($value)) { - $value = ($value) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); } return mb_strlen($value, 'UTF-8'); @@ -406,10 +411,10 @@ class TextData $mixedCaseString = Functions::flattenSingleValue($mixedCaseString); if (is_bool($mixedCaseString)) { - $mixedCaseString = ($mixedCaseString) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $mixedCaseString = ($mixedCaseString) ? Calculation::getTRUE() : Calculation::getFALSE(); } - return \PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToLower($mixedCaseString); + return StringHelper::strToLower($mixedCaseString); } /** @@ -426,10 +431,10 @@ class TextData $mixedCaseString = Functions::flattenSingleValue($mixedCaseString); if (is_bool($mixedCaseString)) { - $mixedCaseString = ($mixedCaseString) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $mixedCaseString = ($mixedCaseString) ? Calculation::getTRUE() : Calculation::getFALSE(); } - return \PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToUpper($mixedCaseString); + return StringHelper::strToUpper($mixedCaseString); } /** @@ -446,10 +451,10 @@ class TextData $mixedCaseString = Functions::flattenSingleValue($mixedCaseString); if (is_bool($mixedCaseString)) { - $mixedCaseString = ($mixedCaseString) ? \PhpOffice\PhpSpreadsheet\Calculation::getTRUE() : \PhpOffice\PhpSpreadsheet\Calculation::getFALSE(); + $mixedCaseString = ($mixedCaseString) ? Calculation::getTRUE() : Calculation::getFALSE(); } - return \PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToTitle($mixedCaseString); + return StringHelper::strToTitle($mixedCaseString); } /** @@ -543,11 +548,11 @@ class TextData $value = Functions::flattenSingleValue($value); $format = Functions::flattenSingleValue($format); - if ((is_string($value)) && (!is_numeric($value)) && \PhpOffice\PhpSpreadsheet\Shared\Date::isDateTimeFormatCode($format)) { + if ((is_string($value)) && (!is_numeric($value)) && Date::isDateTimeFormatCode($format)) { $value = DateTime::DATEVALUE($value); } - return (string) \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString($value, $format); + return (string) NumberFormat::toFormattedString($value, $format); } /** @@ -563,9 +568,9 @@ class TextData if (!is_numeric($value)) { $numberValue = str_replace( - \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getThousandsSeparator(), + StringHelper::getThousandsSeparator(), '', - trim($value, " \t\n\r\0\x0B" . \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getCurrencyCode()) + trim($value, " \t\n\r\0\x0B" . StringHelper::getCurrencyCode()) ); if (is_numeric($numberValue)) { return (float) $numberValue; diff --git a/src/PhpSpreadsheet/Calculation/Token/Stack.php b/src/PhpSpreadsheet/Calculation/Token/Stack.php index efa63011..16b8635f 100644 --- a/src/PhpSpreadsheet/Calculation/Token/Stack.php +++ b/src/PhpSpreadsheet/Calculation/Token/Stack.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Token; +use PhpOffice\PhpSpreadsheet\Calculation; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -65,7 +67,7 @@ class Stack 'reference' => $reference, ]; if ($type == 'Function') { - $localeFunction = \PhpOffice\PhpSpreadsheet\Calculation::localeFunc($value); + $localeFunction = Calculation::localeFunc($value); if ($localeFunction != $value) { $this->stack[($this->count - 1)]['localeValue'] = $localeFunction; } diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 0263853d..2ed9b47f 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -948,6 +948,86 @@ class Cell return array_values($sortKeys); } + /** + * Convert an associative array of single cell coordinates to values to an associative array + * of cell ranges to values. Only adjacent cell coordinates with the same + * value will be merged. If the value is an object, it must implement the method getHashCode(). + * + * For example, this function converts: + * + * [ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y' ] + * + * to: + * + * [ 'A1:A3' => 'x', 'A4' => 'y' ] + * + * @param array $pCoordCollection associative array mapping coordinates to values + * + * @return array associative array mapping coordinate ranges to valuea + */ + public static function mergeRangesInCollection(array $pCoordCollection) + { + $hashedValues = []; + + foreach ($pCoordCollection as $coord => $value) { + list($column, $row) = self::coordinateFromString($coord); + $row = (int) (ltrim($row, '$')); + $hashCode = $column . '-' . (is_object($value) ? $value->getHashCode() : $value); + + if (!isset($hashedValues[$hashCode])) { + $hashedValues[$hashCode] = (object) [ + 'value' => $value, + 'col' => $column, + 'rows' => [$row], + ]; + } else { + $hashedValues[$hashCode]->rows[] = $row; + } + } + + $mergedCoordCollection = []; + ksort($hashedValues); + + foreach ($hashedValues as $hashedValue) { + sort($hashedValue->rows); + $rowStart = null; + $rowEnd = null; + $ranges = []; + + foreach ($hashedValue->rows as $row) { + if ($rowStart === null) { + $rowStart = $row; + $rowEnd = $row; + } elseif ($rowEnd === $row - 1) { + $rowEnd = $row; + } else { + if ($rowStart == $rowEnd) { + $ranges[] = $hashedValue->col . $rowStart; + } else { + $ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd; + } + + $rowStart = $row; + $rowEnd = $row; + } + } + + if ($rowStart !== null) { + if ($rowStart == $rowEnd) { + $ranges[] = $hashedValue->col . $rowStart; + } else { + $ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd; + } + } + + foreach ($ranges as $range) { + $mergedCoordCollection[$range] = $hashedValue->value; + } + } + + return $mergedCoordCollection; + } + /** * Compare 2 cells. * diff --git a/src/PhpSpreadsheet/Cell/AdvancedValueBinder.php b/src/PhpSpreadsheet/Cell/AdvancedValueBinder.php index ba960839..f7f161fd 100644 --- a/src/PhpSpreadsheet/Cell/AdvancedValueBinder.php +++ b/src/PhpSpreadsheet/Cell/AdvancedValueBinder.php @@ -2,6 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,36 +36,36 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder /** * Bind value to a cell. * - * @param \PhpOffice\PhpSpreadsheet\Cell $cell Cell to bind value to + * @param Cell $cell Cell to bind value to * @param mixed $value Value to bind in cell * * @return bool */ - public function bindValue(\PhpOffice\PhpSpreadsheet\Cell $cell, $value = null) + public function bindValue(Cell $cell, $value = null) { // sanitize UTF-8 strings if (is_string($value)) { - $value = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::sanitizeUTF8($value); + $value = StringHelper::sanitizeUTF8($value); } // Find out data type $dataType = parent::dataTypeForValue($value); // Style logic - strings - if ($dataType === DataType::TYPE_STRING && !$value instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if ($dataType === DataType::TYPE_STRING && !$value instanceof RichText) { // Test for booleans using locale-setting - if ($value == \PhpOffice\PhpSpreadsheet\Calculation::getTRUE()) { + if ($value == Calculation::getTRUE()) { $cell->setValueExplicit(true, DataType::TYPE_BOOL); return true; - } elseif ($value == \PhpOffice\PhpSpreadsheet\Calculation::getFALSE()) { + } elseif ($value == Calculation::getFALSE()) { $cell->setValueExplicit(false, DataType::TYPE_BOOL); return true; } // Check for number in scientific format - if (preg_match('/^' . \PhpOffice\PhpSpreadsheet\Calculation::CALCULATION_REGEXP_NUMBER . '$/', $value)) { + if (preg_match('/^' . Calculation::CALCULATION_REGEXP_NUMBER . '$/', $value)) { $cell->setValueExplicit((float) $value, DataType::TYPE_NUMERIC); return true; @@ -98,15 +105,15 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder $cell->setValueExplicit($value, DataType::TYPE_NUMERIC); // Set style $cell->getWorksheet()->getStyle($cell->getCoordinate()) - ->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00); + ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_PERCENTAGE_00); return true; } // Check for currency - $currencyCode = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getCurrencyCode(); - $decimalSeparator = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getDecimalSeparator(); - $thousandsSeparator = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getThousandsSeparator(); + $currencyCode = StringHelper::getCurrencyCode(); + $decimalSeparator = StringHelper::getDecimalSeparator(); + $thousandsSeparator = StringHelper::getThousandsSeparator(); if (preg_match('/^' . preg_quote($currencyCode) . ' *(\d{1,3}(' . preg_quote($thousandsSeparator) . '\d{3})*|(\d+))(' . preg_quote($decimalSeparator) . '\d{2})?$/', $value)) { // Convert value to number $value = (float) trim(str_replace([$currencyCode, $thousandsSeparator, $decimalSeparator], ['', '', '.'], $value)); @@ -114,7 +121,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder // Set style $cell->getWorksheet()->getStyle($cell->getCoordinate()) ->getNumberFormat()->setFormatCode( - str_replace('$', $currencyCode, \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE) + str_replace('$', $currencyCode, NumberFormat::FORMAT_CURRENCY_USD_SIMPLE) ); return true; @@ -124,7 +131,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder $cell->setValueExplicit($value, DataType::TYPE_NUMERIC); // Set style $cell->getWorksheet()->getStyle($cell->getCoordinate()) - ->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); + ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); return true; } @@ -137,7 +144,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder $cell->setValueExplicit($days, DataType::TYPE_NUMERIC); // Set style $cell->getWorksheet()->getStyle($cell->getCoordinate()) - ->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME3); + ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_TIME3); return true; } @@ -151,13 +158,13 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder $cell->setValueExplicit($days, DataType::TYPE_NUMERIC); // Set style $cell->getWorksheet()->getStyle($cell->getCoordinate()) - ->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4); + ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_TIME4); return true; } // Check for datetime, e.g. '2008-12-31', '2008-12-31 15:59', '2008-12-31 15:59:10' - if (($d = \PhpOffice\PhpSpreadsheet\Shared\Date::stringToExcel($value)) !== false) { + if (($d = Date::stringToExcel($value)) !== false) { // Convert value to number $cell->setValueExplicit($d, DataType::TYPE_NUMERIC); // Determine style. Either there is a time part or not. Look for ':' @@ -174,7 +181,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder // Check for newline character "\n" if (strpos($value, "\n") !== false) { - $value = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::sanitizeUTF8($value); + $value = StringHelper::sanitizeUTF8($value); $cell->setValueExplicit($value, DataType::TYPE_STRING); // Set style $cell->getWorksheet()->getStyle($cell->getCoordinate()) diff --git a/src/PhpSpreadsheet/Cell/DataType.php b/src/PhpSpreadsheet/Cell/DataType.php index 2f41b66c..b308fe74 100644 --- a/src/PhpSpreadsheet/Cell/DataType.php +++ b/src/PhpSpreadsheet/Cell/DataType.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -71,13 +74,13 @@ class DataType */ public static function checkString($pValue) { - if ($pValue instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if ($pValue instanceof RichText) { // TODO: Sanitize Rich-Text string (max. character count is 32,767) return $pValue; } // string must never be longer than 32,767 characters, truncate if necessary - $pValue = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::substring($pValue, 0, 32767); + $pValue = StringHelper::substring($pValue, 0, 32767); // we require that newline is represented as "\n" in core, not as "\r\n" or "\r" $pValue = str_replace(["\r\n", "\r"], "\n", $pValue); diff --git a/src/PhpSpreadsheet/Cell/DefaultValueBinder.php b/src/PhpSpreadsheet/Cell/DefaultValueBinder.php index f9e7729f..a0fc5209 100644 --- a/src/PhpSpreadsheet/Cell/DefaultValueBinder.php +++ b/src/PhpSpreadsheet/Cell/DefaultValueBinder.php @@ -2,6 +2,11 @@ namespace PhpOffice\PhpSpreadsheet\Cell; +use DateTime; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,21 +34,21 @@ class DefaultValueBinder implements IValueBinder /** * Bind value to a cell. * - * @param \PhpOffice\PhpSpreadsheet\Cell $cell Cell to bind value to + * @param Cell $cell Cell to bind value to * @param mixed $value Value to bind in cell * * @return bool */ - public function bindValue(\PhpOffice\PhpSpreadsheet\Cell $cell, $value = null) + public function bindValue(Cell $cell, $value = null) { // sanitize UTF-8 strings if (is_string($value)) { - $value = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::sanitizeUTF8($value); + $value = StringHelper::sanitizeUTF8($value); } elseif (is_object($value)) { // Handle any objects that might be injected - if ($value instanceof \DateTime) { + if ($value instanceof DateTime) { $value = $value->format('Y-m-d H:i:s'); - } elseif (!($value instanceof \PhpOffice\PhpSpreadsheet\RichText)) { + } elseif (!($value instanceof RichText)) { $value = (string) $value; } } @@ -69,7 +74,7 @@ class DefaultValueBinder implements IValueBinder return DataType::TYPE_NULL; } elseif ($pValue === '') { return DataType::TYPE_STRING; - } elseif ($pValue instanceof \PhpOffice\PhpSpreadsheet\RichText) { + } elseif ($pValue instanceof RichText) { return DataType::TYPE_INLINE; } elseif ($pValue[0] === '=' && strlen($pValue) > 1) { return DataType::TYPE_FORMULA; diff --git a/src/PhpSpreadsheet/Cell/IValueBinder.php b/src/PhpSpreadsheet/Cell/IValueBinder.php index 191eb844..72813b2c 100644 --- a/src/PhpSpreadsheet/Cell/IValueBinder.php +++ b/src/PhpSpreadsheet/Cell/IValueBinder.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Cell; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,10 +31,10 @@ interface IValueBinder /** * Bind value to a cell. * - * @param \PhpOffice\PhpSpreadsheet\Cell $cell Cell to bind value to + * @param Cell $cell Cell to bind value to * @param mixed $value Value to bind in cell * * @return bool */ - public function bindValue(\PhpOffice\PhpSpreadsheet\Cell $cell, $value = null); + public function bindValue(Cell $cell, $value = null); } diff --git a/src/PhpSpreadsheet/Chart/DataSeries.php b/src/PhpSpreadsheet/Chart/DataSeries.php index 092736a6..63be0d41 100644 --- a/src/PhpSpreadsheet/Chart/DataSeries.php +++ b/src/PhpSpreadsheet/Chart/DataSeries.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Chart; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -388,7 +390,7 @@ class DataSeries return $this; } - public function refresh(\PhpOffice\PhpSpreadsheet\Worksheet $worksheet) + public function refresh(Worksheet $worksheet) { foreach ($this->plotValues as $plotValues) { if ($plotValues !== null) { diff --git a/src/PhpSpreadsheet/Chart/DataSeriesValues.php b/src/PhpSpreadsheet/Chart/DataSeriesValues.php index 82813400..7fbb5fb3 100644 --- a/src/PhpSpreadsheet/Chart/DataSeriesValues.php +++ b/src/PhpSpreadsheet/Chart/DataSeriesValues.php @@ -2,6 +2,11 @@ namespace PhpOffice\PhpSpreadsheet\Chart; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -76,17 +81,25 @@ class DataSeriesValues */ private $dataValues = []; + /** + * Fill color. + * + * @var string + */ + private $fillColor; + /** * Create a new DataSeriesValues object. * - * @param mixed $dataType + * @param string $dataType * @param string $dataSource * @param null|mixed $formatCode - * @param mixed $pointCount + * @param int $pointCount * @param mixed $dataValues * @param null|mixed $marker + * @param null|string $fillColor */ - public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = [], $marker = null) + public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = [], $marker = null, $fillColor = null) { $this->setDataType($dataType); $this->dataSource = $dataSource; @@ -94,6 +107,7 @@ class DataSeriesValues $this->pointCount = $pointCount; $this->dataValues = $dataValues; $this->pointMarker = $marker; + $this->fillColor = $fillColor; } /** @@ -111,9 +125,9 @@ class DataSeriesValues * * @param string $dataType Datatype of this data series * Typical values are: - * \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues::DATASERIES_TYPE_STRING + * DataSeriesValues::DATASERIES_TYPE_STRING * Normally used for axis point values - * \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues::DATASERIES_TYPE_NUMBER + * DataSeriesValues::DATASERIES_TYPE_NUMBER * Normally used for chart data values * * @throws Exception @@ -212,6 +226,33 @@ class DataSeriesValues return $this->pointCount; } + /** + * Get fill color. + * + * @return string HEX color + */ + public function getFillColor() + { + return $this->fillColor; + } + + /** + * Set fill color for series. + * + * @param string $color HEX color + * + * @return DataSeriesValues + */ + public function setFillColor($color) + { + if (!preg_match('/^[a-f0-9]{6}$/i', $color)) { + throw new Exception('Invalid hex color for chart series'); + } + $this->fillColor = $color; + + return $this; + } + /** * Identify if the Data Series is a multi-level or a simple series. * @@ -277,17 +318,17 @@ class DataSeriesValues */ public function setDataValues($dataValues) { - $this->dataValues = \PhpOffice\PhpSpreadsheet\Calculation\Functions::flattenArray($dataValues); + $this->dataValues = Functions::flattenArray($dataValues); $this->pointCount = count($dataValues); return $this; } - public function refresh(\PhpOffice\PhpSpreadsheet\Worksheet $worksheet, $flatten = true) + public function refresh(Worksheet $worksheet, $flatten = true) { if ($this->dataSource !== null) { - $calcEngine = \PhpOffice\PhpSpreadsheet\Calculation::getInstance($worksheet->getParent()); - $newDataValues = \PhpOffice\PhpSpreadsheet\Calculation::unwrapResult( + $calcEngine = Calculation::getInstance($worksheet->getParent()); + $newDataValues = Calculation::unwrapResult( $calcEngine->_calculateFormulaValue( '=' . $this->dataSource, null, @@ -295,7 +336,7 @@ class DataSeriesValues ) ); if ($flatten) { - $this->dataValues = \PhpOffice\PhpSpreadsheet\Calculation\Functions::flattenArray($newDataValues); + $this->dataValues = Functions::flattenArray($newDataValues); foreach ($this->dataValues as &$dataValue) { if ((!empty($dataValue)) && ($dataValue[0] == '#')) { $dataValue = 0.0; @@ -308,9 +349,9 @@ class DataSeriesValues list(, $cellRange) = $cellRange; } - $dimensions = \PhpOffice\PhpSpreadsheet\Cell::rangeDimension(str_replace('$', '', $cellRange)); + $dimensions = Cell::rangeDimension(str_replace('$', '', $cellRange)); if (($dimensions[0] == 1) || ($dimensions[1] == 1)) { - $this->dataValues = \PhpOffice\PhpSpreadsheet\Calculation\Functions::flattenArray($newDataValues); + $this->dataValues = Functions::flattenArray($newDataValues); } else { $newArray = array_values(array_shift($newDataValues)); foreach ($newArray as $i => $newDataSet) { diff --git a/src/PhpSpreadsheet/Chart/Exception.php b/src/PhpSpreadsheet/Chart/Exception.php index 57562b73..9c19cfd7 100644 --- a/src/PhpSpreadsheet/Chart/Exception.php +++ b/src/PhpSpreadsheet/Chart/Exception.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Chart; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +26,7 @@ namespace PhpOffice\PhpSpreadsheet\Chart; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Exception extends \PhpOffice\PhpSpreadsheet\Exception +class Exception extends PhpSpreadsheetException { /** * Error handler callback. diff --git a/src/PhpSpreadsheet/Chart/PlotArea.php b/src/PhpSpreadsheet/Chart/PlotArea.php index 5c16db84..0dd12cd4 100644 --- a/src/PhpSpreadsheet/Chart/PlotArea.php +++ b/src/PhpSpreadsheet/Chart/PlotArea.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Chart; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -124,7 +126,7 @@ class PlotArea return $this; } - public function refresh(\PhpOffice\PhpSpreadsheet\Worksheet $worksheet) + public function refresh(Worksheet $worksheet) { foreach ($this->plotSeries as $plotSeries) { $plotSeries->refresh($worksheet); diff --git a/src/PhpSpreadsheet/Chart/Renderer/JpGraph.php b/src/PhpSpreadsheet/Chart/Renderer/JpGraph.php index 834d06d8..53883f45 100644 --- a/src/PhpSpreadsheet/Chart/Renderer/JpGraph.php +++ b/src/PhpSpreadsheet/Chart/Renderer/JpGraph.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Chart\Renderer; +use PhpOffice\PhpSpreadsheet\Chart; +use PhpOffice\PhpSpreadsheet\Settings; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -105,7 +108,7 @@ class JpGraph } else { // Format labels according to any formatting code if (!is_null($datasetLabelFormatCode)) { - $datasetLabels[$i] = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString($datasetLabel, $datasetLabelFormatCode); + $datasetLabels[$i] = NumberFormat::toFormattedString($datasetLabel, $datasetLabelFormatCode); } } ++$testCurrentIndex; @@ -542,7 +545,7 @@ class JpGraph private function renderAreaChart($groupCount, $dimensions = '2d') { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_line.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_line.php'; $this->renderCartesianPlotArea(); @@ -553,7 +556,7 @@ class JpGraph private function renderLineChart($groupCount, $dimensions = '2d') { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_line.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_line.php'; $this->renderCartesianPlotArea(); @@ -564,7 +567,7 @@ class JpGraph private function renderBarChart($groupCount, $dimensions = '2d') { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_bar.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_bar.php'; $this->renderCartesianPlotArea(); @@ -575,9 +578,9 @@ class JpGraph private function renderScatterChart($groupCount) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_scatter.php'; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_regstat.php'; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_line.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_scatter.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_regstat.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_line.php'; $this->renderCartesianPlotArea('linlin'); @@ -588,7 +591,7 @@ class JpGraph private function renderBubbleChart($groupCount) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_scatter.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_scatter.php'; $this->renderCartesianPlotArea('linlin'); @@ -599,9 +602,9 @@ class JpGraph private function renderPieChart($groupCount, $dimensions = '2d', $doughnut = false, $multiplePlots = false) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_pie.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_pie.php'; if ($dimensions == '3d') { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_pie3d.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_pie3d.php'; } $this->renderPiePlotArea($doughnut); @@ -675,7 +678,7 @@ class JpGraph private function renderRadarChart($groupCount) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_radar.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_radar.php'; $this->renderRadarPlotArea(); @@ -686,7 +689,7 @@ class JpGraph private function renderStockChart($groupCount) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_stock.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_stock.php'; $this->renderCartesianPlotArea('intint'); @@ -697,7 +700,7 @@ class JpGraph private function renderContourChart($groupCount, $dimensions) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_contour.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_contour.php'; $this->renderCartesianPlotArea('intint'); @@ -708,11 +711,11 @@ class JpGraph private function renderCombinationChart($groupCount, $dimensions, $outputDestination) { - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_line.php'; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_bar.php'; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_scatter.php'; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_regstat.php'; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . 'jpgraph_line.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_line.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_bar.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_scatter.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_regstat.php'; + require_once Settings::getChartRendererPath() . 'jpgraph_line.php'; $this->renderCartesianPlotArea(); @@ -848,11 +851,11 @@ class JpGraph /** * Create a new jpgraph. */ - public function __construct(\PhpOffice\PhpSpreadsheet\Chart $chart) + public function __construct(Chart $chart) { $this->graph = null; $this->chart = $chart; - require_once \PhpOffice\PhpSpreadsheet\Settings::getChartRendererPath() . '/jpgraph.php'; + require_once Settings::getChartRendererPath() . '/jpgraph.php'; } } diff --git a/src/PhpSpreadsheet/Collection/Cells.php b/src/PhpSpreadsheet/Collection/Cells.php index 137b6f90..daef9040 100644 --- a/src/PhpSpreadsheet/Collection/Cells.php +++ b/src/PhpSpreadsheet/Collection/Cells.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheet\Collection; use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Worksheet; use Psr\SimpleCache\CacheInterface; @@ -124,7 +125,7 @@ class Cells * * @param Cell $cell Cell to update * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Cell */ @@ -138,7 +139,7 @@ class Cells * * @param string $pCoord Coordinate of the cell to delete * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ public function delete($pCoord) { @@ -342,7 +343,7 @@ class Cells $stored = $newCollection->cache->setMultiple($newValues); if (!$stored) { $newCollection->__destruct(); - throw new \PhpOffice\PhpSpreadsheet\Exception('Failed to copy cells in cache'); + throw new PhpSpreadsheetException('Failed to copy cells in cache'); } return $newCollection; @@ -382,7 +383,7 @@ class Cells * Store cell data in cache for the current cell object if it's "dirty", * and the 'nullify' the current cell object. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ private function storeCurrentCell() { @@ -392,7 +393,7 @@ class Cells $stored = $this->cache->set($this->cachePrefix . $this->currentCoordinate, $this->currentCell); if (!$stored) { $this->__destruct(); - throw new \PhpOffice\PhpSpreadsheet\Exception("Failed to store cell {$this->currentCoordinate} in cache"); + throw new PhpSpreadsheetException("Failed to store cell {$this->currentCoordinate} in cache"); } $this->currentCellIsDirty = false; } @@ -407,7 +408,7 @@ class Cells * @param string $pCoord Coordinate of the cell to update * @param Cell $cell Cell to update * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Cell */ @@ -430,7 +431,7 @@ class Cells * * @param string $pCoord Coordinate of the cell * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Cell Cell that was found, or null if not found */ @@ -449,7 +450,7 @@ class Cells // Check if the entry that has been requested actually exists $cell = $this->cache->get($this->cachePrefix . $pCoord); if ($cell === null) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Cell entry {$pCoord} no longer exists in cache. This probably means that the cache was cleared by someone else."); + throw new PhpSpreadsheetException("Cell entry {$pCoord} no longer exists in cache. This probably means that the cache was cleared by someone else."); } // Set current entry to the requested entry diff --git a/src/PhpSpreadsheet/Collection/Memory.php b/src/PhpSpreadsheet/Collection/Memory.php index 966b84ba..a32551b0 100644 --- a/src/PhpSpreadsheet/Collection/Memory.php +++ b/src/PhpSpreadsheet/Collection/Memory.php @@ -2,13 +2,15 @@ namespace PhpOffice\PhpSpreadsheet\Collection; +use Psr\SimpleCache\CacheInterface; + /** * This is the default implementation for in-memory cell collection. * * Alternatives implementation should leverage off-memory, non-volatile storage * to reduce overall memory usage. */ -class Memory implements \Psr\SimpleCache\CacheInterface +class Memory implements CacheInterface { private $cache = []; diff --git a/src/PhpSpreadsheet/Document/Security.php b/src/PhpSpreadsheet/Document/Security.php index 6bb99b97..0175dcc4 100644 --- a/src/PhpSpreadsheet/Document/Security.php +++ b/src/PhpSpreadsheet/Document/Security.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Document; +use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -173,7 +175,7 @@ class Security public function setRevisionsPassword($pValue, $pAlreadyHashed = false) { if (!$pAlreadyHashed) { - $pValue = \PhpOffice\PhpSpreadsheet\Shared\PasswordHasher::hashPassword($pValue); + $pValue = PasswordHasher::hashPassword($pValue); } $this->revisionsPassword = $pValue; @@ -201,7 +203,7 @@ class Security public function setWorkbookPassword($pValue, $pAlreadyHashed = false) { if (!$pAlreadyHashed) { - $pValue = \PhpOffice\PhpSpreadsheet\Shared\PasswordHasher::hashPassword($pValue); + $pValue = PasswordHasher::hashPassword($pValue); } $this->workbookPassword = $pValue; diff --git a/src/PhpSpreadsheet/Helper/Html.php b/src/PhpSpreadsheet/Helper/Html.php index 67b3c481..a78be230 100644 --- a/src/PhpSpreadsheet/Helper/Html.php +++ b/src/PhpSpreadsheet/Helper/Html.php @@ -6,6 +6,9 @@ use DOMDocument; use DOMElement; use DOMNode; use DOMText; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Style\Color; +use PhpOffice\PhpSpreadsheet\Style\Font; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -625,7 +628,7 @@ class Html // Discard excess white space $dom->preserveWhiteSpace = false; - $this->richTextObject = new \PhpOffice\PhpSpreadsheet\RichText(); + $this->richTextObject = new RichText(); $this->parseElements($dom); // Clean any further spurious whitespace @@ -663,7 +666,7 @@ class Html $richtextRun->getFont()->setSize($this->size); } if ($this->color) { - $richtextRun->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color('ff' . $this->color)); + $richtextRun->getFont()->setColor(new Color('ff' . $this->color)); } if ($this->bold) { $richtextRun->getFont()->setBold(true); @@ -672,13 +675,13 @@ class Html $richtextRun->getFont()->setItalic(true); } if ($this->underline) { - $richtextRun->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); + $richtextRun->getFont()->setUnderline(Font::UNDERLINE_SINGLE); } if ($this->superscript) { - $richtextRun->getFont()->setSuperScript(true); + $richtextRun->getFont()->setSuperscript(true); } if ($this->subscript) { - $richtextRun->getFont()->setSubScript(true); + $richtextRun->getFont()->setSubscript(true); } if ($this->strikethrough) { $richtextRun->getFont()->setStrikethrough(true); diff --git a/src/PhpSpreadsheet/Helper/Sample.php b/src/PhpSpreadsheet/Helper/Sample.php index e6cf1530..c538fe95 100644 --- a/src/PhpSpreadsheet/Helper/Sample.php +++ b/src/PhpSpreadsheet/Helper/Sample.php @@ -4,6 +4,8 @@ namespace PhpOffice\PhpSpreadsheet\Helper; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\IWriter; +use ReflectionClass; /** * Helper class to be used in sample code. @@ -164,15 +166,17 @@ class Sample /** * Log a line about the write operation. * - * @param \PhpOffice\PhpSpreadsheet\Writer\IWriter $writer + * @param IWriter $writer * @param string $path * @param float $callStartTime + * + * @throws \ReflectionException */ - public function logWrite(\PhpOffice\PhpSpreadsheet\Writer\IWriter $writer, $path, $callStartTime) + public function logWrite(IWriter $writer, $path, $callStartTime) { $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; - $reflection = new \ReflectionClass($writer); + $reflection = new ReflectionClass($writer); $format = $reflection->getShortName(); $message = "Write {$format} format to {$path} in " . sprintf('%.4f', $callTime) . ' seconds'; diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index c0d064b7..7924e37e 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Reader; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; /** @@ -266,7 +268,7 @@ class Csv extends BaseReader implements IReader $worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1); } - $worksheetInfo[0]['lastColumnLetter'] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); + $worksheetInfo[0]['lastColumnLetter'] = Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1; // Close file @@ -282,12 +284,12 @@ class Csv extends BaseReader implements IReader * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ public function load($pFilename) { // Create new Spreadsheet - $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $spreadsheet = new Spreadsheet(); // Load into this instance return $this->loadIntoExisting($pFilename, $spreadsheet); @@ -339,7 +341,7 @@ class Csv extends BaseReader implements IReader if ($rowDatum != '' && $this->readFilter->readCell($columnLetter, $currentRow)) { // Convert encoding if necessary if ($this->inputEncoding !== 'UTF-8') { - $rowDatum = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($rowDatum, 'UTF-8', $this->inputEncoding); + $rowDatum = StringHelper::convertEncoding($rowDatum, 'UTF-8', $this->inputEncoding); } // Set cell value diff --git a/src/PhpSpreadsheet/Reader/Exception.php b/src/PhpSpreadsheet/Reader/Exception.php index 167ab4ac..5f2ce05d 100644 --- a/src/PhpSpreadsheet/Reader/Exception.php +++ b/src/PhpSpreadsheet/Reader/Exception.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Reader; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +26,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Exception extends \PhpOffice\PhpSpreadsheet\Exception +class Exception extends PhpSpreadsheetException { /** * Error handler callback. diff --git a/src/PhpSpreadsheet/Reader/Gnumeric.php b/src/PhpSpreadsheet/Reader/Gnumeric.php index c6418704..a153e0c7 100644 --- a/src/PhpSpreadsheet/Reader/Gnumeric.php +++ b/src/PhpSpreadsheet/Reader/Gnumeric.php @@ -3,8 +3,20 @@ namespace PhpOffice\PhpSpreadsheet\Reader; use DateTimeZone; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\NamedRange; +use PhpOffice\PhpSpreadsheet\ReferenceHelper; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Settings; +use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Borders; +use PhpOffice\PhpSpreadsheet\Style\Fill; +use PhpOffice\PhpSpreadsheet\Style\Font; +use XMLReader; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -52,7 +64,7 @@ class Gnumeric extends BaseReader implements IReader public function __construct() { $this->readFilter = new DefaultReadFilter(); - $this->referenceHelper = \PhpOffice\PhpSpreadsheet\ReferenceHelper::getInstance(); + $this->referenceHelper = ReferenceHelper::getInstance(); } /** @@ -97,7 +109,7 @@ class Gnumeric extends BaseReader implements IReader File::assertFile($pFilename); $xml = new XMLReader(); - $xml->xml($this->securityScanFile('compress.zlib://' . realpath($pFilename)), null, \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions()); + $xml->xml($this->securityScanFile('compress.zlib://' . realpath($pFilename)), null, Settings::getLibXmlLoaderOptions()); $xml->setParserProperty(2, true); $worksheetNames = []; @@ -126,7 +138,7 @@ class Gnumeric extends BaseReader implements IReader File::assertFile($pFilename); $xml = new XMLReader(); - $xml->xml($this->securityScanFile('compress.zlib://' . realpath($pFilename)), null, \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions()); + $xml->xml($this->securityScanFile('compress.zlib://' . realpath($pFilename)), null, Settings::getLibXmlLoaderOptions()); $xml->setParserProperty(2, true); $worksheetInfo = []; @@ -154,7 +166,7 @@ class Gnumeric extends BaseReader implements IReader break; } } - $tmpInfo['lastColumnLetter'] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); + $tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $worksheetInfo[] = $tmpInfo; } } @@ -216,7 +228,7 @@ class Gnumeric extends BaseReader implements IReader $gFileData = $this->gzfileGetContents($pFilename); - $xml = simplexml_load_string($this->securityScan($gFileData), 'SimpleXMLElement', \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions()); + $xml = simplexml_load_string($this->securityScan($gFileData), 'SimpleXMLElement', Settings::getLibXmlLoaderOptions()); $namespacesMeta = $xml->getNamespaces(true); $gnmXML = $xml->children($namespacesMeta['gnm']); @@ -339,7 +351,7 @@ class Gnumeric extends BaseReader implements IReader // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula // cells... during the load, all formulae should be correct, and we're simply bringing the worksheet // name in line with the formula, not the reverse - $spreadsheet->getActiveSheet()->setTitle($worksheetName, false); + $spreadsheet->getActiveSheet()->setTitle($worksheetName, false, false); if ((!$this->readDataOnly) && (isset($sheet->PrintInformation))) { if (isset($sheet->PrintInformation->Margins)) { @@ -387,7 +399,7 @@ class Gnumeric extends BaseReader implements IReader $maxCol = $column; } - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = Cell::stringFromColumnIndex($column); // Read cell? if ($this->getReadFilter() !== null) { @@ -398,7 +410,7 @@ class Gnumeric extends BaseReader implements IReader $ValueType = $cellAttributes->ValueType; $ExprID = (string) $cellAttributes->ExprID; - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA; + $type = Cell\DataType::TYPE_FORMULA; if ($ExprID > '') { if (((string) $cell) > '') { $this->expressions[$ExprID] = [ @@ -417,27 +429,27 @@ class Gnumeric extends BaseReader implements IReader $worksheetName ); } - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA; + $type = Cell\DataType::TYPE_FORMULA; } else { switch ($ValueType) { case '10': // NULL - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL; + $type = Cell\DataType::TYPE_NULL; break; case '20': // Boolean - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL; + $type = Cell\DataType::TYPE_BOOL; $cell = ($cell == 'TRUE') ? true : false; break; case '30': // Integer $cell = (int) $cell; // Excel 2007+ doesn't differentiate between integer and float, so set the value and dropthru to the next (numeric) case case '40': // Float - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC; + $type = Cell\DataType::TYPE_NUMERIC; break; case '50': // Error - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR; + $type = Cell\DataType::TYPE_ERROR; break; case '60': // String - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING; + $type = Cell\DataType::TYPE_STRING; break; case '70': // Cell Range case '80': // Array @@ -459,11 +471,11 @@ class Gnumeric extends BaseReader implements IReader $styleAttributes = $styleRegion->attributes(); if (($styleAttributes['startRow'] <= $maxRow) && ($styleAttributes['startCol'] <= $maxCol)) { - $startColumn = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex((int) $styleAttributes['startCol']); + $startColumn = Cell::stringFromColumnIndex((int) $styleAttributes['startCol']); $startRow = $styleAttributes['startRow'] + 1; $endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol']; - $endColumn = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($endColumn); + $endColumn = Cell::stringFromColumnIndex($endColumn); $endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow']; $endRow += 1; $cellRange = $startColumn . $startRow . ':' . $endColumn . $endRow; @@ -472,49 +484,49 @@ class Gnumeric extends BaseReader implements IReader // We still set the number format mask for date/time values, even if readDataOnly is true if ((!$this->readDataOnly) || - (\PhpOffice\PhpSpreadsheet\Shared\Date::isDateTimeFormatCode((string) $styleAttributes['Format']))) { + (Date::isDateTimeFormatCode((string) $styleAttributes['Format']))) { $styleArray = []; - $styleArray['numberformat']['code'] = (string) $styleAttributes['Format']; + $styleArray['numberFormat']['formatCode'] = (string) $styleAttributes['Format']; // If readDataOnly is false, we set all formatting information if (!$this->readDataOnly) { switch ($styleAttributes['HAlign']) { case '1': - $styleArray['alignment']['horizontal'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL; + $styleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_GENERAL; break; case '2': - $styleArray['alignment']['horizontal'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT; + $styleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_LEFT; break; case '4': - $styleArray['alignment']['horizontal'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT; + $styleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_RIGHT; break; case '8': - $styleArray['alignment']['horizontal'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER; + $styleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_CENTER; break; case '16': case '64': - $styleArray['alignment']['horizontal'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS; + $styleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_CENTER_CONTINUOUS; break; case '32': - $styleArray['alignment']['horizontal'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY; + $styleArray['alignment']['horizontal'] = Alignment::HORIZONTAL_JUSTIFY; break; } switch ($styleAttributes['VAlign']) { case '1': - $styleArray['alignment']['vertical'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP; + $styleArray['alignment']['vertical'] = Alignment::VERTICAL_TOP; break; case '2': - $styleArray['alignment']['vertical'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM; + $styleArray['alignment']['vertical'] = Alignment::VERTICAL_BOTTOM; break; case '4': - $styleArray['alignment']['vertical'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER; + $styleArray['alignment']['vertical'] = Alignment::VERTICAL_CENTER; break; case '8': - $styleArray['alignment']['vertical'] = \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY; + $styleArray['alignment']['vertical'] = Alignment::VERTICAL_JUSTIFY; break; } - $styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? true : false; + $styleArray['alignment']['wrapText'] = ($styleAttributes['WrapText'] == '1') ? true : false; $styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? true : false; $styleArray['alignment']['indent'] = ((int) ($styleAttributes['Indent']) > 0) ? $styleAttributes['indent'] : 0; @@ -523,69 +535,69 @@ class Gnumeric extends BaseReader implements IReader $RGB = self::parseGnumericColour($styleAttributes['Back']); $shade = $styleAttributes['Shade']; if (($RGB != '000000') || ($shade != '0')) { - $styleArray['fill']['color']['rgb'] = $styleArray['fill']['startcolor']['rgb'] = $RGB; + $styleArray['fill']['color']['rgb'] = $styleArray['fill']['startColor']['rgb'] = $RGB; $RGB2 = self::parseGnumericColour($styleAttributes['PatternColor']); - $styleArray['fill']['endcolor']['rgb'] = $RGB2; + $styleArray['fill']['endColor']['rgb'] = $RGB2; switch ($shade) { case '1': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID; + $styleArray['fill']['fillType'] = Fill::FILL_SOLID; break; case '2': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR; + $styleArray['fill']['fillType'] = Fill::FILL_GRADIENT_LINEAR; break; case '3': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH; + $styleArray['fill']['fillType'] = Fill::FILL_GRADIENT_PATH; break; case '4': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKDOWN; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKDOWN; break; case '5': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRAY; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKGRAY; break; case '6': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRID; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKGRID; break; case '7': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKHORIZONTAL; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKHORIZONTAL; break; case '8': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKTRELLIS; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKTRELLIS; break; case '9': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKUP; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKUP; break; case '10': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKVERTICAL; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_DARKVERTICAL; break; case '11': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY0625; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_GRAY0625; break; case '12': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_GRAY125; break; case '13': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTDOWN; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTDOWN; break; case '14': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRAY; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTGRAY; break; case '15': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRID; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTGRID; break; case '16': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTHORIZONTAL; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTHORIZONTAL; break; case '17': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTTRELLIS; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTTRELLIS; break; case '18': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTUP; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTUP; break; case '19': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTVERTICAL; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_LIGHTVERTICAL; break; case '20': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_MEDIUMGRAY; + $styleArray['fill']['fillType'] = Fill::FILL_PATTERN_MEDIUMGRAY; break; } } @@ -595,30 +607,30 @@ class Gnumeric extends BaseReader implements IReader $styleArray['font']['size'] = (int) ($fontAttributes['Unit']); $styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? true : false; $styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? true : false; - $styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? true : false; + $styleArray['font']['strikethrough'] = ($fontAttributes['StrikeThrough'] == '1') ? true : false; switch ($fontAttributes['Underline']) { case '1': - $styleArray['font']['underline'] = \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE; + $styleArray['font']['underline'] = Font::UNDERLINE_SINGLE; break; case '2': - $styleArray['font']['underline'] = \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE; + $styleArray['font']['underline'] = Font::UNDERLINE_DOUBLE; break; case '3': - $styleArray['font']['underline'] = \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLEACCOUNTING; + $styleArray['font']['underline'] = Font::UNDERLINE_SINGLEACCOUNTING; break; case '4': - $styleArray['font']['underline'] = \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLEACCOUNTING; + $styleArray['font']['underline'] = Font::UNDERLINE_DOUBLEACCOUNTING; break; default: - $styleArray['font']['underline'] = \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE; + $styleArray['font']['underline'] = Font::UNDERLINE_NONE; break; } switch ($fontAttributes['Script']) { case '1': - $styleArray['font']['superScript'] = true; + $styleArray['font']['superscript'] = true; break; case '-1': - $styleArray['font']['subScript'] = true; + $styleArray['font']['subscript'] = true; break; } @@ -637,13 +649,13 @@ class Gnumeric extends BaseReader implements IReader } if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}))) { $styleArray['borders']['diagonal'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes()); - $styleArray['borders']['diagonaldirection'] = \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH; + $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_BOTH; } elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) { $styleArray['borders']['diagonal'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes()); - $styleArray['borders']['diagonaldirection'] = \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_UP; + $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_UP; } elseif (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'})) { $styleArray['borders']['diagonal'] = self::parseBorderAttributes($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}->attributes()); - $styleArray['borders']['diagonaldirection'] = \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_DOWN; + $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_DOWN; } } if (isset($styleRegion->Style->HyperLink)) { @@ -668,19 +680,19 @@ class Gnumeric extends BaseReader implements IReader $hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false; $columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1; while ($c < $column) { - $spreadsheet->getActiveSheet()->getColumnDimension(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); + $spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); ++$c; } while (($c < ($column + $columnCount)) && ($c <= $maxCol)) { - $spreadsheet->getActiveSheet()->getColumnDimension(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setWidth($columnWidth); + $spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setWidth($columnWidth); if ($hidden) { - $spreadsheet->getActiveSheet()->getColumnDimension(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setVisible(false); + $spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setVisible(false); } ++$c; } } while ($c <= $maxCol) { - $spreadsheet->getActiveSheet()->getColumnDimension(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); + $spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); ++$c; } } @@ -740,7 +752,7 @@ class Gnumeric extends BaseReader implements IReader $range[0] = trim($range[0], "'"); if ($worksheet = $spreadsheet->getSheetByName($range[0])) { $extractedRange = str_replace('$', '', $range[1]); - $spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange($name, $worksheet, $extractedRange)); + $spreadsheet->addNamedRange(new NamedRange($name, $worksheet, $extractedRange)); } } } @@ -758,46 +770,46 @@ class Gnumeric extends BaseReader implements IReader switch ($borderAttributes['Style']) { case '0': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE; + $styleArray['borderStyle'] = Border::BORDER_NONE; break; case '1': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleArray['borderStyle'] = Border::BORDER_THIN; break; case '2': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM; + $styleArray['borderStyle'] = Border::BORDER_MEDIUM; break; case '3': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT; + $styleArray['borderStyle'] = Border::BORDER_SLANTDASHDOT; break; case '4': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED; + $styleArray['borderStyle'] = Border::BORDER_DASHED; break; case '5': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK; + $styleArray['borderStyle'] = Border::BORDER_THICK; break; case '6': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE; + $styleArray['borderStyle'] = Border::BORDER_DOUBLE; break; case '7': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED; + $styleArray['borderStyle'] = Border::BORDER_DOTTED; break; case '8': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED; + $styleArray['borderStyle'] = Border::BORDER_MEDIUMDASHED; break; case '9': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT; + $styleArray['borderStyle'] = Border::BORDER_DASHDOT; break; case '10': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT; + $styleArray['borderStyle'] = Border::BORDER_MEDIUMDASHDOT; break; case '11': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT; + $styleArray['borderStyle'] = Border::BORDER_DASHDOTDOT; break; case '12': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT; + $styleArray['borderStyle'] = Border::BORDER_MEDIUMDASHDOTDOT; break; case '13': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT; + $styleArray['borderStyle'] = Border::BORDER_MEDIUMDASHDOTDOT; break; } @@ -806,7 +818,7 @@ class Gnumeric extends BaseReader implements IReader private function parseRichText($is) { - $value = new \PhpOffice\PhpSpreadsheet\RichText(); + $value = new RichText(); $value->createText($is); return $value; diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 2f0aa473..6136ad4c 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -6,7 +6,12 @@ use DOMDocument; use DOMElement; use DOMNode; use DOMText; +use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Color; +use PhpOffice\PhpSpreadsheet\Style\Fill; +use PhpOffice\PhpSpreadsheet\Worksheet; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -98,16 +103,16 @@ class Html extends BaseReader implements IReader 'font' => [ 'underline' => true, 'color' => [ - 'argb' => \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLUE, + 'argb' => Color::COLOR_BLUE, ], ], ], // Blue underlined 'hr' => [ 'borders' => [ 'bottom' => [ - 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'borderStyle' => Border::BORDER_THIN, 'color' => [ - \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK, + Color::COLOR_BLACK, ], ], ], @@ -276,12 +281,12 @@ class Html extends BaseReader implements IReader /** * @param DOMNode $element - * @param \PhpOffice\PhpSpreadsheet\Worksheet $sheet + * @param Worksheet $sheet * @param int $row * @param string $column * @param string $cellContent */ - protected function processDomElement(DOMNode $element, \PhpOffice\PhpSpreadsheet\Worksheet $sheet, &$row, &$column, &$cellContent) + protected function processDomElement(DOMNode $element, Worksheet $sheet, &$row, &$column, &$cellContent) { foreach ($element->childNodes as $child) { if ($child instanceof DOMText) { @@ -312,7 +317,7 @@ class Html extends BaseReader implements IReader break; case 'title': $this->processDomElement($child, $sheet, $row, $column, $cellContent); - $sheet->setTitle($cellContent); + $sheet->setTitle($cellContent, true, false); $cellContent = ''; break; case 'span': @@ -437,6 +442,9 @@ class Html extends BaseReader implements IReader case 'td': $this->processDomElement($child, $sheet, $row, $column, $cellContent); + // apply inline style + $this->applyInlineStyle($sheet, $row, $column, $attributeArray); + while (isset($this->rowspan[$column . $row])) { ++$column; } @@ -450,7 +458,7 @@ class Html extends BaseReader implements IReader ++$columnTo; } $range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1); - foreach (\PhpOffice\PhpSpreadsheet\Cell::extractAllCellReferencesInRange($range) as $value) { + foreach (Cell::extractAllCellReferencesInRange($range) as $value) { $this->rowspan[$value] = true; } $sheet->mergeCells($range); @@ -458,7 +466,7 @@ class Html extends BaseReader implements IReader } elseif (isset($attributeArray['rowspan'])) { //create merging rowspan $range = $column . $row . ':' . $column . ($row + $attributeArray['rowspan'] - 1); - foreach (\PhpOffice\PhpSpreadsheet\Cell::extractAllCellReferencesInRange($range) as $value) { + foreach (Cell::extractAllCellReferencesInRange($range) as $value) { $this->rowspan[$value] = true; } $sheet->mergeCells($range); @@ -474,7 +482,7 @@ class Html extends BaseReader implements IReader $sheet->getStyle($column . $row)->applyFromArray( [ 'fill' => [ - 'type' => PHPExcel_Style_Fill::FILL_SOLID, + 'fillType' => Fill::FILL_SOLID, 'color' => ['rgb' => $attributeArray['bgcolor']], ], ] @@ -579,4 +587,56 @@ class Html extends BaseReader implements IReader return $xml; } + + /** + * Apply inline css inline style. + * + * NOTES : + * Currently only intended for td & th element, + * and only takes 'background-color' and 'color'; property with HEX color + * + * TODO : + * - Implement to other propertie, such as border + * + * @param Worksheet $sheet + * @param array $attributeArray + * @param int $row + * @param string $column + */ + private function applyInlineStyle(&$sheet, $row, $column, $attributeArray) + { + if (!isset($attributeArray['style'])) { + return; + } + + $supported_styles = ['background-color', 'color']; + + // add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color + $styles = explode(';', $attributeArray['style']); + foreach ($styles as $st) { + $value = explode(':', $st); + + if (empty(trim($value[0])) || !in_array(trim($value[0]), $supported_styles)) { + continue; + } + + //check if has #, so we can get clean hex + if (substr(trim($value[1]), 0, 1) == '#') { + $style_color = substr(trim($value[1]), 1); + } + + if (empty($style_color)) { + continue; + } + + switch (trim($value[0])) { + case 'background-color': + $sheet->getStyle($column . $row)->applyFromArray(['fill' => ['fillType' => Fill::FILL_SOLID, 'color' => ['rgb' => "{$style_color}"]]]); + break; + case 'color': + $sheet->getStyle($column . $row)->applyFromArray(['font' => ['color' => ['rgb' => "$style_color}"]]]); + break; + } + } + } } diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index 13f48ea4..31ff4aa2 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -5,9 +5,16 @@ namespace PhpOffice\PhpSpreadsheet\Reader; use DateTime; use DateTimeZone; use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Cell\DataType; +use PhpOffice\PhpSpreadsheet\Document\Properties; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Settings; +use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; +use XMLReader; use ZipArchive; /** @@ -76,7 +83,7 @@ class Ods extends BaseReader implements IReader $xml = simplexml_load_string( $this->securityScan($zip->getFromName('META-INF/manifest.xml')), 'SimpleXMLElement', - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $namespacesContent = $xml->getNamespaces(true); if (isset($namespacesContent['manifest'])) { @@ -119,11 +126,11 @@ class Ods extends BaseReader implements IReader $worksheetNames = []; - $xml = new \XMLReader(); + $xml = new XMLReader(); $xml->xml( $this->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'), null, - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $xml->setParserProperty(2, true); @@ -140,12 +147,12 @@ class Ods extends BaseReader implements IReader } // Now read each node until we find our first table:table node while ($xml->read()) { - if ($xml->name == 'table:table' && $xml->nodeType == \XMLReader::ELEMENT) { + if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) { // Loop through each table:table node reading the table:name attribute for each worksheet name do { $worksheetNames[] = $xml->getAttribute('table:name'); $xml->next(); - } while ($xml->name == 'table:table' && $xml->nodeType == \XMLReader::ELEMENT); + } while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT); } } } @@ -173,11 +180,11 @@ class Ods extends BaseReader implements IReader throw new Exception('Could not open ' . $pFilename . ' for reading! Error opening file.'); } - $xml = new \XMLReader(); + $xml = new XMLReader(); $res = $xml->xml( $this->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'), null, - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $xml->setParserProperty(2, true); @@ -194,7 +201,7 @@ class Ods extends BaseReader implements IReader } // Now read each node until we find our first table:table node while ($xml->read()) { - if ($xml->name == 'table:table' && $xml->nodeType == \XMLReader::ELEMENT) { + if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) { $worksheetNames[] = $xml->getAttribute('table:name'); $tmpInfo = [ @@ -209,7 +216,7 @@ class Ods extends BaseReader implements IReader $currCells = 0; do { $xml->read(); - if ($xml->name == 'table:table-row' && $xml->nodeType == \XMLReader::ELEMENT) { + if ($xml->name == 'table:table-row' && $xml->nodeType == XMLReader::ELEMENT) { $rowspan = $xml->getAttribute('table:number-rows-repeated'); $rowspan = empty($rowspan) ? 1 : $rowspan; $tmpInfo['totalRows'] += $rowspan; @@ -218,14 +225,14 @@ class Ods extends BaseReader implements IReader // Step into the row $xml->read(); do { - if ($xml->name == 'table:table-cell' && $xml->nodeType == \XMLReader::ELEMENT) { + if ($xml->name == 'table:table-cell' && $xml->nodeType == XMLReader::ELEMENT) { if (!$xml->isEmptyElement) { ++$currCells; $xml->next(); } else { $xml->read(); } - } elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == \XMLReader::ELEMENT) { + } elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) { $mergeSize = $xml->getAttribute('table:number-columns-repeated'); $currCells += $mergeSize; $xml->read(); @@ -236,7 +243,7 @@ class Ods extends BaseReader implements IReader $tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'], $currCells); $tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1; - $tmpInfo['lastColumnLetter'] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); + $tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $worksheetInfo[] = $tmpInfo; } } @@ -252,12 +259,12 @@ class Ods extends BaseReader implements IReader * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ public function load($pFilename) { // Create new Spreadsheet - $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $spreadsheet = new Spreadsheet(); // Load into this instance return $this->loadIntoExisting($pFilename, $spreadsheet); @@ -281,13 +288,13 @@ class Ods extends BaseReader implements IReader * Loads PhpSpreadsheet from file into PhpSpreadsheet instance. * * @param string $pFilename - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ - public function loadIntoExisting($pFilename, \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) { File::assertFile($pFilename); @@ -306,7 +313,7 @@ class Ods extends BaseReader implements IReader $xml = simplexml_load_string( $this->securityScan($zip->getFromName('meta.xml')), 'SimpleXMLElement', - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $namespacesMeta = $xml->getNamespaces(true); @@ -359,26 +366,26 @@ class Ods extends BaseReader implements IReader $docProps->setCreated($creationDate); break; case 'user-defined': - $propertyValueType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_STRING; + $propertyValueType = Properties::PROPERTY_TYPE_STRING; foreach ($propertyValueAttributes as $key => $value) { if ($key == 'name') { $propertyValueName = (string) $value; } elseif ($key == 'value-type') { switch ($value) { case 'date': - $propertyValue = \PhpOffice\PhpSpreadsheet\Document\Properties::convertProperty($propertyValue, 'date'); - $propertyValueType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE; + $propertyValue = Properties::convertProperty($propertyValue, 'date'); + $propertyValueType = Properties::PROPERTY_TYPE_DATE; break; case 'boolean': - $propertyValue = \PhpOffice\PhpSpreadsheet\Document\Properties::convertProperty($propertyValue, 'bool'); - $propertyValueType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN; + $propertyValue = Properties::convertProperty($propertyValue, 'bool'); + $propertyValueType = Properties::PROPERTY_TYPE_BOOLEAN; break; case 'float': - $propertyValue = \PhpOffice\PhpSpreadsheet\Document\Properties::convertProperty($propertyValue, 'r4'); - $propertyValueType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_FLOAT; + $propertyValue = Properties::convertProperty($propertyValue, 'r4'); + $propertyValueType = Properties::PROPERTY_TYPE_FLOAT; break; default: - $propertyValueType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_STRING; + $propertyValueType = Properties::PROPERTY_TYPE_STRING; } } } @@ -395,7 +402,7 @@ class Ods extends BaseReader implements IReader $dom = new \DOMDocument('1.01', 'UTF-8'); $dom->loadXML( $this->securityScan($zip->getFromName('content.xml')), - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $officeNs = $dom->lookupNamespaceUri('office'); @@ -433,7 +440,7 @@ class Ods extends BaseReader implements IReader // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in // formula cells... during the load, all formulae should be correct, and we're simply // bringing the worksheet name in line with the formula, not the reverse - $spreadsheet->getActiveSheet()->setTitle($worksheetName, false); + $spreadsheet->getActiveSheet()->setTitle($worksheetName, false, false); } // Go through every child of table element @@ -563,7 +570,7 @@ class Ods extends BaseReader implements IReader if (floor($dataValue) == $dataValue) { $dataValue = (int) $dataValue; } - $formatting = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00; + $formatting = NumberFormat::FORMAT_PERCENTAGE_00; break; case 'currency': $type = DataType::TYPE_NUMERIC; @@ -572,7 +579,7 @@ class Ods extends BaseReader implements IReader if (floor($dataValue) == $dataValue) { $dataValue = (int) $dataValue; } - $formatting = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; + $formatting = NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; break; case 'float': $type = DataType::TYPE_NUMERIC; @@ -597,7 +604,7 @@ class Ods extends BaseReader implements IReader $dateObj->format('Y m d H i s') ); - $dataValue = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( + $dataValue = Date::formattedPHPToExcel( $year, $month, $day, @@ -607,11 +614,11 @@ class Ods extends BaseReader implements IReader ); if ($dataValue != floor($dataValue)) { - $formatting = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX15 + $formatting = NumberFormat::FORMAT_DATE_XLSX15 . ' ' - . \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4; + . NumberFormat::FORMAT_DATE_TIME4; } else { - $formatting = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX15; + $formatting = NumberFormat::FORMAT_DATE_XLSX15; } break; case 'time': @@ -619,12 +626,12 @@ class Ods extends BaseReader implements IReader $timeValue = $cellData->getAttributeNS($officeNs, 'time-value'); - $dataValue = \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel( + $dataValue = Date::PHPToExcel( strtotime( '01-01-1970 ' . implode(':', sscanf($timeValue, 'PT%dH%dM%dS')) ) ); - $formatting = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4; + $formatting = NumberFormat::FORMAT_DATE_TIME4; break; default: $dataValue = null; @@ -643,16 +650,16 @@ class Ods extends BaseReader implements IReader // Only replace in alternate array entries (i.e. non-quoted blocks) if ($tKey = !$tKey) { // Cell range reference in another sheet - $value = preg_replace('/\[([^\.]+)\.([^\.]+):\.([^\.]+)\]/Ui', '$1!$2:$3', $value); + $value = preg_replace('/\[([^\.]+)\.([^\.]+):\.([^\.]+)\]/U', '$1!$2:$3', $value); // Cell reference in another sheet - $value = preg_replace('/\[([^\.]+)\.([^\.]+)\]/Ui', '$1!$2', $value); + $value = preg_replace('/\[([^\.]+)\.([^\.]+)\]/U', '$1!$2', $value); // Cell range reference - $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/Ui', '$1:$2', $value); + $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/U', '$1:$2', $value); // Simple cell reference - $value = preg_replace('/\[\.([^\.]+)\]/Ui', '$1', $value); + $value = preg_replace('/\[\.([^\.]+)\]/U', '$1', $value); $value = Calculation::translateSeparator(';', ',', $value, $inBraces); } @@ -723,11 +730,11 @@ class Ods extends BaseReader implements IReader $columnTo = $columnID; if ($cellData->hasAttributeNS($tableNs, 'number-columns-spanned')) { - $columnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($columnID); + $columnIndex = Cell::columnIndexFromString($columnID); $columnIndex += (int) $cellData->getAttributeNS($tableNs, 'number-columns-spanned'); $columnIndex -= 2; - $columnTo = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnIndex); + $columnTo = Cell::stringFromColumnIndex($columnIndex); } $rowTo = $rowID; @@ -795,11 +802,11 @@ class Ods extends BaseReader implements IReader /** * @param string $is * - * @return \PhpOffice\PhpSpreadsheet\RichText + * @return RichText */ private function parseRichText($is) { - $value = new \PhpOffice\PhpSpreadsheet\RichText(); + $value = new RichText(); $value->createText($is); return $value; diff --git a/src/PhpSpreadsheet/Reader/Slk.php b/src/PhpSpreadsheet/Reader/Slk.php index dbe2cd0f..6ed4839b 100644 --- a/src/PhpSpreadsheet/Reader/Slk.php +++ b/src/PhpSpreadsheet/Reader/Slk.php @@ -2,6 +2,12 @@ namespace PhpOffice\PhpSpreadsheet\Reader; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Border; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -151,7 +157,7 @@ class Slk extends BaseReader implements IReader $columnIndex = 0; // convert SYLK encoded $rowData to UTF-8 - $rowData = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::SYLKtoUTF8($rowData); + $rowData = StringHelper::SYLKtoUTF8($rowData); // explode each row at semicolons while taking into account that literal semicolon (;) // is escaped like this (;;) @@ -178,7 +184,7 @@ class Slk extends BaseReader implements IReader } } - $worksheetInfo[0]['lastColumnLetter'] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); + $worksheetInfo[0]['lastColumnLetter'] = Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1; // Close file @@ -194,12 +200,12 @@ class Slk extends BaseReader implements IReader * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ public function load($pFilename) { // Create new Spreadsheet - $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $spreadsheet = new Spreadsheet(); // Load into this instance return $this->loadIntoExisting($pFilename, $spreadsheet); @@ -209,13 +215,13 @@ class Slk extends BaseReader implements IReader * Loads PhpSpreadsheet from file into PhpSpreadsheet instance. * * @param string $pFilename - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ - public function loadIntoExisting($pFilename, \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) { // Open file if (!$this->canRead($pFilename)) { @@ -241,7 +247,7 @@ class Slk extends BaseReader implements IReader // loop through one row (line) at a time in the file while (($rowData = fgets($fileHandle)) !== false) { // convert SYLK encoded $rowData to UTF-8 - $rowData = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::SYLKtoUTF8($rowData); + $rowData = StringHelper::SYLKtoUTF8($rowData); // explode each row at semicolons while taking into account that literal semicolon (;) // is escaped like this (;;) @@ -254,7 +260,7 @@ class Slk extends BaseReader implements IReader foreach ($rowData as $rowDatum) { switch ($rowDatum[0]) { case 'P': - $formatArray['numberformat']['code'] = str_replace($fromFormats, $toFormats, substr($rowDatum, 1)); + $formatArray['numberFormat']['formatCode'] = str_replace($fromFormats, $toFormats, substr($rowDatum, 1)); break; case 'E': case 'F': @@ -274,16 +280,16 @@ class Slk extends BaseReader implements IReader $formatArray['font']['bold'] = true; break; case 'T': - $formatArray['borders']['top']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['top']['borderStyle'] = Border::BORDER_THIN; break; case 'B': - $formatArray['borders']['bottom']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['bottom']['borderStyle'] = Border::BORDER_THIN; break; case 'L': - $formatArray['borders']['left']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['left']['borderStyle'] = Border::BORDER_THIN; break; case 'R': - $formatArray['borders']['right']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['right']['borderStyle'] = Border::BORDER_THIN; break; } } @@ -342,7 +348,7 @@ class Slk extends BaseReader implements IReader if ($columnReference[0] == '[') { $columnReference = $column + trim($columnReference, '[]'); } - $A1CellReference = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; + $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); } @@ -355,13 +361,13 @@ class Slk extends BaseReader implements IReader break; } } - $columnLetter = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column - 1); - $cellData = \PhpOffice\PhpSpreadsheet\Calculation::unwrapResult($cellData); + $columnLetter = Cell::stringFromColumnIndex($column - 1); + $cellData = Calculation::unwrapResult($cellData); // Set cell value $spreadsheet->getActiveSheet()->getCell($columnLetter . $row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData); if ($hasCalculatedValue) { - $cellData = \PhpOffice\PhpSpreadsheet\Calculation::unwrapResult($cellData); + $cellData = Calculation::unwrapResult($cellData); $spreadsheet->getActiveSheet()->getCell($columnLetter . $row)->setCalculatedValue($cellData); } // Read cell formatting @@ -395,16 +401,16 @@ class Slk extends BaseReader implements IReader $styleData['font']['bold'] = true; break; case 'T': - $styleData['borders']['top']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['top']['borderStyle'] = Border::BORDER_THIN; break; case 'B': - $styleData['borders']['bottom']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['bottom']['borderStyle'] = Border::BORDER_THIN; break; case 'L': - $styleData['borders']['left']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['left']['borderStyle'] = Border::BORDER_THIN; break; case 'R': - $styleData['borders']['right']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['right']['borderStyle'] = Border::BORDER_THIN; break; } } @@ -412,22 +418,22 @@ class Slk extends BaseReader implements IReader } } if (($formatStyle > '') && ($column > '') && ($row > '')) { - $columnLetter = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column - 1); + $columnLetter = Cell::stringFromColumnIndex($column - 1); if (isset($this->formats[$formatStyle])) { $spreadsheet->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($this->formats[$formatStyle]); } } if ((!empty($styleData)) && ($column > '') && ($row > '')) { - $columnLetter = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column - 1); + $columnLetter = Cell::stringFromColumnIndex($column - 1); $spreadsheet->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($styleData); } if ($columnWidth > '') { if ($startCol == $endCol) { - $startCol = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($startCol - 1); + $startCol = Cell::stringFromColumnIndex($startCol - 1); $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); } else { - $startCol = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($startCol - 1); - $endCol = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($endCol - 1); + $startCol = Cell::stringFromColumnIndex($startCol - 1); + $endCol = Cell::stringFromColumnIndex($endCol - 1); $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); do { $spreadsheet->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth); diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index 801b27d7..8e0f6ae8 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -2,7 +2,31 @@ namespace PhpOffice\PhpSpreadsheet\Reader; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Cell\DataValidation; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\NamedRange; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\CodePage; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Escher; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE; use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Shared\OLE; +use PhpOffice\PhpSpreadsheet\Shared\OLERead; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Borders; +use PhpOffice\PhpSpreadsheet\Style\Font; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; +use PhpOffice\PhpSpreadsheet\Style\Protection; +use PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; +use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; +use PhpOffice\PhpSpreadsheet\Worksheet\SheetView; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -194,7 +218,7 @@ class Xls extends BaseReader implements IReader /** * Workbook to be returned by the reader. * - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $spreadsheet; @@ -426,13 +450,13 @@ class Xls extends BaseReader implements IReader try { // Use ParseXL for the hard work. - $ole = new \PhpOffice\PhpSpreadsheet\Shared\OLERead(); + $ole = new OLERead(); // get excel data $ole->read($pFilename); return true; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { return false; } } @@ -461,7 +485,7 @@ class Xls extends BaseReader implements IReader // Parse Workbook Global Substream while ($this->pos < $this->dataSize) { - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); switch ($code) { case self::XLS_TYPE_BOF: @@ -516,7 +540,7 @@ class Xls extends BaseReader implements IReader // Parse Workbook Global Substream while ($this->pos < $this->dataSize) { - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); switch ($code) { case self::XLS_TYPE_BOF: @@ -553,7 +577,7 @@ class Xls extends BaseReader implements IReader $this->pos = $sheet['offset']; while ($this->pos <= $this->dataSize - 4) { - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); switch ($code) { case self::XLS_TYPE_RK: @@ -562,14 +586,14 @@ class Xls extends BaseReader implements IReader case self::XLS_TYPE_FORMULA: case self::XLS_TYPE_BOOLERR: case self::XLS_TYPE_LABEL: - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; - $rowIndex = self::getInt2d($recordData, 0) + 1; - $columnIndex = self::getInt2d($recordData, 2); + $rowIndex = self::getUInt2d($recordData, 0) + 1; + $columnIndex = self::getUInt2d($recordData, 2); $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex); $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex); @@ -586,7 +610,7 @@ class Xls extends BaseReader implements IReader } } - $tmpInfo['lastColumnLetter'] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); + $tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; $worksheetInfo[] = $tmpInfo; @@ -602,7 +626,7 @@ class Xls extends BaseReader implements IReader * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ public function load($pFilename) { @@ -610,7 +634,7 @@ class Xls extends BaseReader implements IReader $this->loadOLE($pFilename); // Initialisations - $this->spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $this->spreadsheet = new Spreadsheet(); $this->spreadsheet->removeSheetByIndex(0); // remove 1st sheet if (!$this->readDataOnly) { $this->spreadsheet->removeCellStyleXfByIndex(0); // remove the default style @@ -644,7 +668,7 @@ class Xls extends BaseReader implements IReader // Parse Workbook Global Substream while ($this->pos < $this->dataSize) { - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); switch ($code) { case self::XLS_TYPE_BOF: @@ -762,7 +786,7 @@ class Xls extends BaseReader implements IReader // treat MSODRAWINGGROUP records, workbook-level Escher if (!$this->readDataOnly && $this->drawingGroupData) { - $escherWorkbook = new \PhpOffice\PhpSpreadsheet\Shared\Escher(); + $escherWorkbook = new Escher(); $reader = new Xls\Escher($escherWorkbook); $escherWorkbook = $reader->load($this->drawingGroupData); } @@ -784,7 +808,7 @@ class Xls extends BaseReader implements IReader // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula // cells... during the load, all formulae should be correct, and we're simply bringing the worksheet // name in line with the formula, not the reverse - $this->phpSheet->setTitle($sheet['name'], false); + $this->phpSheet->setTitle($sheet['name'], false, false); $this->phpSheet->setSheetState($sheet['sheetState']); $this->pos = $sheet['offset']; @@ -812,7 +836,7 @@ class Xls extends BaseReader implements IReader $this->textObjRef = -1; while ($this->pos <= $this->dataSize - 4) { - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); switch ($code) { case self::XLS_TYPE_BOF: @@ -980,7 +1004,7 @@ class Xls extends BaseReader implements IReader // treat MSODRAWING records, sheet-level Escher if (!$this->readDataOnly && $this->drawingData) { - $escherWorksheet = new \PhpOffice\PhpSpreadsheet\Shared\Escher(); + $escherWorksheet = new Escher(); $reader = new Xls\Escher($escherWorksheet); $escherWorksheet = $reader->load($this->drawingData); @@ -1000,8 +1024,8 @@ class Xls extends BaseReader implements IReader } // calculate the width and height of the shape - list($startColumn, $startRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($spContainer->getStartCoordinates()); - list($endColumn, $endRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($spContainer->getEndCoordinates()); + list($startColumn, $startRow) = Cell::coordinateFromString($spContainer->getStartCoordinates()); + list($endColumn, $endRow) = Cell::coordinateFromString($spContainer->getEndCoordinates()); $startOffsetX = $spContainer->getStartOffsetX(); $startOffsetY = $spContainer->getStartOffsetY(); @@ -1047,7 +1071,7 @@ class Xls extends BaseReader implements IReader // need check because some blip types are not supported by Escher reader such as EMF if ($blip = $BSE->getBlip()) { $ih = imagecreatefromstring($blip->getData()); - $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing(); + $drawing = new MemoryDrawing(); $drawing->setImageResource($ih); // width, height, offsetX, offsetY @@ -1058,13 +1082,13 @@ class Xls extends BaseReader implements IReader $drawing->setOffsetY($offsetY); switch ($blipType) { - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_JPEG: - $drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG); - $drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_JPEG); + case BSE::BLIPTYPE_JPEG: + $drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG); + $drawing->setMimeType(MemoryDrawing::MIMETYPE_JPEG); break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_PNG: - $drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_PNG); - $drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_PNG); + case BSE::BLIPTYPE_PNG: + $drawing->setRenderingFunction(MemoryDrawing::RENDERING_PNG); + $drawing->setMimeType(MemoryDrawing::MIMETYPE_PNG); break; } @@ -1082,10 +1106,10 @@ class Xls extends BaseReader implements IReader // treat SHAREDFMLA records if ($this->version == self::XLS_BIFF8) { foreach ($this->sharedFormulaParts as $cell => $baseCell) { - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($cell); + list($column, $row) = Cell::coordinateFromString($cell); if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($column, $row, $this->phpSheet->getTitle())) { $formula = $this->getFormulaFromStructure($this->sharedFormulas[$baseCell], $cell); - $this->phpSheet->getCell($cell)->setValueExplicit('=' . $formula, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA); + $this->phpSheet->getCell($cell)->setValueExplicit('=' . $formula, Cell\DataType::TYPE_FORMULA); } } } @@ -1157,8 +1181,8 @@ class Xls extends BaseReader implements IReader $coordinateStrings = explode(':', $extractedRange); if (count($coordinateStrings) == 2) { - list($firstColumn, $firstRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($coordinateStrings[0]); - list($lastColumn, $lastRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($coordinateStrings[1]); + list($firstColumn, $firstRow) = Cell::coordinateFromString($coordinateStrings[0]); + list($lastColumn, $lastRow) = Cell::coordinateFromString($coordinateStrings[1]); if ($firstColumn == 'A' and $lastColumn == 'IV') { // then we have repeating rows @@ -1187,7 +1211,7 @@ class Xls extends BaseReader implements IReader $scope = ($definedName['scope'] == 0) ? null : $this->spreadsheet->getSheetByName($this->sheets[$definedName['scope'] - 1]['name']); - $this->spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange((string) $definedName['name'], $docSheet, $extractedRange, $localOnly, $scope)); + $this->spreadsheet->addNamedRange(new NamedRange((string) $definedName['name'], $docSheet, $extractedRange, $localOnly, $scope)); } } // Named Value @@ -1263,7 +1287,7 @@ class Xls extends BaseReader implements IReader private function loadOLE($pFilename) { // OLE reader - $ole = new \PhpOffice\PhpSpreadsheet\Shared\OLERead(); + $ole = new OLERead(); // get excel data, $ole->read($pFilename); // Get workbook data: workbook stream + sheet streams @@ -1323,7 +1347,7 @@ class Xls extends BaseReader implements IReader // extract property value based on property type switch ($type) { case 0x02: // 2 byte signed integer - $value = self::getInt2d($this->summaryInformation, $secOffset + 4 + $offset); + $value = self::getUInt2d($this->summaryInformation, $secOffset + 4 + $offset); break; case 0x03: // 4 byte signed integer $value = self::getInt4d($this->summaryInformation, $secOffset + 4 + $offset); @@ -1334,12 +1358,12 @@ class Xls extends BaseReader implements IReader case 0x1E: // null-terminated string prepended by dword string length $byteLength = self::getInt4d($this->summaryInformation, $secOffset + 4 + $offset); $value = substr($this->summaryInformation, $secOffset + 8 + $offset, $byteLength); - $value = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($value, 'UTF-8', $codePage); + $value = StringHelper::convertEncoding($value, 'UTF-8', $codePage); $value = rtrim($value); break; case 0x40: // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) // PHP-time - $value = \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE2LocalDate(substr($this->summaryInformation, $secOffset + 4 + $offset, 8)); + $value = OLE::OLE2LocalDate(substr($this->summaryInformation, $secOffset + 4 + $offset, 8)); break; case 0x47: // Clipboard format // not needed yet, fix later if necessary @@ -1348,7 +1372,7 @@ class Xls extends BaseReader implements IReader switch ($id) { case 0x01: // Code Page - $codePage = \PhpOffice\PhpSpreadsheet\Shared\CodePage::numberToName($value); + $codePage = CodePage::numberToName($value); break; case 0x02: // Title $this->spreadsheet->getProperties()->setTitle($value); @@ -1457,13 +1481,13 @@ class Xls extends BaseReader implements IReader // extract property value based on property type switch ($type) { case 0x02: // 2 byte signed integer - $value = self::getInt2d($this->documentSummaryInformation, $secOffset + 4 + $offset); + $value = self::getUInt2d($this->documentSummaryInformation, $secOffset + 4 + $offset); break; case 0x03: // 4 byte signed integer $value = self::getInt4d($this->documentSummaryInformation, $secOffset + 4 + $offset); break; case 0x0B: // Boolean - $value = self::getInt2d($this->documentSummaryInformation, $secOffset + 4 + $offset); + $value = self::getUInt2d($this->documentSummaryInformation, $secOffset + 4 + $offset); $value = ($value == 0 ? false : true); break; case 0x13: // 4 byte unsigned integer @@ -1472,12 +1496,12 @@ class Xls extends BaseReader implements IReader case 0x1E: // null-terminated string prepended by dword string length $byteLength = self::getInt4d($this->documentSummaryInformation, $secOffset + 4 + $offset); $value = substr($this->documentSummaryInformation, $secOffset + 8 + $offset, $byteLength); - $value = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($value, 'UTF-8', $codePage); + $value = StringHelper::convertEncoding($value, 'UTF-8', $codePage); $value = rtrim($value); break; case 0x40: // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) // PHP-Time - $value = \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE2LocalDate(substr($this->documentSummaryInformation, $secOffset + 4 + $offset, 8)); + $value = OLE::OLE2LocalDate(substr($this->documentSummaryInformation, $secOffset + 4 + $offset, 8)); break; case 0x47: // Clipboard format // not needed yet, fix later if necessary @@ -1486,7 +1510,7 @@ class Xls extends BaseReader implements IReader switch ($id) { case 0x01: // Code Page - $codePage = \PhpOffice\PhpSpreadsheet\Shared\CodePage::numberToName($value); + $codePage = CodePage::numberToName($value); break; case 0x02: // Category $this->spreadsheet->getProperties()->setCategory($value); @@ -1542,7 +1566,7 @@ class Xls extends BaseReader implements IReader */ private function readDefault() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); // move stream pointer to next record $this->pos += 4 + $length; @@ -1554,7 +1578,7 @@ class Xls extends BaseReader implements IReader */ private function readNote() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -1566,7 +1590,7 @@ class Xls extends BaseReader implements IReader $cellAddress = $this->readBIFF8CellAddress(substr($recordData, 0, 4)); if ($this->version == self::XLS_BIFF8) { - $noteObjID = self::getInt2d($recordData, 6); + $noteObjID = self::getUInt2d($recordData, 6); $noteAuthor = self::readUnicodeStringLong(substr($recordData, 8)); $noteAuthor = $noteAuthor['value']; $this->cellNotes[$noteObjID] = [ @@ -1580,13 +1604,13 @@ class Xls extends BaseReader implements IReader // If the address row is -1 and the column is 0, (which translates as $B$65536) then this is a continuation // note from the previous cell annotation. We're not yet handling this, so annotations longer than the // max 2048 bytes will probably throw a wobbly. - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); $extension = true; $cellAddress = array_pop(array_keys($this->phpSheet->getComments())); } $cellAddress = str_replace('$', '', $cellAddress); - $noteLength = self::getInt2d($recordData, 4); + $noteLength = self::getUInt2d($recordData, 4); $noteText = trim(substr($recordData, 6)); if ($extension) { @@ -1607,7 +1631,7 @@ class Xls extends BaseReader implements IReader */ private function readTextObject() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -1623,10 +1647,10 @@ class Xls extends BaseReader implements IReader // cchText: 2 bytes; length of the text (in the first continue record) // cbRuns: 2 bytes; length of the formatting (in the second continue record) // followed by the continuation records containing the actual text and formatting - $grbitOpts = self::getInt2d($recordData, 0); - $rot = self::getInt2d($recordData, 2); - $cchText = self::getInt2d($recordData, 10); - $cbRuns = self::getInt2d($recordData, 12); + $grbitOpts = self::getUInt2d($recordData, 0); + $rot = self::getUInt2d($recordData, 2); + $cchText = self::getUInt2d($recordData, 10); + $cbRuns = self::getUInt2d($recordData, 12); $text = $this->getSplicedRecordData(); $textByte = $text['spliceOffsets'][1] - $text['spliceOffsets'][0] - 1; @@ -1636,7 +1660,7 @@ class Xls extends BaseReader implements IReader // it is possible to use a compressed format, // which omits the high bytes of all characters, if they are all zero if (($is16Bit & 0x01) === 0) { - $textStr = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::ConvertEncoding($textStr, 'UTF-8', 'ISO-8859-1'); + $textStr = StringHelper::ConvertEncoding($textStr, 'UTF-8', 'ISO-8859-1'); } else { $textStr = $this->decodeCodepage($textStr); } @@ -1654,18 +1678,18 @@ class Xls extends BaseReader implements IReader */ private function readBof() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = substr($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 2; size: 2; type of the following data - $substreamType = self::getInt2d($recordData, 2); + $substreamType = self::getUInt2d($recordData, 2); switch ($substreamType) { case self::XLS_WORKBOOKGLOBALS: - $version = self::getInt2d($recordData, 0); + $version = self::getUInt2d($recordData, 0); if (($version != self::XLS_BIFF8) && ($version != self::XLS_BIFF7)) { throw new Exception('Cannot read this Excel file. Version is too old.'); } @@ -1679,7 +1703,7 @@ class Xls extends BaseReader implements IReader // substream, e.g. chart // just skip the entire substream do { - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); $this->readDefault(); } while ($code != self::XLS_TYPE_EOF && $this->pos < $this->dataSize); break; @@ -1703,7 +1727,7 @@ class Xls extends BaseReader implements IReader */ private function readFilepass() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); if ($length != 54) { throw new Exception('Unexpected file pass record length'); @@ -1721,7 +1745,7 @@ class Xls extends BaseReader implements IReader $this->encryption = self::MS_BIFF_CRYPTO_RC4; // Decryption required from the record after next onwards - $this->encryptionStartPos = $this->pos + self::getInt2d($this->data, $this->pos + 2); + $this->encryptionStartPos = $this->pos + self::getUInt2d($this->data, $this->pos + 2); } /** @@ -1852,16 +1876,16 @@ class Xls extends BaseReader implements IReader */ private function readCodepage() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; code page identifier - $codepage = self::getInt2d($recordData, 0); + $codepage = self::getUInt2d($recordData, 0); - $this->codepage = \PhpOffice\PhpSpreadsheet\Shared\CodePage::numberToName($codepage); + $this->codepage = CodePage::numberToName($codepage); } /** @@ -1878,16 +1902,16 @@ class Xls extends BaseReader implements IReader */ private function readDateMode() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; 0 = base 1900, 1 = base 1904 - \PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar(\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900); + Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); if (ord($recordData[0]) == 1) { - \PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar(\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904); + Date::setExcelCalendar(Date::CALENDAR_MAC_1904); } } @@ -1896,40 +1920,40 @@ class Xls extends BaseReader implements IReader */ private function readFont() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; if (!$this->readDataOnly) { - $objFont = new \PhpOffice\PhpSpreadsheet\Style\Font(); + $objFont = new Font(); // offset: 0; size: 2; height of the font (in twips = 1/20 of a point) - $size = self::getInt2d($recordData, 0); + $size = self::getUInt2d($recordData, 0); $objFont->setSize($size / 20); // offset: 2; size: 2; option flags // bit: 0; mask 0x0001; bold (redundant in BIFF5-BIFF8) // bit: 1; mask 0x0002; italic - $isItalic = (0x0002 & self::getInt2d($recordData, 2)) >> 1; + $isItalic = (0x0002 & self::getUInt2d($recordData, 2)) >> 1; if ($isItalic) { $objFont->setItalic(true); } // bit: 2; mask 0x0004; underlined (redundant in BIFF5-BIFF8) - // bit: 3; mask 0x0008; strike - $isStrike = (0x0008 & self::getInt2d($recordData, 2)) >> 3; + // bit: 3; mask 0x0008; strikethrough + $isStrike = (0x0008 & self::getUInt2d($recordData, 2)) >> 3; if ($isStrike) { $objFont->setStrikethrough(true); } // offset: 4; size: 2; colour index - $colorIndex = self::getInt2d($recordData, 4); + $colorIndex = self::getUInt2d($recordData, 4); $objFont->colorIndex = $colorIndex; // offset: 6; size: 2; font weight - $weight = self::getInt2d($recordData, 6); + $weight = self::getUInt2d($recordData, 6); switch ($weight) { case 0x02BC: $objFont->setBold(true); @@ -1937,13 +1961,13 @@ class Xls extends BaseReader implements IReader } // offset: 8; size: 2; escapement type - $escapement = self::getInt2d($recordData, 8); + $escapement = self::getUInt2d($recordData, 8); switch ($escapement) { case 0x0001: - $objFont->setSuperScript(true); + $objFont->setSuperscript(true); break; case 0x0002: - $objFont->setSubScript(true); + $objFont->setSubscript(true); break; } @@ -1953,16 +1977,16 @@ class Xls extends BaseReader implements IReader case 0x00: break; // no underline case 0x01: - $objFont->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); + $objFont->setUnderline(Font::UNDERLINE_SINGLE); break; case 0x02: - $objFont->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE); + $objFont->setUnderline(Font::UNDERLINE_DOUBLE); break; case 0x21: - $objFont->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLEACCOUNTING); + $objFont->setUnderline(Font::UNDERLINE_SINGLEACCOUNTING); break; case 0x22: - $objFont->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLEACCOUNTING); + $objFont->setUnderline(Font::UNDERLINE_DOUBLEACCOUNTING); break; } @@ -1997,14 +2021,14 @@ class Xls extends BaseReader implements IReader */ private function readFormat() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; if (!$this->readDataOnly) { - $indexCode = self::getInt2d($recordData, 0); + $indexCode = self::getUInt2d($recordData, 0); if ($this->version == self::XLS_BIFF8) { $string = self::readUnicodeStringLong(substr($recordData, 2)); @@ -2034,49 +2058,49 @@ class Xls extends BaseReader implements IReader */ private function readXf() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; - $objStyle = new \PhpOffice\PhpSpreadsheet\Style(); + $objStyle = new Style(); if (!$this->readDataOnly) { // offset: 0; size: 2; Index to FONT record - if (self::getInt2d($recordData, 0) < 4) { - $fontIndex = self::getInt2d($recordData, 0); + if (self::getUInt2d($recordData, 0) < 4) { + $fontIndex = self::getUInt2d($recordData, 0); } else { // this has to do with that index 4 is omitted in all BIFF versions for some strange reason // check the OpenOffice documentation of the FONT record - $fontIndex = self::getInt2d($recordData, 0) - 1; + $fontIndex = self::getUInt2d($recordData, 0) - 1; } $objStyle->setFont($this->objFonts[$fontIndex]); // offset: 2; size: 2; Index to FORMAT record - $numberFormatIndex = self::getInt2d($recordData, 2); + $numberFormatIndex = self::getUInt2d($recordData, 2); if (isset($this->formats[$numberFormatIndex])) { // then we have user-defined format code - $numberformat = ['code' => $this->formats[$numberFormatIndex]]; - } elseif (($code = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') { + $numberFormat = ['formatCode' => $this->formats[$numberFormatIndex]]; + } elseif (($code = NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') { // then we have built-in format code - $numberformat = ['code' => $code]; + $numberFormat = ['formatCode' => $code]; } else { // we set the general format code - $numberformat = ['code' => 'General']; + $numberFormat = ['formatCode' => 'General']; } - $objStyle->getNumberFormat()->setFormatCode($numberformat['code']); + $objStyle->getNumberFormat()->setFormatCode($numberFormat['formatCode']); // offset: 4; size: 2; XF type, cell protection, and parent style XF // bit 2-0; mask 0x0007; XF_TYPE_PROT - $xfTypeProt = self::getInt2d($recordData, 4); + $xfTypeProt = self::getUInt2d($recordData, 4); // bit 0; mask 0x01; 1 = cell is locked $isLocked = (0x01 & $xfTypeProt) >> 0; - $objStyle->getProtection()->setLocked($isLocked ? \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT : \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED); + $objStyle->getProtection()->setLocked($isLocked ? Protection::PROTECTION_INHERIT : Protection::PROTECTION_UNPROTECTED); // bit 1; mask 0x02; 1 = Formula is hidden $isHidden = (0x02 & $xfTypeProt) >> 1; - $objStyle->getProtection()->setHidden($isHidden ? \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED : \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED); + $objStyle->getProtection()->setHidden($isHidden ? Protection::PROTECTION_PROTECTED : Protection::PROTECTION_UNPROTECTED); // bit 2; mask 0x04; 0 = Cell XF, 1 = Cell Style XF $isCellStyleXf = (0x04 & $xfTypeProt) >> 2; @@ -2086,25 +2110,25 @@ class Xls extends BaseReader implements IReader $horAlign = (0x07 & ord($recordData[6])) >> 0; switch ($horAlign) { case 0: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_GENERAL); break; case 1: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT); break; case 2: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); break; case 3: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT); break; case 4: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_FILL); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_FILL); break; case 5: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_JUSTIFY); break; case 6: - $objStyle->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS); + $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER_CONTINUOUS); break; } // bit 3, mask 0x08; wrap text @@ -2121,16 +2145,16 @@ class Xls extends BaseReader implements IReader $vertAlign = (0x70 & ord($recordData[6])) >> 4; switch ($vertAlign) { case 0: - $objStyle->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP); + $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_TOP); break; case 1: - $objStyle->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); + $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); break; case 2: - $objStyle->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM); + $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_BOTTOM); break; case 3: - $objStyle->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY); + $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_JUSTIFY); break; } @@ -2195,13 +2219,13 @@ class Xls extends BaseReader implements IReader $diagonalUp = (0x80000000 & self::getInt4d($recordData, 10)) >> 31 ? true : false; if ($diagonalUp == false && $diagonalDown == false) { - $objStyle->getBorders()->setDiagonalDirection(\PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_NONE); + $objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_NONE); } elseif ($diagonalUp == true && $diagonalDown == false) { - $objStyle->getBorders()->setDiagonalDirection(\PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_UP); + $objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_UP); } elseif ($diagonalUp == false && $diagonalDown == true) { - $objStyle->getBorders()->setDiagonalDirection(\PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_DOWN); + $objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_DOWN); } elseif ($diagonalUp == true && $diagonalDown == true) { - $objStyle->getBorders()->setDiagonalDirection(\PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH); + $objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_BOTH); } // offset: 14; size: 4; @@ -2225,10 +2249,10 @@ class Xls extends BaseReader implements IReader } // offset: 18; size: 2; pattern and background colour // bit: 6-0; mask: 0x007F; color index for pattern color - $objStyle->getFill()->startcolorIndex = (0x007F & self::getInt2d($recordData, 18)) >> 0; + $objStyle->getFill()->startcolorIndex = (0x007F & self::getUInt2d($recordData, 18)) >> 0; // bit: 13-7; mask: 0x3F80; color index for pattern background - $objStyle->getFill()->endcolorIndex = (0x3F80 & self::getInt2d($recordData, 18)) >> 7; + $objStyle->getFill()->endcolorIndex = (0x3F80 & self::getUInt2d($recordData, 18)) >> 7; } else { // BIFF5 @@ -2312,7 +2336,7 @@ class Xls extends BaseReader implements IReader private function readXfExt() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2328,28 +2352,28 @@ class Xls extends BaseReader implements IReader // offset: 12; size: 2; record version // offset: 14; size: 2; index to XF record which this record modifies - $ixfe = self::getInt2d($recordData, 14); + $ixfe = self::getUInt2d($recordData, 14); // offset: 16; size: 2; not used // offset: 18; size: 2; number of extension properties that follow - $cexts = self::getInt2d($recordData, 18); + $cexts = self::getUInt2d($recordData, 18); // start reading the actual extension data $offset = 20; while ($offset < $length) { // extension type - $extType = self::getInt2d($recordData, $offset); + $extType = self::getUInt2d($recordData, $offset); // extension length - $cb = self::getInt2d($recordData, $offset + 2); + $cb = self::getUInt2d($recordData, $offset + 2); // extension data $extData = substr($recordData, $offset + 4, $cb); switch ($extType) { case 4: // fill start color - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2364,7 +2388,7 @@ class Xls extends BaseReader implements IReader } break; case 5: // fill end color - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2379,7 +2403,7 @@ class Xls extends BaseReader implements IReader } break; case 7: // border color top - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2394,7 +2418,7 @@ class Xls extends BaseReader implements IReader } break; case 8: // border color bottom - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2409,7 +2433,7 @@ class Xls extends BaseReader implements IReader } break; case 9: // border color left - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2424,7 +2448,7 @@ class Xls extends BaseReader implements IReader } break; case 10: // border color right - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2439,7 +2463,7 @@ class Xls extends BaseReader implements IReader } break; case 11: // border color diagonal - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2454,7 +2478,7 @@ class Xls extends BaseReader implements IReader } break; case 13: // font color - $xclfType = self::getInt2d($extData, 0); // color type + $xclfType = self::getUInt2d($extData, 0); // color type $xclrValue = substr($extData, 4, 4); // color value (value based on color type) if ($xclfType == 2) { @@ -2480,7 +2504,7 @@ class Xls extends BaseReader implements IReader */ private function readStyle() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2488,7 +2512,7 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; index to XF record and flag for built-in style - $ixfe = self::getInt2d($recordData, 0); + $ixfe = self::getUInt2d($recordData, 0); // bit: 11-0; mask 0x0FFF; index to XF record $xfIndex = (0x0FFF & $ixfe) >> 0; @@ -2517,7 +2541,7 @@ class Xls extends BaseReader implements IReader */ private function readPalette() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2525,7 +2549,7 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; number of following colors - $nm = self::getInt2d($recordData, 0); + $nm = self::getUInt2d($recordData, 0); // list of RGB colors for ($i = 0; $i < $nm; ++$i) { @@ -2549,7 +2573,7 @@ class Xls extends BaseReader implements IReader */ private function readSheet() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // offset: 0; size: 4; absolute stream position of the BOF record of the sheet @@ -2562,16 +2586,16 @@ class Xls extends BaseReader implements IReader // offset: 4; size: 1; sheet state switch (ord($recordData[4])) { case 0x00: - $sheetState = \PhpOffice\PhpSpreadsheet\Worksheet::SHEETSTATE_VISIBLE; + $sheetState = Worksheet::SHEETSTATE_VISIBLE; break; case 0x01: - $sheetState = \PhpOffice\PhpSpreadsheet\Worksheet::SHEETSTATE_HIDDEN; + $sheetState = Worksheet::SHEETSTATE_HIDDEN; break; case 0x02: - $sheetState = \PhpOffice\PhpSpreadsheet\Worksheet::SHEETSTATE_VERYHIDDEN; + $sheetState = Worksheet::SHEETSTATE_VERYHIDDEN; break; default: - $sheetState = \PhpOffice\PhpSpreadsheet\Worksheet::SHEETSTATE_VISIBLE; + $sheetState = Worksheet::SHEETSTATE_VISIBLE; break; } @@ -2600,7 +2624,7 @@ class Xls extends BaseReader implements IReader */ private function readExternalBook() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2613,7 +2637,7 @@ class Xls extends BaseReader implements IReader if (strlen($recordData) > 4) { // external reference // offset: 0; size: 2; number of sheet names ($nm) - $nm = self::getInt2d($recordData, 0); + $nm = self::getUInt2d($recordData, 0); $offset += 2; // offset: 2; size: var; encoded URL without sheet name (Unicode string, 16-bit length) @@ -2662,7 +2686,7 @@ class Xls extends BaseReader implements IReader */ private function readExternName() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2671,7 +2695,7 @@ class Xls extends BaseReader implements IReader // external sheet references provided for named cells if ($this->version == self::XLS_BIFF8) { // offset: 0; size: 2; options - $options = self::getInt2d($recordData, 0); + $options = self::getUInt2d($recordData, 0); // offset: 2; size: 2; @@ -2696,7 +2720,7 @@ class Xls extends BaseReader implements IReader */ private function readExternSheet() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2705,15 +2729,15 @@ class Xls extends BaseReader implements IReader // external sheet references provided for named cells if ($this->version == self::XLS_BIFF8) { // offset: 0; size: 2; number of following ref structures - $nm = self::getInt2d($recordData, 0); + $nm = self::getUInt2d($recordData, 0); for ($i = 0; $i < $nm; ++$i) { $this->ref[] = [ // offset: 2 + 6 * $i; index to EXTERNALBOOK record - 'externalBookIndex' => self::getInt2d($recordData, 2 + 6 * $i), + 'externalBookIndex' => self::getUInt2d($recordData, 2 + 6 * $i), // offset: 4 + 6 * $i; index to first sheet in EXTERNALBOOK record - 'firstSheetIndex' => self::getInt2d($recordData, 4 + 6 * $i), + 'firstSheetIndex' => self::getUInt2d($recordData, 4 + 6 * $i), // offset: 6 + 6 * $i; index to last sheet in EXTERNALBOOK record - 'lastSheetIndex' => self::getInt2d($recordData, 6 + 6 * $i), + 'lastSheetIndex' => self::getUInt2d($recordData, 6 + 6 * $i), ]; } } @@ -2732,7 +2756,7 @@ class Xls extends BaseReader implements IReader */ private function readDefinedName() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2742,7 +2766,7 @@ class Xls extends BaseReader implements IReader // retrieves named cells // offset: 0; size: 2; option flags - $opts = self::getInt2d($recordData, 0); + $opts = self::getUInt2d($recordData, 0); // bit: 5; mask: 0x0020; 0 = user-defined name, 1 = built-in-name $isBuiltInName = (0x0020 & $opts) >> 5; @@ -2754,10 +2778,10 @@ class Xls extends BaseReader implements IReader // offset: 4; size: 2; size of the formula data (it can happen that this is zero) // note: there can also be additional data, this is not included in $flen - $flen = self::getInt2d($recordData, 4); + $flen = self::getUInt2d($recordData, 4); // offset: 8; size: 2; 0=Global name, otherwise index to sheet (1-based) - $scope = self::getInt2d($recordData, 8); + $scope = self::getUInt2d($recordData, 8); // offset: 14; size: var; Name (Unicode string without length field) $string = self::readUnicodeString(substr($recordData, 14), $nlen); @@ -2768,7 +2792,7 @@ class Xls extends BaseReader implements IReader try { $formula = $this->getFormulaFromStructure($formulaStructure); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { $formula = ''; } @@ -2786,7 +2810,7 @@ class Xls extends BaseReader implements IReader */ private function readMsoDrawingGroup() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); // get spliced record data $splicedRecordData = $this->getSplicedRecordData(); @@ -2827,7 +2851,7 @@ class Xls extends BaseReader implements IReader // loop through the Unicode strings (16-bit length) for ($i = 0; $i < $nm; ++$i) { // number of characters in the Unicode string - $numChars = self::getInt2d($recordData, $pos); + $numChars = self::getUInt2d($recordData, $pos); $pos += 2; // option flags @@ -2845,7 +2869,7 @@ class Xls extends BaseReader implements IReader if ($hasRichText) { // number of Rich-Text formatting runs - $formattingRuns = self::getInt2d($recordData, $pos); + $formattingRuns = self::getUInt2d($recordData, $pos); $pos += 2; } @@ -2952,10 +2976,10 @@ class Xls extends BaseReader implements IReader // list of formatting runs for ($j = 0; $j < $formattingRuns; ++$j) { // first formatted character; zero-based - $charPos = self::getInt2d($recordData, $pos + $j * 4); + $charPos = self::getUInt2d($recordData, $pos + $j * 4); // index to font record - $fontIndex = self::getInt2d($recordData, $pos + 2 + $j * 4); + $fontIndex = self::getUInt2d($recordData, $pos + 2 + $j * 4); $fmtRuns[] = [ 'charPos' => $charPos, @@ -2986,7 +3010,7 @@ class Xls extends BaseReader implements IReader */ private function readPrintGridlines() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -2994,7 +3018,7 @@ class Xls extends BaseReader implements IReader if ($this->version == self::XLS_BIFF8 && !$this->readDataOnly) { // offset: 0; size: 2; 0 = do not print sheet grid lines; 1 = print sheet gridlines - $printGridlines = (bool) self::getInt2d($recordData, 0); + $printGridlines = (bool) self::getUInt2d($recordData, 0); $this->phpSheet->setPrintGridlines($printGridlines); } } @@ -3004,7 +3028,7 @@ class Xls extends BaseReader implements IReader */ private function readDefaultRowHeight() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3012,7 +3036,7 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2; option flags // offset: 2; size: 2; default height for unused rows, (twips 1/20 point) - $height = self::getInt2d($recordData, 2); + $height = self::getUInt2d($recordData, 2); $this->phpSheet->getDefaultRowDimension()->setRowHeight($height / 20); } @@ -3021,7 +3045,7 @@ class Xls extends BaseReader implements IReader */ private function readSheetPr() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3030,16 +3054,16 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2 // bit: 6; mask: 0x0040; 0 = outline buttons above outline group - $isSummaryBelow = (0x0040 & self::getInt2d($recordData, 0)) >> 6; + $isSummaryBelow = (0x0040 & self::getUInt2d($recordData, 0)) >> 6; $this->phpSheet->setShowSummaryBelow($isSummaryBelow); // bit: 7; mask: 0x0080; 0 = outline buttons left of outline group - $isSummaryRight = (0x0080 & self::getInt2d($recordData, 0)) >> 7; + $isSummaryRight = (0x0080 & self::getUInt2d($recordData, 0)) >> 7; $this->phpSheet->setShowSummaryRight($isSummaryRight); // bit: 8; mask: 0x100; 0 = scale printout in percent, 1 = fit printout to number of pages // this corresponds to radio button setting in page setup dialog in Excel - $this->isFitToPages = (bool) ((0x0100 & self::getInt2d($recordData, 0)) >> 8); + $this->isFitToPages = (bool) ((0x0100 & self::getUInt2d($recordData, 0)) >> 8); } /** @@ -3047,7 +3071,7 @@ class Xls extends BaseReader implements IReader */ private function readHorizontalPageBreaks() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3055,16 +3079,16 @@ class Xls extends BaseReader implements IReader if ($this->version == self::XLS_BIFF8 && !$this->readDataOnly) { // offset: 0; size: 2; number of the following row index structures - $nm = self::getInt2d($recordData, 0); + $nm = self::getUInt2d($recordData, 0); // offset: 2; size: 6 * $nm; list of $nm row index structures for ($i = 0; $i < $nm; ++$i) { - $r = self::getInt2d($recordData, 2 + 6 * $i); - $cf = self::getInt2d($recordData, 2 + 6 * $i + 2); - $cl = self::getInt2d($recordData, 2 + 6 * $i + 4); + $r = self::getUInt2d($recordData, 2 + 6 * $i); + $cf = self::getUInt2d($recordData, 2 + 6 * $i + 2); + $cl = self::getUInt2d($recordData, 2 + 6 * $i + 4); // not sure why two column indexes are necessary? - $this->phpSheet->setBreakByColumnAndRow($cf, $r, \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_ROW); + $this->phpSheet->setBreakByColumnAndRow($cf, $r, Worksheet::BREAK_ROW); } } } @@ -3074,7 +3098,7 @@ class Xls extends BaseReader implements IReader */ private function readVerticalPageBreaks() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3082,16 +3106,16 @@ class Xls extends BaseReader implements IReader if ($this->version == self::XLS_BIFF8 && !$this->readDataOnly) { // offset: 0; size: 2; number of the following column index structures - $nm = self::getInt2d($recordData, 0); + $nm = self::getUInt2d($recordData, 0); // offset: 2; size: 6 * $nm; list of $nm row index structures for ($i = 0; $i < $nm; ++$i) { - $c = self::getInt2d($recordData, 2 + 6 * $i); - $rf = self::getInt2d($recordData, 2 + 6 * $i + 2); - $rl = self::getInt2d($recordData, 2 + 6 * $i + 4); + $c = self::getUInt2d($recordData, 2 + 6 * $i); + $rf = self::getUInt2d($recordData, 2 + 6 * $i + 2); + $rl = self::getUInt2d($recordData, 2 + 6 * $i + 4); // not sure why two row indexes are necessary? - $this->phpSheet->setBreakByColumnAndRow($c, $rf, \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_COLUMN); + $this->phpSheet->setBreakByColumnAndRow($c, $rf, Worksheet::BREAK_COLUMN); } } } @@ -3101,7 +3125,7 @@ class Xls extends BaseReader implements IReader */ private function readHeader() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3128,7 +3152,7 @@ class Xls extends BaseReader implements IReader */ private function readFooter() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3154,7 +3178,7 @@ class Xls extends BaseReader implements IReader */ private function readHcenter() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3162,7 +3186,7 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; 0 = print sheet left aligned, 1 = print sheet centered horizontally - $isHorizontalCentered = (bool) self::getInt2d($recordData, 0); + $isHorizontalCentered = (bool) self::getUInt2d($recordData, 0); $this->phpSheet->getPageSetup()->setHorizontalCentered($isHorizontalCentered); } @@ -3173,7 +3197,7 @@ class Xls extends BaseReader implements IReader */ private function readVcenter() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3181,7 +3205,7 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; 0 = print sheet aligned at top page border, 1 = print sheet vertically centered - $isVerticalCentered = (bool) self::getInt2d($recordData, 0); + $isVerticalCentered = (bool) self::getUInt2d($recordData, 0); $this->phpSheet->getPageSetup()->setVerticalCentered($isVerticalCentered); } @@ -3192,7 +3216,7 @@ class Xls extends BaseReader implements IReader */ private function readLeftMargin() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3209,7 +3233,7 @@ class Xls extends BaseReader implements IReader */ private function readRightMargin() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3226,7 +3250,7 @@ class Xls extends BaseReader implements IReader */ private function readTopMargin() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3243,7 +3267,7 @@ class Xls extends BaseReader implements IReader */ private function readBottomMargin() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3260,7 +3284,7 @@ class Xls extends BaseReader implements IReader */ private function readPageSetup() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3268,34 +3292,34 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; paper size - $paperSize = self::getInt2d($recordData, 0); + $paperSize = self::getUInt2d($recordData, 0); // offset: 2; size: 2; scaling factor - $scale = self::getInt2d($recordData, 2); + $scale = self::getUInt2d($recordData, 2); // offset: 6; size: 2; fit worksheet width to this number of pages, 0 = use as many as needed - $fitToWidth = self::getInt2d($recordData, 6); + $fitToWidth = self::getUInt2d($recordData, 6); // offset: 8; size: 2; fit worksheet height to this number of pages, 0 = use as many as needed - $fitToHeight = self::getInt2d($recordData, 8); + $fitToHeight = self::getUInt2d($recordData, 8); // offset: 10; size: 2; option flags // bit: 1; mask: 0x0002; 0=landscape, 1=portrait - $isPortrait = (0x0002 & self::getInt2d($recordData, 10)) >> 1; + $isPortrait = (0x0002 & self::getUInt2d($recordData, 10)) >> 1; // bit: 2; mask: 0x0004; 1= paper size, scaling factor, paper orient. not init // when this bit is set, do not use flags for those properties - $isNotInit = (0x0004 & self::getInt2d($recordData, 10)) >> 2; + $isNotInit = (0x0004 & self::getUInt2d($recordData, 10)) >> 2; if (!$isNotInit) { $this->phpSheet->getPageSetup()->setPaperSize($paperSize); switch ($isPortrait) { case 0: - $this->phpSheet->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); + $this->phpSheet->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); break; case 1: - $this->phpSheet->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT); + $this->phpSheet->getPageSetup()->setOrientation(PageSetup::ORIENTATION_PORTRAIT); break; } @@ -3321,7 +3345,7 @@ class Xls extends BaseReader implements IReader */ private function readProtect() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3334,7 +3358,7 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2; // bit 0, mask 0x01; 1 = sheet is protected - $bool = (0x01 & self::getInt2d($recordData, 0)) >> 0; + $bool = (0x01 & self::getUInt2d($recordData, 0)) >> 0; $this->phpSheet->getProtection()->setSheet((bool) $bool); } @@ -3343,7 +3367,7 @@ class Xls extends BaseReader implements IReader */ private function readScenProtect() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3356,7 +3380,7 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2; // bit: 0, mask 0x01; 1 = scenarios are protected - $bool = (0x01 & self::getInt2d($recordData, 0)) >> 0; + $bool = (0x01 & self::getUInt2d($recordData, 0)) >> 0; $this->phpSheet->getProtection()->setScenarios((bool) $bool); } @@ -3366,7 +3390,7 @@ class Xls extends BaseReader implements IReader */ private function readObjectProtect() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3379,7 +3403,7 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2; // bit: 0, mask 0x01; 1 = objects are protected - $bool = (0x01 & self::getInt2d($recordData, 0)) >> 0; + $bool = (0x01 & self::getUInt2d($recordData, 0)) >> 0; $this->phpSheet->getProtection()->setObjects((bool) $bool); } @@ -3389,7 +3413,7 @@ class Xls extends BaseReader implements IReader */ private function readPassword() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3397,7 +3421,7 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; 16-bit hash value of password - $password = strtoupper(dechex(self::getInt2d($recordData, 0))); // the hashed password + $password = strtoupper(dechex(self::getUInt2d($recordData, 0))); // the hashed password $this->phpSheet->getProtection()->setPassword($password, true); } } @@ -3407,14 +3431,14 @@ class Xls extends BaseReader implements IReader */ private function readDefColWidth() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; default column width - $width = self::getInt2d($recordData, 0); + $width = self::getUInt2d($recordData, 0); if ($width != 8) { $this->phpSheet->getDefaultColumnDimension()->setWidth($width); } @@ -3425,7 +3449,7 @@ class Xls extends BaseReader implements IReader */ private function readColInfo() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3433,26 +3457,26 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; index to first column in range - $fc = self::getInt2d($recordData, 0); // first column index + $fc = self::getUInt2d($recordData, 0); // first column index // offset: 2; size: 2; index to last column in range - $lc = self::getInt2d($recordData, 2); // first column index + $lc = self::getUInt2d($recordData, 2); // first column index // offset: 4; size: 2; width of the column in 1/256 of the width of the zero character - $width = self::getInt2d($recordData, 4); + $width = self::getUInt2d($recordData, 4); // offset: 6; size: 2; index to XF record for default column formatting - $xfIndex = self::getInt2d($recordData, 6); + $xfIndex = self::getUInt2d($recordData, 6); // offset: 8; size: 2; option flags // bit: 0; mask: 0x0001; 1= columns are hidden - $isHidden = (0x0001 & self::getInt2d($recordData, 8)) >> 0; + $isHidden = (0x0001 & self::getUInt2d($recordData, 8)) >> 0; // bit: 10-8; mask: 0x0700; outline level of the columns (0 = no outline) - $level = (0x0700 & self::getInt2d($recordData, 8)) >> 8; + $level = (0x0700 & self::getUInt2d($recordData, 8)) >> 8; // bit: 12; mask: 0x1000; 1 = collapsed - $isCollapsed = (0x1000 & self::getInt2d($recordData, 8)) >> 12; + $isCollapsed = (0x1000 & self::getUInt2d($recordData, 8)) >> 12; // offset: 10; size: 2; not used @@ -3482,7 +3506,7 @@ class Xls extends BaseReader implements IReader */ private function readRow() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3490,7 +3514,7 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; index of this row - $r = self::getInt2d($recordData, 0); + $r = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to column of the first cell which is described by a cell record @@ -3499,10 +3523,10 @@ class Xls extends BaseReader implements IReader // offset: 6; size: 2; // bit: 14-0; mask: 0x7FFF; height of the row, in twips = 1/20 of a point - $height = (0x7FFF & self::getInt2d($recordData, 6)) >> 0; + $height = (0x7FFF & self::getUInt2d($recordData, 6)) >> 0; // bit: 15: mask: 0x8000; 0 = row has custom height; 1= row has default height - $useDefaultHeight = (0x8000 & self::getInt2d($recordData, 6)) >> 15; + $useDefaultHeight = (0x8000 & self::getUInt2d($recordData, 6)) >> 15; if (!$useDefaultHeight) { $this->phpSheet->getRowDimension($r + 1)->setRowHeight($height / 20); @@ -3551,23 +3575,23 @@ class Xls extends BaseReader implements IReader */ private function readRk() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; index to row - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to column - $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset: 4; size: 2; index to XF record - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); // offset: 6; size: 4; RK value $rknum = self::getInt4d($recordData, 6); @@ -3580,7 +3604,7 @@ class Xls extends BaseReader implements IReader } // add cell - $cell->setValueExplicit($numValue, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC); + $cell->setValueExplicit($numValue, Cell\DataType::TYPE_NUMERIC); } } @@ -3595,24 +3619,24 @@ class Xls extends BaseReader implements IReader */ private function readLabelSst() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; index to row - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to column - $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($column); $emptyCell = true; // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset: 4; size: 2; index to XF record - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); // offset: 6; size: 4; index to SST record $index = self::getInt4d($recordData, 6); @@ -3620,18 +3644,18 @@ class Xls extends BaseReader implements IReader // add cell if (($fmtRuns = $this->sst[$index]['fmtRuns']) && !$this->readDataOnly) { // then we should treat as rich text - $richText = new \PhpOffice\PhpSpreadsheet\RichText(); + $richText = new RichText(); $charPos = 0; $sstCount = count($this->sst[$index]['fmtRuns']); for ($i = 0; $i <= $sstCount; ++$i) { if (isset($fmtRuns[$i])) { - $text = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::substring($this->sst[$index]['value'], $charPos, $fmtRuns[$i]['charPos'] - $charPos); + $text = StringHelper::substring($this->sst[$index]['value'], $charPos, $fmtRuns[$i]['charPos'] - $charPos); $charPos = $fmtRuns[$i]['charPos']; } else { - $text = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::substring($this->sst[$index]['value'], $charPos, \PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($this->sst[$index]['value'])); + $text = StringHelper::substring($this->sst[$index]['value'], $charPos, StringHelper::countCharacters($this->sst[$index]['value'])); } - if (\PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($text) > 0) { + if (StringHelper::countCharacters($text) > 0) { if ($i == 0) { // first text run, no style $richText->createText($text); } else { @@ -3651,13 +3675,13 @@ class Xls extends BaseReader implements IReader } if ($this->readEmptyCells || trim($richText->getPlainText()) !== '') { $cell = $this->phpSheet->getCell($columnString . ($row + 1)); - $cell->setValueExplicit($richText, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); + $cell->setValueExplicit($richText, Cell\DataType::TYPE_STRING); $emptyCell = false; } } else { if ($this->readEmptyCells || trim($this->sst[$index]['value']) !== '') { $cell = $this->phpSheet->getCell($columnString . ($row + 1)); - $cell->setValueExplicit($this->sst[$index]['value'], \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); + $cell->setValueExplicit($this->sst[$index]['value'], Cell\DataType::TYPE_STRING); $emptyCell = false; } } @@ -3679,32 +3703,32 @@ class Xls extends BaseReader implements IReader */ private function readMulRk() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; index to row - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to first column - $colFirst = self::getInt2d($recordData, 2); + $colFirst = self::getUInt2d($recordData, 2); // offset: var; size: 2; index to last column - $colLast = self::getInt2d($recordData, $length - 2); + $colLast = self::getUInt2d($recordData, $length - 2); $columns = $colLast - $colFirst + 1; // offset within record data $offset = 4; for ($i = 0; $i < $columns; ++$i) { - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($colFirst + $i); + $columnString = Cell::stringFromColumnIndex($colFirst + $i); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset: var; size: 2; index to XF record - $xfIndex = self::getInt2d($recordData, $offset); + $xfIndex = self::getUInt2d($recordData, $offset); // offset: var; size: 4; RK value $numValue = self::getIEEE754(self::getInt4d($recordData, $offset + 2)); @@ -3715,7 +3739,7 @@ class Xls extends BaseReader implements IReader } // add cell value - $cell->setValueExplicit($numValue, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC); + $cell->setValueExplicit($numValue, Cell\DataType::TYPE_NUMERIC); } $offset += 6; @@ -3732,23 +3756,23 @@ class Xls extends BaseReader implements IReader */ private function readNumber() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; index to row - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size 2; index to column - $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset 4; size: 2; index to XF record - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); $numValue = self::extractNumber(substr($recordData, 6, 8)); @@ -3759,7 +3783,7 @@ class Xls extends BaseReader implements IReader } // add cell value - $cell->setValueExplicit($numValue, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC); + $cell->setValueExplicit($numValue, Cell\DataType::TYPE_NUMERIC); } } @@ -3773,24 +3797,24 @@ class Xls extends BaseReader implements IReader */ private function readFormula() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; row index - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; col index - $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($column); // offset: 20: size: variable; formula structure $formulaStructure = substr($recordData, 20); // offset: 14: size: 2; option flags, recalculate always, recalculate on open etc. - $options = self::getInt2d($recordData, 14); + $options = self::getUInt2d($recordData, 14); // bit: 0; mask: 0x0001; 1 = recalculate always // bit: 1; mask: 0x0002; 1 = calculate on open @@ -3806,9 +3830,9 @@ class Xls extends BaseReader implements IReader if ($isPartOfSharedFormula) { // part of shared formula which means there will be a formula with a tExp token and nothing else // get the base cell, grab tExp token - $baseRow = self::getInt2d($formulaStructure, 3); - $baseCol = self::getInt2d($formulaStructure, 5); - $this->_baseCell = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol) . ($baseRow + 1); + $baseRow = self::getUInt2d($formulaStructure, 3); + $baseCol = self::getUInt2d($formulaStructure, 5); + $this->_baseCell = Cell::stringFromColumnIndex($baseCol) . ($baseRow + 1); } // Read cell? @@ -3821,15 +3845,15 @@ class Xls extends BaseReader implements IReader // offset: 16: size: 4; not used // offset: 4; size: 2; XF index - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); // offset: 6; size: 8; result of the formula if ((ord($recordData[6]) == 0) && (ord($recordData[12]) == 255) && (ord($recordData[13]) == 255)) { // String formula. Result follows in appended STRING record - $dataType = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING; + $dataType = Cell\DataType::TYPE_STRING; // read possible SHAREDFMLA record - $code = self::getInt2d($this->data, $this->pos); + $code = self::getUInt2d($this->data, $this->pos); if ($code == self::XLS_TYPE_SHAREDFMLA) { $this->readSharedFmla(); } @@ -3840,23 +3864,23 @@ class Xls extends BaseReader implements IReader && (ord($recordData[12]) == 255) && (ord($recordData[13]) == 255)) { // Boolean formula. Result is in +2; 0=false, 1=true - $dataType = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL; + $dataType = Cell\DataType::TYPE_BOOL; $value = (bool) ord($recordData[8]); } elseif ((ord($recordData[6]) == 2) && (ord($recordData[12]) == 255) && (ord($recordData[13]) == 255)) { // Error formula. Error code is in +2 - $dataType = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR; + $dataType = Cell\DataType::TYPE_ERROR; $value = Xls\ErrorCode::lookup(ord($recordData[8])); } elseif ((ord($recordData[6]) == 3) && (ord($recordData[12]) == 255) && (ord($recordData[13]) == 255)) { // Formula result is a null string - $dataType = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL; + $dataType = Cell\DataType::TYPE_NULL; $value = ''; } else { // forumla result is a number, first 14 bytes like _NUMBER record - $dataType = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC; + $dataType = Cell\DataType::TYPE_NUMERIC; $value = self::extractNumber(substr($recordData, 6, 8)); } @@ -3875,8 +3899,8 @@ class Xls extends BaseReader implements IReader throw new Exception('Not BIFF8. Can only read BIFF8 formulas'); } $formula = $this->getFormulaFromStructure($formulaStructure); // get formula in human language - $cell->setValueExplicit('=' . $formula, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + $cell->setValueExplicit('=' . $formula, Cell\DataType::TYPE_FORMULA); + } catch (PhpSpreadsheetException $e) { $cell->setValueExplicit($value, $dataType); } } else { @@ -3899,7 +3923,7 @@ class Xls extends BaseReader implements IReader */ private function readSharedFmla() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3930,7 +3954,7 @@ class Xls extends BaseReader implements IReader */ private function readString() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -3957,23 +3981,23 @@ class Xls extends BaseReader implements IReader */ private function readBoolErr() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; row index - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; column index - $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset: 4; size: 2; index to XF record - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); // offset: 6; size: 1; the boolean value or error value $boolErr = ord($recordData[6]); @@ -3987,13 +4011,13 @@ class Xls extends BaseReader implements IReader $value = (bool) $boolErr; // add cell value - $cell->setValueExplicit($value, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL); + $cell->setValueExplicit($value, Cell\DataType::TYPE_BOOL); break; case 1: // error type $value = Xls\ErrorCode::lookup($boolErr); // add cell value - $cell->setValueExplicit($value, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR); + $cell->setValueExplicit($value, Cell\DataType::TYPE_ERROR); break; } @@ -4014,27 +4038,27 @@ class Xls extends BaseReader implements IReader */ private function readMulBlank() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; index to row - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to first column - $fc = self::getInt2d($recordData, 2); + $fc = self::getUInt2d($recordData, 2); // offset: 4; size: 2 x nc; list of indexes to XF records // add style information if (!$this->readDataOnly && $this->readEmptyCells) { for ($i = 0; $i < $length / 2 - 3; ++$i) { - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($fc + $i); + $columnString = Cell::stringFromColumnIndex($fc + $i); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { - $xfIndex = self::getInt2d($recordData, 4 + 2 * $i); + $xfIndex = self::getUInt2d($recordData, 4 + 2 * $i); $this->phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->mapCellXfIndex[$xfIndex]); } } @@ -4055,23 +4079,23 @@ class Xls extends BaseReader implements IReader */ private function readLabel() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; index to row - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to column - $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $column = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset: 4; size: 2; XF index - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); // add cell value // todo: what if string is very long? continue record @@ -4084,7 +4108,7 @@ class Xls extends BaseReader implements IReader } if ($this->readEmptyCells || trim($value) !== '') { $cell = $this->phpSheet->getCell($columnString . ($row + 1)); - $cell->setValueExplicit($value, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING); + $cell->setValueExplicit($value, Cell\DataType::TYPE_STRING); if (!$this->readDataOnly) { // add cell style @@ -4099,23 +4123,23 @@ class Xls extends BaseReader implements IReader */ private function readBlank() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; row index - $row = self::getInt2d($recordData, 0); + $row = self::getUInt2d($recordData, 0); // offset: 2; size: 2; col index - $col = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col); + $col = self::getUInt2d($recordData, 2); + $columnString = Cell::stringFromColumnIndex($col); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { // offset: 4; size: 2; XF index - $xfIndex = self::getInt2d($recordData, 4); + $xfIndex = self::getUInt2d($recordData, 4); // add style information if (!$this->readDataOnly && $this->readEmptyCells) { @@ -4129,7 +4153,7 @@ class Xls extends BaseReader implements IReader */ private function readMsoDrawing() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); // get spliced record data $splicedRecordData = $this->getSplicedRecordData(); @@ -4143,7 +4167,7 @@ class Xls extends BaseReader implements IReader */ private function readObj() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4162,11 +4186,11 @@ class Xls extends BaseReader implements IReader // data: var; subrecord data // for now, we are just interested in the second subrecord containing the object type - $ftCmoType = self::getInt2d($recordData, 0); - $cbCmoSize = self::getInt2d($recordData, 2); - $otObjType = self::getInt2d($recordData, 4); - $idObjID = self::getInt2d($recordData, 6); - $grbitOpts = self::getInt2d($recordData, 6); + $ftCmoType = self::getUInt2d($recordData, 0); + $cbCmoSize = self::getUInt2d($recordData, 2); + $otObjType = self::getUInt2d($recordData, 4); + $idObjID = self::getUInt2d($recordData, 6); + $grbitOpts = self::getUInt2d($recordData, 6); $this->objs[] = [ 'ftCmoType' => $ftCmoType, @@ -4183,30 +4207,30 @@ class Xls extends BaseReader implements IReader */ private function readWindow2() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; option flags - $options = self::getInt2d($recordData, 0); + $options = self::getUInt2d($recordData, 0); // offset: 2; size: 2; index to first visible row - $firstVisibleRow = self::getInt2d($recordData, 2); + $firstVisibleRow = self::getUInt2d($recordData, 2); // offset: 4; size: 2; index to first visible colum - $firstVisibleColumn = self::getInt2d($recordData, 4); + $firstVisibleColumn = self::getUInt2d($recordData, 4); if ($this->version === self::XLS_BIFF8) { // offset: 8; size: 2; not used // offset: 10; size: 2; cached magnification factor in page break preview (in percent); 0 = Default (60%) // offset: 12; size: 2; cached magnification factor in normal view (in percent); 0 = Default (100%) // offset: 14; size: 4; not used - $zoomscaleInPageBreakPreview = self::getInt2d($recordData, 10); + $zoomscaleInPageBreakPreview = self::getUInt2d($recordData, 10); if ($zoomscaleInPageBreakPreview === 0) { $zoomscaleInPageBreakPreview = 60; } - $zoomscaleInNormalView = self::getInt2d($recordData, 12); + $zoomscaleInNormalView = self::getUInt2d($recordData, 12); if ($zoomscaleInNormalView === 0) { $zoomscaleInNormalView = 100; } @@ -4237,9 +4261,9 @@ class Xls extends BaseReader implements IReader //FIXME: set $firstVisibleRow and $firstVisibleColumn - if ($this->phpSheet->getSheetView()->getView() !== \PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_LAYOUT) { + if ($this->phpSheet->getSheetView()->getView() !== SheetView::SHEETVIEW_PAGE_LAYOUT) { //NOTE: this setting is inferior to page layout view(Excel2007-) - $view = $isPageBreakPreview ? \PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW : \PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_NORMAL; + $view = $isPageBreakPreview ? SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW : SheetView::SHEETVIEW_NORMAL; $this->phpSheet->getSheetView()->setView($view); if ($this->version === self::XLS_BIFF8) { $zoomScale = $isPageBreakPreview ? $zoomscaleInPageBreakPreview : $zoomscaleInNormalView; @@ -4254,7 +4278,7 @@ class Xls extends BaseReader implements IReader */ private function readPageLayoutView() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4262,17 +4286,17 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2; rt //->ignore - $rt = self::getInt2d($recordData, 0); + $rt = self::getUInt2d($recordData, 0); // offset: 2; size: 2; grbitfr //->ignore - $grbitFrt = self::getInt2d($recordData, 2); + $grbitFrt = self::getUInt2d($recordData, 2); // offset: 4; size: 8; reserved //->ignore // offset: 12; size 2; zoom scale - $wScalePLV = self::getInt2d($recordData, 12); + $wScalePLV = self::getUInt2d($recordData, 12); // offset: 14; size 2; grbit - $grbit = self::getInt2d($recordData, 14); + $grbit = self::getUInt2d($recordData, 14); // decomprise grbit $fPageLayoutView = $grbit & 0x01; @@ -4280,7 +4304,7 @@ class Xls extends BaseReader implements IReader $fWhitespaceHidden = ($grbit >> 3) & 0x01; //no support if ($fPageLayoutView === 1) { - $this->phpSheet->getSheetView()->setView(\PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_LAYOUT); + $this->phpSheet->getSheetView()->setView(SheetView::SHEETVIEW_PAGE_LAYOUT); $this->phpSheet->getSheetView()->setZoomScale($wScalePLV); //set by Excel2007 only if SHEETVIEW_PAGE_LAYOUT } //otherwise, we cannot know whether SHEETVIEW_PAGE_LAYOUT or SHEETVIEW_PAGE_BREAK_PREVIEW. @@ -4291,17 +4315,17 @@ class Xls extends BaseReader implements IReader */ private function readScl() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record $this->pos += 4 + $length; // offset: 0; size: 2; numerator of the view magnification - $numerator = self::getInt2d($recordData, 0); + $numerator = self::getUInt2d($recordData, 0); // offset: 2; size: 2; numerator of the view magnification - $denumerator = self::getInt2d($recordData, 2); + $denumerator = self::getUInt2d($recordData, 2); // set the zoom scale (in percent) $this->phpSheet->getSheetView()->setZoomScale($numerator * 100 / $denumerator); @@ -4312,7 +4336,7 @@ class Xls extends BaseReader implements IReader */ private function readPane() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4320,14 +4344,14 @@ class Xls extends BaseReader implements IReader if (!$this->readDataOnly) { // offset: 0; size: 2; position of vertical split - $px = self::getInt2d($recordData, 0); + $px = self::getUInt2d($recordData, 0); // offset: 2; size: 2; position of horizontal split - $py = self::getInt2d($recordData, 2); + $py = self::getUInt2d($recordData, 2); if ($this->frozen) { // frozen panes - $this->phpSheet->freezePane(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($px) . ($py + 1)); + $this->phpSheet->freezePane(Cell::stringFromColumnIndex($px) . ($py + 1)); } // unfrozen panes; split windows; not supported by PhpSpreadsheet core } @@ -4338,7 +4362,7 @@ class Xls extends BaseReader implements IReader */ private function readSelection() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4349,14 +4373,14 @@ class Xls extends BaseReader implements IReader $paneId = ord($recordData[0]); // offset: 1; size: 2; index to row of the active cell - $r = self::getInt2d($recordData, 1); + $r = self::getUInt2d($recordData, 1); // offset: 3; size: 2; index to column of the active cell - $c = self::getInt2d($recordData, 3); + $c = self::getUInt2d($recordData, 3); // offset: 5; size: 2; index into the following cell range list to the // entry that contains the active cell - $index = self::getInt2d($recordData, 5); + $index = self::getUInt2d($recordData, 5); // offset: 7; size: var; cell range address list containing all selected cell ranges $data = substr($recordData, 7); @@ -4388,7 +4412,7 @@ class Xls extends BaseReader implements IReader $includeCellRange = true; if ($this->getReadFilter() !== null) { $includeCellRange = false; - $rangeBoundaries = \PhpOffice\PhpSpreadsheet\Cell::getRangeBoundaries($cellRangeAddress); + $rangeBoundaries = Cell::getRangeBoundaries($cellRangeAddress); ++$rangeBoundaries[1][0]; for ($row = $rangeBoundaries[0][1]; $row <= $rangeBoundaries[1][1]; ++$row) { for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; ++$column) { @@ -4414,7 +4438,7 @@ class Xls extends BaseReader implements IReader */ private function readMergedCells() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4436,7 +4460,7 @@ class Xls extends BaseReader implements IReader */ private function readHyperLink() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer forward to next record @@ -4446,7 +4470,7 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 8; cell range address of all cells containing this hyperlink try { $cellRange = $this->readBIFF8CellRangeAddressFixed($recordData); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { return; } @@ -4456,22 +4480,22 @@ class Xls extends BaseReader implements IReader // offset: 28, size: 4; option flags // bit: 0; mask: 0x00000001; 0 = no link or extant, 1 = file link or URL - $isFileLinkOrUrl = (0x00000001 & self::getInt2d($recordData, 28)) >> 0; + $isFileLinkOrUrl = (0x00000001 & self::getUInt2d($recordData, 28)) >> 0; // bit: 1; mask: 0x00000002; 0 = relative path, 1 = absolute path or URL - $isAbsPathOrUrl = (0x00000001 & self::getInt2d($recordData, 28)) >> 1; + $isAbsPathOrUrl = (0x00000001 & self::getUInt2d($recordData, 28)) >> 1; // bit: 2 (and 4); mask: 0x00000014; 0 = no description - $hasDesc = (0x00000014 & self::getInt2d($recordData, 28)) >> 2; + $hasDesc = (0x00000014 & self::getUInt2d($recordData, 28)) >> 2; // bit: 3; mask: 0x00000008; 0 = no text, 1 = has text - $hasText = (0x00000008 & self::getInt2d($recordData, 28)) >> 3; + $hasText = (0x00000008 & self::getUInt2d($recordData, 28)) >> 3; // bit: 7; mask: 0x00000080; 0 = no target frame, 1 = has target frame - $hasFrame = (0x00000080 & self::getInt2d($recordData, 28)) >> 7; + $hasFrame = (0x00000080 & self::getUInt2d($recordData, 28)) >> 7; // bit: 8; mask: 0x00000100; 0 = file link or URL, 1 = UNC path (inc. server name) - $isUNC = (0x00000100 & self::getInt2d($recordData, 28)) >> 8; + $isUNC = (0x00000100 & self::getUInt2d($recordData, 28)) >> 8; // offset within record data $offset = 32; @@ -4530,7 +4554,7 @@ class Xls extends BaseReader implements IReader $offset += 16; // offset: var; size: 2; directory up-level count. - $upLevelCount = self::getInt2d($recordData, $offset); + $upLevelCount = self::getUInt2d($recordData, $offset); $offset += 2; // offset: var; size: 4; character count of the shortened file path and name, including trailing zero word @@ -4596,7 +4620,7 @@ class Xls extends BaseReader implements IReader } // apply the hyperlink to all the relevant cells - foreach (\PhpOffice\PhpSpreadsheet\Cell::extractAllCellReferencesInRange($cellRange) as $coordinate) { + foreach (Cell::extractAllCellReferencesInRange($cellRange) as $coordinate) { $this->phpSheet->getCell($coordinate)->getHyperLink()->setUrl($url); } } @@ -4607,7 +4631,7 @@ class Xls extends BaseReader implements IReader */ private function readDataValidations() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer forward to next record @@ -4619,7 +4643,7 @@ class Xls extends BaseReader implements IReader */ private function readDataValidation() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer forward to next record @@ -4636,28 +4660,28 @@ class Xls extends BaseReader implements IReader $type = (0x0000000F & $options) >> 0; switch ($type) { case 0x00: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_NONE; + $type = DataValidation::TYPE_NONE; break; case 0x01: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE; + $type = DataValidation::TYPE_WHOLE; break; case 0x02: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_DECIMAL; + $type = DataValidation::TYPE_DECIMAL; break; case 0x03: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST; + $type = DataValidation::TYPE_LIST; break; case 0x04: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_DATE; + $type = DataValidation::TYPE_DATE; break; case 0x05: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_TIME; + $type = DataValidation::TYPE_TIME; break; case 0x06: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_TEXTLENGTH; + $type = DataValidation::TYPE_TEXTLENGTH; break; case 0x07: - $type = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_CUSTOM; + $type = DataValidation::TYPE_CUSTOM; break; } @@ -4665,13 +4689,13 @@ class Xls extends BaseReader implements IReader $errorStyle = (0x00000070 & $options) >> 4; switch ($errorStyle) { case 0x00: - $errorStyle = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP; + $errorStyle = DataValidation::STYLE_STOP; break; case 0x01: - $errorStyle = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_WARNING; + $errorStyle = DataValidation::STYLE_WARNING; break; case 0x02: - $errorStyle = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION; + $errorStyle = DataValidation::STYLE_INFORMATION; break; } @@ -4695,28 +4719,28 @@ class Xls extends BaseReader implements IReader $operator = (0x00F00000 & $options) >> 20; switch ($operator) { case 0x00: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_BETWEEN; + $operator = DataValidation::OPERATOR_BETWEEN; break; case 0x01: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_NOTBETWEEN; + $operator = DataValidation::OPERATOR_NOTBETWEEN; break; case 0x02: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_EQUAL; + $operator = DataValidation::OPERATOR_EQUAL; break; case 0x03: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_NOTEQUAL; + $operator = DataValidation::OPERATOR_NOTEQUAL; break; case 0x04: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_GREATERTHAN; + $operator = DataValidation::OPERATOR_GREATERTHAN; break; case 0x05: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_LESSTHAN; + $operator = DataValidation::OPERATOR_LESSTHAN; break; case 0x06: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_GREATERTHANOREQUAL; + $operator = DataValidation::OPERATOR_GREATERTHANOREQUAL; break; case 0x07: - $operator = \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_LESSTHANOREQUAL; + $operator = DataValidation::OPERATOR_LESSTHANOREQUAL; break; } @@ -4742,7 +4766,7 @@ class Xls extends BaseReader implements IReader $offset += $string['size']; // offset: var; size: 2; size of the formula data for the first condition - $sz1 = self::getInt2d($recordData, $offset); + $sz1 = self::getUInt2d($recordData, $offset); $offset += 2; // offset: var; size: 2; not used @@ -4755,16 +4779,16 @@ class Xls extends BaseReader implements IReader $formula1 = $this->getFormulaFromStructure($formula1); // in list type validity, null characters are used as item separators - if ($type == \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST) { + if ($type == DataValidation::TYPE_LIST) { $formula1 = str_replace(chr(0), ',', $formula1); } - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { return; } $offset += $sz1; // offset: var; size: 2; size of the formula data for the first condition - $sz2 = self::getInt2d($recordData, $offset); + $sz2 = self::getUInt2d($recordData, $offset); $offset += 2; // offset: var; size: 2; not used @@ -4775,7 +4799,7 @@ class Xls extends BaseReader implements IReader $formula2 = pack('v', $sz2) . $formula2; // prepend the length try { $formula2 = $this->getFormulaFromStructure($formula2); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { return; } $offset += $sz2; @@ -4786,7 +4810,7 @@ class Xls extends BaseReader implements IReader foreach ($cellRangeAddresses as $cellRange) { $stRange = $this->phpSheet->shrinkRangeToFit($cellRange); - foreach (\PhpOffice\PhpSpreadsheet\Cell::extractAllCellReferencesInRange($stRange) as $coordinate) { + foreach (Cell::extractAllCellReferencesInRange($stRange) as $coordinate) { $objValidation = $this->phpSheet->getCell($coordinate)->getDataValidation(); $objValidation->setType($type); $objValidation->setErrorStyle($errorStyle); @@ -4810,7 +4834,7 @@ class Xls extends BaseReader implements IReader */ private function readSheetLayout() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4831,7 +4855,7 @@ class Xls extends BaseReader implements IReader switch ($sz) { case 0x14: // offset: 16; size: 2; color index for sheet tab - $colorIndex = self::getInt2d($recordData, 16); + $colorIndex = self::getUInt2d($recordData, 16); $color = Xls\Color::map($colorIndex, $this->palette, $this->version); $this->phpSheet->getTabColor()->setRGB($color['rgb']); break; @@ -4848,7 +4872,7 @@ class Xls extends BaseReader implements IReader */ private function readSheetProtection() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4865,7 +4889,7 @@ class Xls extends BaseReader implements IReader // offset: 4; size: 8; Currently not used and set to 0 // offset: 12; size: 2; Shared feature type index (2=Enhanced Protetion, 4=SmartTag) - $isf = self::getInt2d($recordData, 12); + $isf = self::getUInt2d($recordData, 12); if ($isf != 2) { return; } @@ -4876,7 +4900,7 @@ class Xls extends BaseReader implements IReader // rgbHdrSData, assume "Enhanced Protection" // offset: 19; size: 2; option flags - $options = self::getInt2d($recordData, 19); + $options = self::getUInt2d($recordData, 19); // bit: 0; mask 0x0001; 1 = user may edit objects, 0 = users must not edit objects $bool = (0x0001 & $options) >> 0; @@ -4948,7 +4972,7 @@ class Xls extends BaseReader implements IReader */ private function readRangeProtection() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // move stream pointer to next record @@ -4961,7 +4985,7 @@ class Xls extends BaseReader implements IReader $offset += 12; // offset: 12; size: 2; shared feature type, 2 = enhanced protection, 4 = smart tag - $isf = self::getInt2d($recordData, 12); + $isf = self::getUInt2d($recordData, 12); if ($isf != 2) { // we only read FEAT records of type 2 return; @@ -4971,7 +4995,7 @@ class Xls extends BaseReader implements IReader $offset += 5; // offset: 19; size: 2; count of ref ranges this feature is on - $cref = self::getInt2d($recordData, 19); + $cref = self::getUInt2d($recordData, 19); $offset += 2; $offset += 6; @@ -4981,7 +5005,7 @@ class Xls extends BaseReader implements IReader for ($i = 0; $i < $cref; ++$i) { try { $cellRange = $this->readBIFF8CellRangeAddressFixed(substr($recordData, 27 + 8 * $i, 8)); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { return; } $cellRanges[] = $cellRange; @@ -5008,7 +5032,7 @@ class Xls extends BaseReader implements IReader */ private function readImData() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); // get spliced record data $splicedRecordData = $this->getSplicedRecordData(); @@ -5017,10 +5041,10 @@ class Xls extends BaseReader implements IReader // UNDER CONSTRUCTION // offset: 0; size: 2; image format - $cf = self::getInt2d($recordData, 0); + $cf = self::getUInt2d($recordData, 0); // offset: 2; size: 2; environment from which the file was written - $env = self::getInt2d($recordData, 2); + $env = self::getUInt2d($recordData, 2); // offset: 4; size: 4; length of the image data $lcb = self::getInt4d($recordData, 4); @@ -5036,16 +5060,16 @@ class Xls extends BaseReader implements IReader $bcSize = self::getInt4d($iData, 0); // offset: 4; size: 2; bcWidth, specifies the width of the bitmap, in pixels - $bcWidth = self::getInt2d($iData, 4); + $bcWidth = self::getUInt2d($iData, 4); // offset: 6; size: 2; bcHeight, specifies the height of the bitmap, in pixels. - $bcHeight = self::getInt2d($iData, 6); + $bcHeight = self::getUInt2d($iData, 6); $ih = imagecreatetruecolor($bcWidth, $bcHeight); // offset: 8; size: 2; bcPlanes, specifies the number of planes for the target device. This value must be 1 // offset: 10; size: 2; bcBitCount specifies the number of bits-per-pixel. This value must be 1, 4, 8, or 24 - $bcBitCount = self::getInt2d($iData, 10); + $bcBitCount = self::getUInt2d($iData, 10); $rgbString = substr($iData, 12); $rgbTriples = []; @@ -5063,7 +5087,7 @@ class Xls extends BaseReader implements IReader } //imagepng($ih, 'image.png'); - $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); + $drawing = new Drawing(); $drawing->setPath($filename); $drawing->setWorksheet($this->phpSheet); break; @@ -5083,7 +5107,7 @@ class Xls extends BaseReader implements IReader */ private function readContinue() { - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $recordData = $this->readRecordData($this->data, $this->pos + 4, $length); // check if we are reading drawing data @@ -5111,7 +5135,7 @@ class Xls extends BaseReader implements IReader // 0xF00D MsofbtClientTextbox $validSplitPoints = [0xF003, 0xF004, 0xF00D]; // add identifiers if we find more - $splitPoint = self::getInt2d($recordData, 2); + $splitPoint = self::getUInt2d($recordData, 2); if (in_array($splitPoint, $validSplitPoints)) { // get spliced record data (and move pointer to next record) $splicedRecordData = $this->getSplicedRecordData(); @@ -5144,15 +5168,15 @@ class Xls extends BaseReader implements IReader ++$i; // offset: 0; size: 2; identifier - $identifier = self::getInt2d($this->data, $this->pos); + $identifier = self::getUInt2d($this->data, $this->pos); // offset: 2; size: 2; length - $length = self::getInt2d($this->data, $this->pos + 2); + $length = self::getUInt2d($this->data, $this->pos + 2); $data .= $this->readRecordData($this->data, $this->pos + 4, $length); $spliceOffsets[$i] = $spliceOffsets[$i - 1] + $length; $this->pos += 4 + $length; - $nextIdentifier = self::getInt2d($this->data, $this->pos); + $nextIdentifier = self::getUInt2d($this->data, $this->pos); } while ($nextIdentifier == self::XLS_TYPE_CONTINUE); $splicedData = [ @@ -5174,7 +5198,7 @@ class Xls extends BaseReader implements IReader private function getFormulaFromStructure($formulaStructure, $baseCell = 'A1') { // offset: 0; size: 2; size of the following formula data - $sz = self::getInt2d($formulaStructure, 0); + $sz = self::getUInt2d($formulaStructure, 0); // offset: 2; size: sz $formulaData = substr($formulaStructure, 2, $sz); @@ -5512,7 +5536,7 @@ class Xls extends BaseReader implements IReader case 0x04: $name = 'tAttrChoose'; // offset: 2; size: 2; number of choices in the CHOOSE function ($nc, number of parameters decreased by 1) - $nc = self::getInt2d($formulaData, 2); + $nc = self::getUInt2d($formulaData, 2); // offset: 4; size: 2 * $nc // offset: 4 + 2 * $nc; size: 2 $size = 2 * $nc + 6; @@ -5582,7 +5606,7 @@ class Xls extends BaseReader implements IReader // offset: 1; size: 2; unsigned 16-bit integer $name = 'tInt'; $size = 3; - $data = self::getInt2d($formulaData, 1); + $data = self::getUInt2d($formulaData, 1); break; case 0x1F: // number // offset: 1; size: 8; @@ -5605,7 +5629,7 @@ class Xls extends BaseReader implements IReader $name = 'tFunc'; $size = 3; // offset: 1; size: 2; index to built-in sheet function - switch (self::getInt2d($formulaData, 1)) { + switch (self::getUInt2d($formulaData, 1)) { case 2: $function = 'ISNA'; $args = 1; @@ -6260,7 +6284,7 @@ class Xls extends BaseReader implements IReader // offset: 1; size: 1; number of arguments $args = ord($formulaData[1]); // offset: 2: size: 2; index to built-in sheet function - $index = self::getInt2d($formulaData, 2); + $index = self::getUInt2d($formulaData, 2); switch ($index) { case 0: $function = 'COUNT'; @@ -6538,7 +6562,7 @@ class Xls extends BaseReader implements IReader $name = 'tName'; $size = 5; // offset: 1; size: 2; one-based index to definedname record - $definedNameIndex = self::getInt2d($formulaData, 1) - 1; + $definedNameIndex = self::getUInt2d($formulaData, 1) - 1; // offset: 2; size: 2; not used $data = $this->definedname[$definedNameIndex]['name']; break; @@ -6562,7 +6586,7 @@ class Xls extends BaseReader implements IReader $name = 'tMemArea'; // offset: 1; size: 4; not used // offset: 5; size: 2; size of the following subexpression - $subSize = self::getInt2d($formulaData, 5); + $subSize = self::getUInt2d($formulaData, 5); $size = 7 + $subSize; $data = $this->getFormulaFromData(substr($formulaData, 7, $subSize)); break; @@ -6572,7 +6596,7 @@ class Xls extends BaseReader implements IReader $name = 'tMemErr'; // offset: 1; size: 4; not used // offset: 5; size: 2; size of the following subexpression - $subSize = self::getInt2d($formulaData, 5); + $subSize = self::getUInt2d($formulaData, 5); $size = 7 + $subSize; $data = $this->getFormulaFromData(substr($formulaData, 7, $subSize)); break; @@ -6581,7 +6605,7 @@ class Xls extends BaseReader implements IReader case 0x69: $name = 'tMemFunc'; // offset: 1; size: 2; size of the following sub-expression - $subSize = self::getInt2d($formulaData, 1); + $subSize = self::getUInt2d($formulaData, 1); $size = 3 + $subSize; $data = $this->getFormulaFromData(substr($formulaData, 3, $subSize)); break; @@ -6606,7 +6630,7 @@ class Xls extends BaseReader implements IReader $size = 7; // offset: 1; size: 2; index to REF entry in EXTERNSHEET record // offset: 3; size: 2; one-based index to DEFINEDNAME or EXTERNNAME record - $index = self::getInt2d($formulaData, 3); + $index = self::getUInt2d($formulaData, 3); // assume index is to EXTERNNAME record $data = $this->externalNames[$index - 1]['name']; // offset: 5; size: 2; not used @@ -6619,12 +6643,12 @@ class Xls extends BaseReader implements IReader try { // offset: 1; size: 2; index to REF entry - $sheetRange = $this->readSheetRangeByRefIndex(self::getInt2d($formulaData, 1)); + $sheetRange = $this->readSheetRangeByRefIndex(self::getUInt2d($formulaData, 1)); // offset: 3; size: 4; cell address $cellAddress = $this->readBIFF8CellAddress(substr($formulaData, 3, 4)); $data = "$sheetRange!$cellAddress"; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { // deleted sheet reference $data = '#REF!'; } @@ -6637,12 +6661,12 @@ class Xls extends BaseReader implements IReader try { // offset: 1; size: 2; index to REF entry - $sheetRange = $this->readSheetRangeByRefIndex(self::getInt2d($formulaData, 1)); + $sheetRange = $this->readSheetRangeByRefIndex(self::getUInt2d($formulaData, 1)); // offset: 3; size: 8; cell address $cellRangeAddress = $this->readBIFF8CellRangeAddress(substr($formulaData, 3, 8)); $data = "$sheetRange!$cellRangeAddress"; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { // deleted sheet reference $data = '#REF!'; } @@ -6672,18 +6696,18 @@ class Xls extends BaseReader implements IReader private function readBIFF8CellAddress($cellAddressStructure) { // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767)) - $row = self::getInt2d($cellAddressStructure, 0) + 1; + $row = self::getUInt2d($cellAddressStructure, 0) + 1; // offset: 2; size: 2; index to column or column offset + relative flags // bit: 7-0; mask 0x00FF; column index - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex(0x00FF & self::getInt2d($cellAddressStructure, 2)); + $column = Cell::stringFromColumnIndex(0x00FF & self::getUInt2d($cellAddressStructure, 2)); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) - if (!(0x4000 & self::getInt2d($cellAddressStructure, 2))) { + if (!(0x4000 & self::getUInt2d($cellAddressStructure, 2))) { $column = '$' . $column; } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) - if (!(0x8000 & self::getInt2d($cellAddressStructure, 2))) { + if (!(0x8000 & self::getUInt2d($cellAddressStructure, 2))) { $row = '$' . $row; } @@ -6702,28 +6726,33 @@ class Xls extends BaseReader implements IReader */ private function readBIFF8CellAddressB($cellAddressStructure, $baseCell = 'A1') { - list($baseCol, $baseRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($baseCell); - $baseCol = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($baseCol) - 1; + list($baseCol, $baseRow) = Cell::coordinateFromString($baseCell); + $baseCol = Cell::columnIndexFromString($baseCol) - 1; // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767)) - $rowIndex = self::getInt2d($cellAddressStructure, 0); - $row = self::getInt2d($cellAddressStructure, 0) + 1; - - // offset: 2; size: 2; index to column or column offset + relative flags - // bit: 7-0; mask 0x00FF; column index - $colIndex = 0x00FF & self::getInt2d($cellAddressStructure, 2); + $rowIndex = self::getUInt2d($cellAddressStructure, 0); + $row = self::getUInt2d($cellAddressStructure, 0) + 1; // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) - if (!(0x4000 & self::getInt2d($cellAddressStructure, 2))) { - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($colIndex); + if (!(0x4000 & self::getUInt2d($cellAddressStructure, 2))) { + // offset: 2; size: 2; index to column or column offset + relative flags + // bit: 7-0; mask 0x00FF; column index + $colIndex = 0x00FF & self::getUInt2d($cellAddressStructure, 2); + + $column = Cell::stringFromColumnIndex($colIndex); $column = '$' . $column; } else { - $colIndex = ($colIndex <= 127) ? $colIndex : $colIndex - 256; - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $colIndex); + // offset: 2; size: 2; index to column or column offset + relative flags + // bit: 7-0; mask 0x00FF; column index + $relativeColIndex = 0x00FF & self::getInt2d($cellAddressStructure, 2); + $colIndex = $baseCol + $relativeColIndex; + $colIndex = ($colIndex < 256) ? $colIndex : $colIndex - 256; + $colIndex = ($colIndex >= 0) ? $colIndex : $colIndex + 256; + $column = Cell::stringFromColumnIndex($colIndex); } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) - if (!(0x8000 & self::getInt2d($cellAddressStructure, 2))) { + if (!(0x8000 & self::getUInt2d($cellAddressStructure, 2))) { $row = '$' . $row; } else { $rowIndex = ($rowIndex <= 32767) ? $rowIndex : $rowIndex - 65536; @@ -6747,10 +6776,10 @@ class Xls extends BaseReader implements IReader private function readBIFF5CellRangeAddressFixed($subData) { // offset: 0; size: 2; index to first row - $fr = self::getInt2d($subData, 0) + 1; + $fr = self::getUInt2d($subData, 0) + 1; // offset: 2; size: 2; index to last row - $lr = self::getInt2d($subData, 2) + 1; + $lr = self::getUInt2d($subData, 2) + 1; // offset: 4; size: 1; index to first column $fc = ord($subData[4]); @@ -6764,8 +6793,8 @@ class Xls extends BaseReader implements IReader } // column index to letter - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($fc); - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($lc); + $fc = Cell::stringFromColumnIndex($fc); + $lc = Cell::stringFromColumnIndex($lc); if ($fr == $lr and $fc == $lc) { return "$fc$fr"; @@ -6788,16 +6817,16 @@ class Xls extends BaseReader implements IReader private function readBIFF8CellRangeAddressFixed($subData) { // offset: 0; size: 2; index to first row - $fr = self::getInt2d($subData, 0) + 1; + $fr = self::getUInt2d($subData, 0) + 1; // offset: 2; size: 2; index to last row - $lr = self::getInt2d($subData, 2) + 1; + $lr = self::getUInt2d($subData, 2) + 1; // offset: 4; size: 2; index to first column - $fc = self::getInt2d($subData, 4); + $fc = self::getUInt2d($subData, 4); // offset: 6; size: 2; index to last column - $lc = self::getInt2d($subData, 6); + $lc = self::getUInt2d($subData, 6); // check values if ($fr > $lr || $fc > $lc) { @@ -6805,8 +6834,8 @@ class Xls extends BaseReader implements IReader } // column index to letter - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($fc); - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($lc); + $fc = Cell::stringFromColumnIndex($fc); + $lc = Cell::stringFromColumnIndex($lc); if ($fr == $lr and $fc == $lc) { return "$fc$fr"; @@ -6830,38 +6859,38 @@ class Xls extends BaseReader implements IReader // not just return e.g. 'A1' and not 'A1:A1' ? // offset: 0; size: 2; index to first row (0... 65535) (or offset (-32768... 32767)) - $fr = self::getInt2d($subData, 0) + 1; + $fr = self::getUInt2d($subData, 0) + 1; // offset: 2; size: 2; index to last row (0... 65535) (or offset (-32768... 32767)) - $lr = self::getInt2d($subData, 2) + 1; + $lr = self::getUInt2d($subData, 2) + 1; // offset: 4; size: 2; index to first column or column offset + relative flags // bit: 7-0; mask 0x00FF; column index - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex(0x00FF & self::getInt2d($subData, 4)); + $fc = Cell::stringFromColumnIndex(0x00FF & self::getUInt2d($subData, 4)); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) - if (!(0x4000 & self::getInt2d($subData, 4))) { + if (!(0x4000 & self::getUInt2d($subData, 4))) { $fc = '$' . $fc; } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) - if (!(0x8000 & self::getInt2d($subData, 4))) { + if (!(0x8000 & self::getUInt2d($subData, 4))) { $fr = '$' . $fr; } // offset: 6; size: 2; index to last column or column offset + relative flags // bit: 7-0; mask 0x00FF; column index - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex(0x00FF & self::getInt2d($subData, 6)); + $lc = Cell::stringFromColumnIndex(0x00FF & self::getUInt2d($subData, 6)); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) - if (!(0x4000 & self::getInt2d($subData, 6))) { + if (!(0x4000 & self::getUInt2d($subData, 6))) { $lc = '$' . $lc; } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) - if (!(0x8000 & self::getInt2d($subData, 6))) { + if (!(0x8000 & self::getUInt2d($subData, 6))) { $lr = '$' . $lr; } @@ -6880,36 +6909,39 @@ class Xls extends BaseReader implements IReader */ private function readBIFF8CellRangeAddressB($subData, $baseCell = 'A1') { - list($baseCol, $baseRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($baseCell); - $baseCol = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($baseCol) - 1; + list($baseCol, $baseRow) = Cell::coordinateFromString($baseCell); + $baseCol = Cell::columnIndexFromString($baseCol) - 1; // TODO: if cell range is just a single cell, should this funciton // not just return e.g. 'A1' and not 'A1:A1' ? // offset: 0; size: 2; first row - $frIndex = self::getInt2d($subData, 0); // adjust below + $frIndex = self::getUInt2d($subData, 0); // adjust below // offset: 2; size: 2; relative index to first row (0... 65535) should be treated as offset (-32768... 32767) - $lrIndex = self::getInt2d($subData, 2); // adjust below - - // offset: 4; size: 2; first column with relative/absolute flags - - // bit: 7-0; mask 0x00FF; column index - $fcIndex = 0x00FF & self::getInt2d($subData, 4); + $lrIndex = self::getUInt2d($subData, 2); // adjust below // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) - if (!(0x4000 & self::getInt2d($subData, 4))) { + if (!(0x4000 & self::getUInt2d($subData, 4))) { // absolute column index - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($fcIndex); + // offset: 4; size: 2; first column with relative/absolute flags + // bit: 7-0; mask 0x00FF; column index + $fcIndex = 0x00FF & self::getUInt2d($subData, 4); + $fc = Cell::stringFromColumnIndex($fcIndex); $fc = '$' . $fc; } else { // column offset - $fcIndex = ($fcIndex <= 127) ? $fcIndex : $fcIndex - 256; - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $fcIndex); + // offset: 4; size: 2; first column with relative/absolute flags + // bit: 7-0; mask 0x00FF; column index + $relativeFcIndex = 0x00FF & self::getInt2d($subData, 4); + $fcIndex = $baseCol + $relativeFcIndex; + $fcIndex = ($fcIndex < 256) ? $fcIndex : $fcIndex - 256; + $fcIndex = ($fcIndex >= 0) ? $fcIndex : $fcIndex + 256; + $fc = Cell::stringFromColumnIndex($fcIndex); } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) - if (!(0x8000 & self::getInt2d($subData, 4))) { + if (!(0x8000 & self::getUInt2d($subData, 4))) { // absolute row index $fr = $frIndex + 1; $fr = '$' . $fr; @@ -6919,26 +6951,29 @@ class Xls extends BaseReader implements IReader $fr = $baseRow + $frIndex; } - // offset: 6; size: 2; last column with relative/absolute flags - - // bit: 7-0; mask 0x00FF; column index - $lcIndex = 0x00FF & self::getInt2d($subData, 6); - $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256; - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $lcIndex); + $lc = Cell::stringFromColumnIndex($baseCol + $lcIndex); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) - if (!(0x4000 & self::getInt2d($subData, 6))) { + if (!(0x4000 & self::getUInt2d($subData, 6))) { // absolute column index - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($lcIndex); + // offset: 6; size: 2; last column with relative/absolute flags + // bit: 7-0; mask 0x00FF; column index + $lcIndex = 0x00FF & self::getUInt2d($subData, 6); + $lc = Cell::stringFromColumnIndex($lcIndex); $lc = '$' . $lc; } else { // column offset - $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256; - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $lcIndex); + // offset: 4; size: 2; first column with relative/absolute flags + // bit: 7-0; mask 0x00FF; column index + $relativeLcIndex = 0x00FF & self::getInt2d($subData, 4); + $lcIndex = $baseCol + $relativeLcIndex; + $lcIndex = ($lcIndex < 256) ? $lcIndex : $lcIndex - 256; + $lcIndex = ($lcIndex >= 0) ? $lcIndex : $lcIndex + 256; + $lc = Cell::stringFromColumnIndex($lcIndex); } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) - if (!(0x8000 & self::getInt2d($subData, 6))) { + if (!(0x8000 & self::getUInt2d($subData, 6))) { // absolute row index $lr = $lrIndex + 1; $lr = '$' . $lr; @@ -6964,7 +6999,7 @@ class Xls extends BaseReader implements IReader $cellRangeAddresses = []; // offset: 0; size: 2; number of the following cell range addresses - $nm = self::getInt2d($subData, 0); + $nm = self::getUInt2d($subData, 0); $offset = 2; // offset: 2; size: 8 * $nm; list of $nm (fixed) cell range addresses @@ -6992,7 +7027,7 @@ class Xls extends BaseReader implements IReader $cellRangeAddresses = []; // offset: 0; size: 2; number of the following cell range addresses - $nm = self::getInt2d($subData, 0); + $nm = self::getUInt2d($subData, 0); $offset = 2; // offset: 2; size: 6 * $nm; list of $nm (fixed) cell range addresses @@ -7049,7 +7084,7 @@ class Xls extends BaseReader implements IReader // todo: check if we have identified the whole set of special characters // it seems that the following characters are not accepted for sheet names // and we may assume that they are not present: []*/:\? - if (preg_match("/[ !\"@#£$%&{()}<>=+'|^,;-]/", $sheetRange)) { + if (preg_match("/[ !\"@#£$%&{()}<>=+'|^,;-]/u", $sheetRange)) { $sheetRange = "'$sheetRange'"; } @@ -7080,7 +7115,7 @@ class Xls extends BaseReader implements IReader $nc = ord($arrayData[0]); // offset: 1; size: 2; number of rows decreased by 1 - $nr = self::getInt2d($arrayData, 1); + $nr = self::getUInt2d($arrayData, 1); $size = 3; // initialize $arrayData = substr($arrayData, 3); @@ -7214,7 +7249,7 @@ class Xls extends BaseReader implements IReader private function readByteStringLong($subData) { // offset: 0; size: 2; length of the string (character count) - $ln = self::getInt2d($subData, 0); + $ln = self::getUInt2d($subData, 0); // offset: 2: size: var; character array (8-bit characters) $value = $this->decodeCodepage(substr($subData, 2)); @@ -7264,7 +7299,7 @@ class Xls extends BaseReader implements IReader $value = ''; // offset: 0: size: 2; length of the string (character count) - $characterCount = self::getInt2d($subData, 0); + $characterCount = self::getUInt2d($subData, 0); $string = self::readUnicodeString(substr($subData, 2), $characterCount); @@ -7395,7 +7430,7 @@ class Xls extends BaseReader implements IReader $string = self::uncompressByteString($string); } - return \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($string, 'UTF-8', 'UTF-16LE'); + return StringHelper::convertEncoding($string, 'UTF-8', 'UTF-16LE'); } /** @@ -7425,7 +7460,7 @@ class Xls extends BaseReader implements IReader */ private function decodeCodepage($string) { - return \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($string, 'UTF-8', $this->codepage); + return StringHelper::convertEncoding($string, 'UTF-8', $this->codepage); } /** @@ -7436,11 +7471,24 @@ class Xls extends BaseReader implements IReader * * @return int */ - public static function getInt2d($data, $pos) + public static function getUInt2d($data, $pos) { return ord($data[$pos]) | (ord($data[$pos + 1]) << 8); } + /** + * Read 16-bit signed integer. + * + * @param string $data + * @param int $pos + * + * @return int + */ + public static function getInt2d($data, $pos) + { + return unpack('s', $data[$pos] . $data[$pos + 1])[1]; + } + /** * Read 32-bit signed integer. * @@ -7467,7 +7515,7 @@ class Xls extends BaseReader implements IReader private function parseRichText($is) { - $value = new \PhpOffice\PhpSpreadsheet\RichText(); + $value = new RichText(); $value->createText($is); return $value; diff --git a/src/PhpSpreadsheet/Reader/Xls/Color.php b/src/PhpSpreadsheet/Reader/Xls/Color.php index 32ea6148..6d3d6340 100644 --- a/src/PhpSpreadsheet/Reader/Xls/Color.php +++ b/src/PhpSpreadsheet/Reader/Xls/Color.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls; +use PhpOffice\PhpSpreadsheet\Reader\Xls; + class Color { /** @@ -24,7 +26,7 @@ class Color } // default color table - if ($version == \PhpOffice\PhpSpreadsheet\Reader\Xls::XLS_BIFF8) { + if ($version == Xls::XLS_BIFF8) { return Color\BIFF8::lookup($color); } diff --git a/src/PhpSpreadsheet/Reader/Xls/Escher.php b/src/PhpSpreadsheet/Reader/Xls/Escher.php index fd6ae1d1..a5e337fd 100644 --- a/src/PhpSpreadsheet/Reader/Xls/Escher.php +++ b/src/PhpSpreadsheet/Reader/Xls/Escher.php @@ -2,6 +2,16 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Reader\Xls; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -100,7 +110,7 @@ class Escher // Parse Escher stream while ($this->pos < $this->dataSize) { // offset: 2; size: 2: Record Type - $fbt = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos + 2); + $fbt = Xls::getUInt2d($this->data, $this->pos + 2); switch ($fbt) { case self::DGGCONTAINER: @@ -172,15 +182,15 @@ class Escher private function readDefault() { // offset 0; size: 2; recVer and recInstance - $verInstance = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos); + $verInstance = Xls::getUInt2d($this->data, $this->pos); // offset: 2; size: 2: Record Type - $fbt = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos + 2); + $fbt = Xls::getUInt2d($this->data, $this->pos + 2); // bit: 0-3; mask: 0x000F; recVer $recVer = (0x000F & $verInstance) >> 0; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -192,14 +202,14 @@ class Escher */ private function readDggContainer() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record $this->pos += 8 + $length; // record is a container, read contents - $dggContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer(); + $dggContainer = new DggContainer(); $this->object->setDggContainer($dggContainer); $reader = new self($dggContainer); $reader->load($recordData); @@ -210,7 +220,7 @@ class Escher */ private function readDgg() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -222,14 +232,14 @@ class Escher */ private function readBstoreContainer() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record $this->pos += 8 + $length; // record is a container, read contents - $bstoreContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer(); + $bstoreContainer = new BstoreContainer(); $this->object->setBstoreContainer($bstoreContainer); $reader = new self($bstoreContainer); $reader->load($recordData); @@ -243,16 +253,16 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record $this->pos += 8 + $length; // add BSE to BstoreContainer - $BSE = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE(); + $BSE = new BSE(); $this->object->addBSE($BSE); $BSE->setBLIPType($recInstance); @@ -267,16 +277,16 @@ class Escher $rgbUid = substr($recordData, 2, 16); // offset: 18; size: 2; tag - $tag = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 18); + $tag = Xls::getUInt2d($recordData, 18); // offset: 20; size: 4; size of BLIP in bytes - $size = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($recordData, 20); + $size = Xls::getInt4d($recordData, 20); // offset: 24; size: 4; number of references to this BLIP - $cRef = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($recordData, 24); + $cRef = Xls::getInt4d($recordData, 24); // offset: 28; size: 4; MSOFO file offset - $foDelay = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($recordData, 28); + $foDelay = Xls::getInt4d($recordData, 28); // offset: 32; size: 1; unused1 $unused1 = ord($recordData[32]); @@ -297,7 +307,7 @@ class Escher $blipData = substr($recordData, 36 + $cbName); // record is a container, read contents - $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls\Escher($BSE); + $reader = new self($BSE); $reader->load($blipData); } @@ -309,9 +319,9 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -336,7 +346,7 @@ class Escher // offset: var; size: var; the raw image data $data = substr($recordData, $pos); - $blip = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip(); + $blip = new Blip(); $blip->setData($data); $this->object->setBlip($blip); @@ -350,9 +360,9 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -377,7 +387,7 @@ class Escher // offset: var; size: var; the raw image data $data = substr($recordData, $pos); - $blip = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip(); + $blip = new Blip(); $blip->setData($data); $this->object->setBlip($blip); @@ -391,9 +401,9 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -410,9 +420,9 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -424,7 +434,7 @@ class Escher */ private function readSplitMenuColors() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -436,16 +446,16 @@ class Escher */ private function readDgContainer() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record $this->pos += 8 + $length; // record is a container, read contents - $dgContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer(); + $dgContainer = new DgContainer(); $this->object->setDgContainer($dgContainer); - $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls\Escher($dgContainer); + $reader = new self($dgContainer); $escher = $reader->load($recordData); } @@ -454,7 +464,7 @@ class Escher */ private function readDg() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -468,16 +478,16 @@ class Escher { // context is either context DgContainer or SpgrContainer - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record $this->pos += 8 + $length; // record is a container, read contents - $spgrContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer(); + $spgrContainer = new SpgrContainer(); - if ($this->object instanceof \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer) { + if ($this->object instanceof DgContainer) { // DgContainer $this->object->setSpgrContainer($spgrContainer); } else { @@ -494,11 +504,11 @@ class Escher */ private function readSpContainer() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // add spContainer to spgrContainer - $spContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer(); + $spContainer = new SpContainer(); $this->object->addChild($spContainer); // move stream pointer to next record @@ -514,7 +524,7 @@ class Escher */ private function readSpgr() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -529,9 +539,9 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -546,9 +556,9 @@ class Escher // offset: 0; size: 2; recVer and recInstance // bit: 4-15; mask: 0xFFF0; recInstance - $recInstance = (0xFFF0 & \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos)) >> 4; + $recInstance = (0xFFF0 & Xls::getUInt2d($this->data, $this->pos)) >> 4; - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -560,38 +570,38 @@ class Escher */ private function readClientAnchor() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record $this->pos += 8 + $length; // offset: 2; size: 2; upper-left corner column index (0-based) - $c1 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 2); + $c1 = Xls::getUInt2d($recordData, 2); // offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width - $startOffsetX = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 4); + $startOffsetX = Xls::getUInt2d($recordData, 4); // offset: 6; size: 2; upper-left corner row index (0-based) - $r1 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 6); + $r1 = Xls::getUInt2d($recordData, 6); // offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height - $startOffsetY = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 8); + $startOffsetY = Xls::getUInt2d($recordData, 8); // offset: 10; size: 2; bottom-right corner column index (0-based) - $c2 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 10); + $c2 = Xls::getUInt2d($recordData, 10); // offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width - $endOffsetX = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 12); + $endOffsetX = Xls::getUInt2d($recordData, 12); // offset: 14; size: 2; bottom-right corner row index (0-based) - $r2 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 14); + $r2 = Xls::getUInt2d($recordData, 14); // offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height - $endOffsetY = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 16); + $endOffsetY = Xls::getUInt2d($recordData, 16); // set the start coordinates - $this->object->setStartCoordinates(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c1) . ($r1 + 1)); + $this->object->setStartCoordinates(Cell::stringFromColumnIndex($c1) . ($r1 + 1)); // set the start offsetX $this->object->setStartOffsetX($startOffsetX); @@ -600,7 +610,7 @@ class Escher $this->object->setStartOffsetY($startOffsetY); // set the end coordinates - $this->object->setEndCoordinates(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($c2) . ($r2 + 1)); + $this->object->setEndCoordinates(Cell::stringFromColumnIndex($c2) . ($r2 + 1)); // set the end offsetX $this->object->setEndOffsetX($endOffsetX); @@ -614,7 +624,7 @@ class Escher */ private function readClientData() { - $length = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($this->data, $this->pos + 4); + $length = Xls::getInt4d($this->data, $this->pos + 4); $recordData = substr($this->data, $this->pos + 8, $length); // move stream pointer to next record @@ -637,7 +647,7 @@ class Escher $fopte = substr($data, 6 * $i, 6); // offset: 0; size: 2; opid - $opid = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($fopte, 0); + $opid = Xls::getUInt2d($fopte, 0); // bit: 0-13; mask: 0x3FFF; opid.opid $opidOpid = (0x3FFF & $opid) >> 0; @@ -649,7 +659,7 @@ class Escher $opidFComplex = (0x8000 & $opid) >> 15; // offset: 2; size: 4; the value for this property - $op = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt4d($fopte, 2); + $op = Xls::getInt4d($fopte, 2); if ($opidFComplex) { $complexData = substr($splicedComplexData, 0, $op); diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index a0e98187..5b4b3e92 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -19,6 +19,7 @@ use PhpOffice\PhpSpreadsheet\Style; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; +use XMLReader; use ZipArchive; /** @@ -219,7 +220,7 @@ class Xlsx extends BaseReader implements IReader $fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id')]; - $xml = new \XMLReader(); + $xml = new XMLReader(); $res = $xml->xml( $this->securityScanFile( 'zip://' . File::realpath($pFilename) . '#' . "$dir/$fileWorksheet" @@ -231,12 +232,12 @@ class Xlsx extends BaseReader implements IReader $currCells = 0; while ($xml->read()) { - if ($xml->name == 'row' && $xml->nodeType == \XMLReader::ELEMENT) { + if ($xml->name == 'row' && $xml->nodeType == XMLReader::ELEMENT) { $row = $xml->getAttribute('r'); $tmpInfo['totalRows'] = $row; $tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'], $currCells); $currCells = 0; - } elseif ($xml->name == 'c' && $xml->nodeType == \XMLReader::ELEMENT) { + } elseif ($xml->name == 'c' && $xml->nodeType == XMLReader::ELEMENT) { ++$currCells; } } @@ -696,7 +697,7 @@ class Xlsx extends BaseReader implements IReader // references in formula cells... during the load, all formulae should be correct, // and we're simply bringing the worksheet name in line with the formula, not the // reverse - $docSheet->setTitle((string) $eleSheet['name'], false); + $docSheet->setTitle((string) $eleSheet['name'], false, false); $fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id')]; $xmlSheet = simplexml_load_string( //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" @@ -765,7 +766,7 @@ class Xlsx extends BaseReader implements IReader } } if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr['codeName'])) { - $docSheet->setCodeName((string) $xmlSheet->sheetPr['codeName']); + $docSheet->setCodeName((string) $xmlSheet->sheetPr['codeName'], false); } if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->outlinePr)) { if (isset($xmlSheet->sheetPr->outlinePr['summaryRight']) && @@ -1917,10 +1918,10 @@ class Xlsx extends BaseReader implements IReader if (isset($style->font->vertAlign) && isset($style->font->vertAlign['val'])) { $vertAlign = strtolower((string) $style->font->vertAlign['val']); if ($vertAlign == 'superscript') { - $docStyle->getFont()->setSuperScript(true); + $docStyle->getFont()->setSuperscript(true); } if ($vertAlign == 'subscript') { - $docStyle->getFont()->setSubScript(true); + $docStyle->getFont()->setSubscript(true); } } } @@ -1987,7 +1988,7 @@ class Xlsx extends BaseReader implements IReader $docStyle->getAlignment()->setWrapText(self::boolean((string) $style->alignment['wrapText'])); $docStyle->getAlignment()->setShrinkToFit(self::boolean((string) $style->alignment['shrinkToFit'])); $docStyle->getAlignment()->setIndent((int) ((string) $style->alignment['indent']) > 0 ? (int) ((string) $style->alignment['indent']) : 0); - $docStyle->getAlignment()->setReadorder((int) ((string) $style->alignment['readingOrder']) > 0 ? (int) ((string) $style->alignment['readingOrder']) : 0); + $docStyle->getAlignment()->setReadOrder((int) ((string) $style->alignment['readingOrder']) > 0 ? (int) ((string) $style->alignment['readingOrder']) : 0); } // protection @@ -2068,10 +2069,10 @@ class Xlsx extends BaseReader implements IReader if (isset($run->rPr->vertAlign) && isset($run->rPr->vertAlign['val'])) { $vertAlign = strtolower((string) $run->rPr->vertAlign['val']); if ($vertAlign == 'superscript') { - $objText->getFont()->setSuperScript(true); + $objText->getFont()->setSuperscript(true); } if ($vertAlign == 'subscript') { - $objText->getFont()->setSubScript(true); + $objText->getFont()->setSubscript(true); } } if (isset($run->rPr->u) && !isset($run->rPr->u['val'])) { diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Chart.php b/src/PhpSpreadsheet/Reader/Xlsx/Chart.php index 48564d6d..2c636e45 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/Chart.php @@ -3,6 +3,16 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Chart\DataSeries; +use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; +use PhpOffice\PhpSpreadsheet\Chart\Layout; +use PhpOffice\PhpSpreadsheet\Chart\Legend; +use PhpOffice\PhpSpreadsheet\Chart\PlotArea; +use PhpOffice\PhpSpreadsheet\Chart\Title; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Style\Color; +use PhpOffice\PhpSpreadsheet\Style\Font; +use SimpleXMLElement; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -29,11 +39,11 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Chart { /** - * @param \SimpleXMLElement $component + * @param SimpleXMLElement $component * @param string $name * @param string $format */ - private static function getAttribute(\SimpleXMLElement $component, $name, $format) + private static function getAttribute(SimpleXMLElement $component, $name, $format) { $attributes = $component->attributes(); if (isset($attributes[$name])) { @@ -56,15 +66,15 @@ class Chart if (isset($color['rgb'])) { return (string) $color['rgb']; } elseif (isset($color['indexed'])) { - return \PhpOffice\PhpSpreadsheet\Style\Color::indexedColor($color['indexed'] - 7, $background)->getARGB(); + return Color::indexedColor($color['indexed'] - 7, $background)->getARGB(); } } /** - * @param \SimpleXMLElement $chartElements + * @param SimpleXMLElement $chartElements * @param string $chartName */ - public static function readChart(\SimpleXMLElement $chartElements, $chartName) + public static function readChart(SimpleXMLElement $chartElements, $chartName) { $namespacesChartMeta = $chartElements->getNamespaces(true); $chartElementsC = $chartElements->children($namespacesChartMeta['c']); @@ -164,9 +174,9 @@ class Chart } } if ($plotAreaLayout == null) { - $plotAreaLayout = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); + $plotAreaLayout = new Layout(); } - $plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($plotAreaLayout, $plotSeries); + $plotArea = new PlotArea($plotAreaLayout, $plotSeries); self::setChartAttributes($plotAreaLayout, $plotAttributes); break; case 'plotVisOnly': @@ -195,7 +205,7 @@ class Chart break; } } - $legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend($legendPos, $legendLayout, $legendOverlay); + $legend = new Legend($legendPos, $legendLayout, $legendOverlay); break; } } @@ -206,7 +216,7 @@ class Chart return $chart; } - private static function chartTitle(\SimpleXMLElement $titleDetails, array $namespacesChartMeta) + private static function chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta) { $caption = []; $titleLayout = null; @@ -228,7 +238,7 @@ class Chart } } - return new \PhpOffice\PhpSpreadsheet\Chart\Title($caption, $titleLayout); + return new Title($caption, $titleLayout); } private static function chartLayoutDetails($chartDetail, $namespacesChartMeta) @@ -245,7 +255,7 @@ class Chart $layout[$detailKey] = self::getAttribute($detail, 'val', 'string'); } - return new \PhpOffice\PhpSpreadsheet\Chart\Layout($layout); + return new Layout($layout); } private static function chartDataSeries($chartDetail, $namespacesChartMeta, $plotType) @@ -297,33 +307,33 @@ class Chart } } - return new \PhpOffice\PhpSpreadsheet\Chart\DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine); + return new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine); } - private static function chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null, $smoothLine = false) + private static function chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null) { if (isset($seriesDetail->strRef)) { $seriesSource = (string) $seriesDetail->strRef->f; $seriesData = self::chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']), 's'); - return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); + return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); } elseif (isset($seriesDetail->numRef)) { $seriesSource = (string) $seriesDetail->numRef->f; $seriesData = self::chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c'])); - return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); + return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); } elseif (isset($seriesDetail->multiLvlStrRef)) { $seriesSource = (string) $seriesDetail->multiLvlStrRef->f; $seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']), 's'); $seriesData['pointCount'] = count($seriesData['dataValues']); - return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); + return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); } elseif (isset($seriesDetail->multiLvlNumRef)) { $seriesSource = (string) $seriesDetail->multiLvlNumRef->f; $seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']), 's'); $seriesData['pointCount'] = count($seriesData['dataValues']); - return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); + return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); } return null; @@ -399,9 +409,9 @@ class Chart ]; } - private static function parseRichText(\SimpleXMLElement $titleDetailPart) + private static function parseRichText(SimpleXMLElement $titleDetailPart) { - $value = new \PhpOffice\PhpSpreadsheet\RichText(); + $value = new RichText(); foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) { if (isset($titleDetailElement->t)) { @@ -419,7 +429,7 @@ class Chart $fontColor = (self::getAttribute($titleDetailElement->rPr, 'color', 'string')); if (!is_null($fontColor)) { - $objText->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(self::readColor($fontColor))); + $objText->getFont()->setColor(new Color(self::readColor($fontColor))); } $bold = self::getAttribute($titleDetailElement->rPr, 'b', 'boolean'); @@ -435,20 +445,20 @@ class Chart $baseline = self::getAttribute($titleDetailElement->rPr, 'baseline', 'integer'); if (!is_null($baseline)) { if ($baseline > 0) { - $objText->getFont()->setSuperScript(true); + $objText->getFont()->setSuperscript(true); } elseif ($baseline < 0) { - $objText->getFont()->setSubScript(true); + $objText->getFont()->setSubscript(true); } } $underscore = (self::getAttribute($titleDetailElement->rPr, 'u', 'string')); if (!is_null($underscore)) { if ($underscore == 'sng') { - $objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); + $objText->getFont()->setUnderline(Font::UNDERLINE_SINGLE); } elseif ($underscore == 'dbl') { - $objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE); + $objText->getFont()->setUnderline(Font::UNDERLINE_DOUBLE); } else { - $objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE); + $objText->getFont()->setUnderline(Font::UNDERLINE_NONE); } } @@ -497,10 +507,10 @@ class Chart } /** - * @param \PhpOffice\PhpSpreadsheet\Chart\Layout $plotArea + * @param Layout $plotArea * @param mixed $plotAttributes */ - private static function setChartAttributes(\PhpOffice\PhpSpreadsheet\Chart\Layout $plotArea, $plotAttributes) + private static function setChartAttributes(Layout $plotArea, $plotAttributes) { foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) { switch ($plotAttributeKey) { diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php index 00e29808..d9368d02 100644 --- a/src/PhpSpreadsheet/Reader/Xml.php +++ b/src/PhpSpreadsheet/Reader/Xml.php @@ -2,8 +2,18 @@ namespace PhpOffice\PhpSpreadsheet\Reader; +use DateTimeZone; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Document\Properties; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Settings; +use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Font; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -126,7 +136,7 @@ class Xml extends BaseReader implements IReader $xml = simplexml_load_string( $this->securityScan(file_get_contents($pFilename)), 'SimpleXMLElement', - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $namespaces = $xml->getNamespaces(true); @@ -155,7 +165,7 @@ class Xml extends BaseReader implements IReader $xml = simplexml_load_string( $this->securityScan(file_get_contents($pFilename)), 'SimpleXMLElement', - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $namespaces = $xml->getNamespaces(true); @@ -201,7 +211,7 @@ class Xml extends BaseReader implements IReader } } - $tmpInfo['lastColumnLetter'] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); + $tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; $worksheetInfo[] = $tmpInfo; @@ -218,7 +228,7 @@ class Xml extends BaseReader implements IReader * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ public function load($pFilename) { @@ -288,41 +298,41 @@ class Xml extends BaseReader implements IReader * Loads from file into Spreadsheet instance. * * @param string $pFilename - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ - public function loadIntoExisting($pFilename, \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) { $fromFormats = ['\-', '\ ']; $toFormats = ['-', ' ']; $underlineStyles = [ - \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE, - \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE, - \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLEACCOUNTING, - \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE, - \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLEACCOUNTING, + Font::UNDERLINE_NONE, + Font::UNDERLINE_DOUBLE, + Font::UNDERLINE_DOUBLEACCOUNTING, + Font::UNDERLINE_SINGLE, + Font::UNDERLINE_SINGLEACCOUNTING, ]; $verticalAlignmentStyles = [ - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM, - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP, - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY, + Alignment::VERTICAL_BOTTOM, + Alignment::VERTICAL_TOP, + Alignment::VERTICAL_CENTER, + Alignment::VERTICAL_JUSTIFY, ]; $horizontalAlignmentStyles = [ - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY, + Alignment::HORIZONTAL_GENERAL, + Alignment::HORIZONTAL_LEFT, + Alignment::HORIZONTAL_RIGHT, + Alignment::HORIZONTAL_CENTER, + Alignment::HORIZONTAL_CENTER_CONTINUOUS, + Alignment::HORIZONTAL_JUSTIFY, ]; - $timezoneObj = new \DateTimeZone('Europe/London'); - $GMT = new \DateTimeZone('UTC'); + $timezoneObj = new DateTimeZone('Europe/London'); + $GMT = new DateTimeZone('UTC'); File::assertFile($pFilename); if (!$this->canRead($pFilename)) { @@ -332,7 +342,7 @@ class Xml extends BaseReader implements IReader $xml = simplexml_load_string( $this->securityScan(file_get_contents($pFilename)), 'SimpleXMLElement', - \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions() + Settings::getLibXmlLoaderOptions() ); $namespaces = $xml->getNamespaces(true); @@ -382,26 +392,26 @@ class Xml extends BaseReader implements IReader foreach ($xml->CustomDocumentProperties[0] as $propertyName => $propertyValue) { $propertyAttributes = $propertyValue->attributes($namespaces['dt']); $propertyName = preg_replace_callback('/_x([0-9a-z]{4})_/', ['self', 'hex2str'], $propertyName); - $propertyType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_UNKNOWN; + $propertyType = Properties::PROPERTY_TYPE_UNKNOWN; switch ((string) $propertyAttributes) { case 'string': - $propertyType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_STRING; + $propertyType = Properties::PROPERTY_TYPE_STRING; $propertyValue = trim($propertyValue); break; case 'boolean': - $propertyType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN; + $propertyType = Properties::PROPERTY_TYPE_BOOLEAN; $propertyValue = (bool) $propertyValue; break; case 'integer': - $propertyType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_INTEGER; + $propertyType = Properties::PROPERTY_TYPE_INTEGER; $propertyValue = (int) $propertyValue; break; case 'float': - $propertyType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_FLOAT; + $propertyType = Properties::PROPERTY_TYPE_FLOAT; $propertyValue = (float) $propertyValue; break; case 'dateTime.tz': - $propertyType = \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE; + $propertyType = Properties::PROPERTY_TYPE_DATE; $propertyValue = strtotime(trim($propertyValue)); break; } @@ -431,7 +441,7 @@ class Xml extends BaseReader implements IReader } break; case 'WrapText': - $this->styles[$styleID]['alignment']['wrap'] = true; + $this->styles[$styleID]['alignment']['wrapText'] = true; break; } } @@ -443,7 +453,7 @@ class Xml extends BaseReader implements IReader foreach ($borderAttributes as $borderStyleKey => $borderStyleValue) { switch ($borderStyleKey) { case 'LineStyle': - $thisBorder['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM; + $thisBorder['borderStyle'] = Border::BORDER_MEDIUM; break; case 'Weight': break; @@ -497,7 +507,7 @@ class Xml extends BaseReader implements IReader $this->styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue, 1); break; case 'Pattern': - $this->styles[$styleID]['fill']['type'] = strtolower($styleAttributeValue); + $this->styles[$styleID]['fill']['fillType'] = strtolower($styleAttributeValue); break; } } @@ -511,7 +521,7 @@ class Xml extends BaseReader implements IReader break; } if ($styleAttributeValue > '') { - $this->styles[$styleID]['numberformat']['code'] = $styleAttributeValue; + $this->styles[$styleID]['numberFormat']['formatCode'] = $styleAttributeValue; } } break; @@ -542,7 +552,7 @@ class Xml extends BaseReader implements IReader // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in // formula cells... during the load, all formulae should be correct, and we're simply bringing // the worksheet name in line with the formula, not the reverse - $spreadsheet->getActiveSheet()->setTitle($worksheetName, false); + $spreadsheet->getActiveSheet()->setTitle($worksheetName, false, false); } $columnID = 'A'; @@ -550,7 +560,7 @@ class Xml extends BaseReader implements IReader foreach ($worksheet->Table->Column as $columnData) { $columnData_ss = $columnData->attributes($namespaces['ss']); if (isset($columnData_ss['Index'])) { - $columnID = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnData_ss['Index'] - 1); + $columnID = Cell::stringFromColumnIndex($columnData_ss['Index'] - 1); } if (isset($columnData_ss['Width'])) { $columnWidth = $columnData_ss['Width']; @@ -574,7 +584,7 @@ class Xml extends BaseReader implements IReader foreach ($rowData->Cell as $cell) { $cell_ss = $cell->attributes($namespaces['ss']); if (isset($cell_ss['Index'])) { - $columnID = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($cell_ss['Index'] - 1); + $columnID = Cell::stringFromColumnIndex($cell_ss['Index'] - 1); } $cellRange = $columnID . $rowID; @@ -589,7 +599,7 @@ class Xml extends BaseReader implements IReader $columnTo = $columnID; if (isset($cell_ss['MergeAcross'])) { $additionalMergedCells += (int) $cell_ss['MergeAcross']; - $columnTo = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex(\PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] - 1); + $columnTo = Cell::stringFromColumnIndex(Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] - 1); } $rowTo = $rowID; if (isset($cell_ss['MergeDown'])) { @@ -611,7 +621,7 @@ class Xml extends BaseReader implements IReader } if (isset($cell->Data)) { $cellValue = $cellData = $cell->Data; - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL; + $type = Cell\DataType::TYPE_NULL; $cellData_ss = $cellData->attributes($namespaces['ss']); if (isset($cellData_ss['Type'])) { $cellDataType = $cellData_ss['Type']; @@ -627,32 +637,32 @@ class Xml extends BaseReader implements IReader */ case 'String': $cellValue = self::convertStringEncoding($cellValue, $this->charSet); - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING; + $type = Cell\DataType::TYPE_STRING; break; case 'Number': - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC; + $type = Cell\DataType::TYPE_NUMERIC; $cellValue = (float) $cellValue; if (floor($cellValue) == $cellValue) { $cellValue = (int) $cellValue; } break; case 'Boolean': - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL; + $type = Cell\DataType::TYPE_BOOL; $cellValue = ($cellValue != 0); break; case 'DateTime': - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC; - $cellValue = \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(strtotime($cellValue)); + $type = Cell\DataType::TYPE_NUMERIC; + $cellValue = Date::PHPToExcel(strtotime($cellValue)); break; case 'Error': - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR; + $type = Cell\DataType::TYPE_ERROR; break; } } if ($hasCalculatedValue) { - $type = \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA; - $columnNumber = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($columnID); + $type = Cell\DataType::TYPE_FORMULA; + $columnNumber = Cell::columnIndexFromString($columnID); if (substr($cellDataFormula, 0, 3) == 'of:') { $cellDataFormula = substr($cellDataFormula, 3); $temp = explode('"', $cellDataFormula); @@ -696,7 +706,7 @@ class Xml extends BaseReader implements IReader if ($columnReference[0] == '[') { $columnReference = $columnNumber + trim($columnReference, '[]'); } - $A1CellReference = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; + $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); } } @@ -764,7 +774,7 @@ class Xml extends BaseReader implements IReader protected static function convertStringEncoding($string, $charset) { if ($charset != 'UTF-8') { - return \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($string, 'UTF-8', $charset); + return StringHelper::convertEncoding($string, 'UTF-8', $charset); } return $string; @@ -772,7 +782,7 @@ class Xml extends BaseReader implements IReader protected function parseRichText($is) { - $value = new \PhpOffice\PhpSpreadsheet\RichText(); + $value = new RichText(); $value->createText(self::convertStringEncoding($is, $this->charSet)); diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 30eb9436..5bd291f2 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -807,7 +807,7 @@ class ReferenceHelper /** * Update named formulas (i.e. containing worksheet references / named ranges). * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet Object to update + * @param Spreadsheet $spreadsheet Object to update * @param string $oldName Old name (name to replace) * @param string $newName New name */ diff --git a/src/PhpSpreadsheet/RichText/Run.php b/src/PhpSpreadsheet/RichText/Run.php index 90fc21a9..a4d74173 100644 --- a/src/PhpSpreadsheet/RichText/Run.php +++ b/src/PhpSpreadsheet/RichText/Run.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Style\Font; + /** * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +30,7 @@ class Run extends TextElement implements ITextElement /** * Font. * - * @var \PhpOffice\PhpSpreadsheet\Style\Font + * @var Font */ private $font; @@ -40,13 +43,13 @@ class Run extends TextElement implements ITextElement { // Initialise variables $this->setText($pText); - $this->font = new \PhpOffice\PhpSpreadsheet\Style\Font(); + $this->font = new Font(); } /** * Get font. * - * @return \PhpOffice\PhpSpreadsheet\Style\Font + * @return Font */ public function getFont() { @@ -56,13 +59,13 @@ class Run extends TextElement implements ITextElement /** * Set font. * - * @param \PhpOffice\PhpSpreadsheet\Style\Font $pFont Font + * @param Font $pFont Font * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return ITextElement */ - public function setFont(\PhpOffice\PhpSpreadsheet\Style\Font $pFont = null) + public function setFont(Font $pFont = null) { $this->font = $pFont; diff --git a/src/PhpSpreadsheet/Shared/CodePage.php b/src/PhpSpreadsheet/Shared/CodePage.php index 6e56d231..a6ece3a6 100644 --- a/src/PhpSpreadsheet/Shared/CodePage.php +++ b/src/PhpSpreadsheet/Shared/CodePage.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -32,7 +34,7 @@ class CodePage * * @param int $codePage Microsoft Code Page Indentifier * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return string Code Page Name */ @@ -44,7 +46,7 @@ class CodePage case 437: return 'CP437'; // OEM US case 720: - throw new \PhpOffice\PhpSpreadsheet\Exception('Code page 720 not supported.'); // OEM Arabic + throw new PhpSpreadsheetException('Code page 720 not supported.'); // OEM Arabic case 737: return 'CP737'; // OEM Greek case 775: @@ -146,12 +148,12 @@ class CodePage case 32768: return 'MAC'; // Apple Roman case 32769: - throw new \PhpOffice\PhpSpreadsheet\Exception('Code page 32769 not supported.'); // ANSI Latin I (BIFF2-BIFF3) + throw new PhpSpreadsheetException('Code page 32769 not supported.'); // ANSI Latin I (BIFF2-BIFF3) case 65000: return 'UTF-7'; // Unicode (UTF-7) case 65001: return 'UTF-8'; // Unicode (UTF-8) } - throw new \PhpOffice\PhpSpreadsheet\Exception('Unknown codepage: ' . $codePage); + throw new PhpSpreadsheetException('Unknown codepage: ' . $codePage); } } diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php index a7409e38..185e643a 100644 --- a/src/PhpSpreadsheet/Shared/Date.php +++ b/src/PhpSpreadsheet/Shared/Date.php @@ -2,6 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use DateTimeInterface; +use DateTimeZone; +use PhpOffice\PhpSpreadsheet\Calculation\DateTime; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -112,7 +119,7 @@ class Date /** * Set the Default timezone to use for dates. * - * @param string|\DateTimeZone $timeZone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions + * @param string|DateTimeZone $timeZone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions * * @throws \Exception * @@ -133,12 +140,12 @@ class Date /** * Return the Default timezone being used for dates. * - * @return \DateTimeZone The timezone being used as default for Excel timestamp to PHP DateTime object + * @return DateTimeZone The timezone being used as default for Excel timestamp to PHP DateTime object */ public static function getDefaultTimezone() { if (self::$defaultTimeZone === null) { - self::$defaultTimeZone = new \DateTimeZone('UTC'); + self::$defaultTimeZone = new DateTimeZone('UTC'); } return self::$defaultTimeZone; @@ -147,19 +154,19 @@ class Date /** * Validate a timezone. * - * @param string|\DateTimeZone $timeZone The timezone to validate, either as a timezone string or object + * @param string|DateTimeZone $timeZone The timezone to validate, either as a timezone string or object * * @throws \Exception * - * @return \DateTimeZone The timezone as a timezone object - * @return \DateTimeZone The timezone as a timezone object + * @return DateTimeZone The timezone as a timezone object + * @return DateTimeZone The timezone as a timezone object */ protected static function validateTimeZone($timeZone) { - if (is_object($timeZone) && $timeZone instanceof \DateTimeZone) { + if (is_object($timeZone) && $timeZone instanceof DateTimeZone) { return $timeZone; } elseif (is_string($timeZone)) { - return new \DateTimeZone($timeZone); + return new DateTimeZone($timeZone); } throw new \Exception('Invalid timezone'); } @@ -168,7 +175,7 @@ class Date * Convert a MS serialized datetime value from Excel to a PHP Date/Time object. * * @param int|float $excelTimestamp MS Excel serialized date/time value - * @param \DateTimeZone|string|null $timeZone The timezone to assume for the Excel timestamp, + * @param DateTimeZone|string|null $timeZone The timezone to assume for the Excel timestamp, * if you don't want to treat it as a UTC value * Use the default (UST) unless you absolutely need a conversion * @@ -209,7 +216,7 @@ class Date * Convert a MS serialized datetime value from Excel to a unix timestamp. * * @param int|float $excelTimestamp MS Excel serialized date/time value - * @param \DateTimeZone|string|null $timeZone The timezone to assume for the Excel timestamp, + * @param DateTimeZone|string|null $timeZone The timezone to assume for the Excel timestamp, * if you don't want to treat it as a UTC value * Use the default (UST) unless you absolutely need a conversion * @@ -233,7 +240,7 @@ class Date */ public static function PHPToExcel($dateValue) { - if ((is_object($dateValue)) && ($dateValue instanceof \DateTimeInterface)) { + if ((is_object($dateValue)) && ($dateValue instanceof DateTimeInterface)) { return self::dateTimeToExcel($dateValue); } elseif (is_numeric($dateValue)) { return self::timestampToExcel($dateValue); @@ -247,11 +254,11 @@ class Date /** * Convert a PHP DateTime object to an MS Excel serialized date/time value. * - * @param \DateTimeInterface $dateValue PHP DateTime object + * @param DateTimeInterface $dateValue PHP DateTime object * * @return float MS Excel serialized date/time value */ - public static function dateTimeToExcel(\DateTimeInterface $dateValue) + public static function dateTimeToExcel(DateTimeInterface $dateValue) { return self::formattedPHPToExcel( $dateValue->format('Y'), @@ -266,7 +273,7 @@ class Date /** * Convert a Unix timestamp to an MS Excel serialized date/time value. * - * @param \DateTimeInterface $dateValue Unix Timestamp + * @param DateTimeInterface $dateValue Unix Timestamp * * @return float MS Excel serialized date/time value */ @@ -329,11 +336,11 @@ class Date /** * Is a given cell a date/time? * - * @param \PhpOffice\PhpSpreadsheet\Cell $pCell + * @param Cell $pCell * * @return bool */ - public static function isDateTime(\PhpOffice\PhpSpreadsheet\Cell $pCell) + public static function isDateTime(Cell $pCell) { return self::isDateTimeFormat( $pCell->getWorksheet()->getStyle( @@ -345,11 +352,11 @@ class Date /** * Is a given number format a date/time? * - * @param \PhpOffice\PhpSpreadsheet\Style\NumberFormat $pFormat + * @param NumberFormat $pFormat * * @return bool */ - public static function isDateTimeFormat(\PhpOffice\PhpSpreadsheet\Style\NumberFormat $pFormat) + public static function isDateTimeFormat(NumberFormat $pFormat) { return self::isDateTimeFormatCode($pFormat->getFormatCode()); } @@ -365,7 +372,7 @@ class Date */ public static function isDateTimeFormatCode($pFormatCode) { - if (strtolower($pFormatCode) === strtolower(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_GENERAL)) { + if (strtolower($pFormatCode) === strtolower(NumberFormat::FORMAT_GENERAL)) { // "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check) return false; } @@ -377,28 +384,28 @@ class Date // Switch on formatcode switch ($pFormatCode) { // Explicitly defined date formats - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DMYSLASH: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DMYMINUS: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DMMINUS: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_MYMINUS: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME1: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME2: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME3: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME5: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME6: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME7: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME8: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDDSLASH: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX14: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX15: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX16: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX17: - case \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_XLSX22: + case NumberFormat::FORMAT_DATE_YYYYMMDD: + case NumberFormat::FORMAT_DATE_YYYYMMDD2: + case NumberFormat::FORMAT_DATE_DDMMYYYY: + case NumberFormat::FORMAT_DATE_DMYSLASH: + case NumberFormat::FORMAT_DATE_DMYMINUS: + case NumberFormat::FORMAT_DATE_DMMINUS: + case NumberFormat::FORMAT_DATE_MYMINUS: + case NumberFormat::FORMAT_DATE_DATETIME: + case NumberFormat::FORMAT_DATE_TIME1: + case NumberFormat::FORMAT_DATE_TIME2: + case NumberFormat::FORMAT_DATE_TIME3: + case NumberFormat::FORMAT_DATE_TIME4: + case NumberFormat::FORMAT_DATE_TIME5: + case NumberFormat::FORMAT_DATE_TIME6: + case NumberFormat::FORMAT_DATE_TIME7: + case NumberFormat::FORMAT_DATE_TIME8: + case NumberFormat::FORMAT_DATE_YYYYMMDDSLASH: + case NumberFormat::FORMAT_DATE_XLSX14: + case NumberFormat::FORMAT_DATE_XLSX15: + case NumberFormat::FORMAT_DATE_XLSX16: + case NumberFormat::FORMAT_DATE_XLSX17: + case NumberFormat::FORMAT_DATE_XLSX22: return true; } @@ -446,15 +453,15 @@ class Date return false; } - $dateValueNew = \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATEVALUE($dateValue); + $dateValueNew = DateTime::DATEVALUE($dateValue); - if ($dateValueNew === \PhpOffice\PhpSpreadsheet\Calculation\Functions::VALUE()) { + if ($dateValueNew === Functions::VALUE()) { return false; } if (strpos($dateValue, ':') !== false) { - $timeValue = \PhpOffice\PhpSpreadsheet\Calculation\DateTime::TIMEVALUE($dateValue); - if ($timeValue === \PhpOffice\PhpSpreadsheet\Calculation\Functions::VALUE()) { + $timeValue = DateTime::TIMEVALUE($dateValue); + if ($timeValue === Functions::VALUE()) { return false; } $dateValueNew += $timeValue; diff --git a/src/PhpSpreadsheet/Shared/Drawing.php b/src/PhpSpreadsheet/Shared/Drawing.php index 436112be..0f88b8d7 100644 --- a/src/PhpSpreadsheet/Shared/Drawing.php +++ b/src/PhpSpreadsheet/Shared/Drawing.php @@ -70,13 +70,13 @@ class Drawing $name = $pDefaultFont->getName(); $size = $pDefaultFont->getSize(); - if (isset(\PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths[$name][$size])) { + if (isset(Font::$defaultColumnWidths[$name][$size])) { // Exact width can be determined - $colWidth = $pValue * \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths[$name][$size]['width'] / \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths[$name][$size]['px']; + $colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['width'] / Font::$defaultColumnWidths[$name][$size]['px']; } else { // We don't have data for this particular font and size, use approximation by // extrapolating from Calibri 11 - $colWidth = $pValue * 11 * \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths['Calibri'][11]['width'] / \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths['Calibri'][11]['px'] / $size; + $colWidth = $pValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width'] / Font::$defaultColumnWidths['Calibri'][11]['px'] / $size; } return $colWidth; @@ -96,13 +96,13 @@ class Drawing $name = $pDefaultFont->getName(); $size = $pDefaultFont->getSize(); - if (isset(\PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths[$name][$size])) { + if (isset(Font::$defaultColumnWidths[$name][$size])) { // Exact width can be determined - $colWidth = $pValue * \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths[$name][$size]['px'] / \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths[$name][$size]['width']; + $colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['px'] / Font::$defaultColumnWidths[$name][$size]['width']; } else { // We don't have data for this particular font and size, use approximation by // extrapolating from Calibri 11 - $colWidth = $pValue * $size * \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths['Calibri'][11]['px'] / \PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths['Calibri'][11]['width'] / 11; + $colWidth = $pValue * $size * Font::$defaultColumnWidths['Calibri'][11]['px'] / Font::$defaultColumnWidths['Calibri'][11]['width'] / 11; } // Round pixels to closest integer diff --git a/src/PhpSpreadsheet/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php b/src/PhpSpreadsheet/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php index c2b6787a..cf5cef72 100644 --- a/src/PhpSpreadsheet/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php +++ b/src/PhpSpreadsheet/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,7 +31,7 @@ class SpContainer /** * Parent Shape Group Container. * - * @var \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer + * @var SpgrContainer */ private $parent; @@ -113,7 +115,7 @@ class SpContainer /** * Set parent Shape Group Container. * - * @param \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer $parent + * @param SpgrContainer $parent */ public function setParent($parent) { @@ -123,7 +125,7 @@ class SpContainer /** * Get the parent Shape Group Container. * - * @return \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer + * @return SpgrContainer */ public function getParent() { @@ -379,7 +381,7 @@ class SpContainer $nestingLevel = 0; $parent = $this->getParent(); - while ($parent instanceof \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer) { + while ($parent instanceof SpgrContainer) { ++$nestingLevel; $parent = $parent->getParent(); } diff --git a/src/PhpSpreadsheet/Shared/File.php b/src/PhpSpreadsheet/Shared/File.php index 9efd83ff..3b7b64ba 100644 --- a/src/PhpSpreadsheet/Shared/File.php +++ b/src/PhpSpreadsheet/Shared/File.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use InvalidArgumentException; use ZipArchive; /** @@ -151,16 +152,16 @@ class File * * @param string $filename * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public static function assertFile($filename) { if (!is_file($filename)) { - throw new \InvalidArgumentException('File "' . $filename . '" does not exist.'); + throw new InvalidArgumentException('File "' . $filename . '" does not exist.'); } if (!is_readable($filename)) { - throw new \InvalidArgumentException('Could not open "' . $filename . '" for reading.'); + throw new InvalidArgumentException('Could not open "' . $filename . '" for reading.'); } } } diff --git a/src/PhpSpreadsheet/Shared/Font.php b/src/PhpSpreadsheet/Shared/Font.php index befc2751..33ce9ace 100644 --- a/src/PhpSpreadsheet/Shared/Font.php +++ b/src/PhpSpreadsheet/Shared/Font.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\RichText; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -236,7 +239,7 @@ class Font * Calculate an (approximate) OpenXML column width, based on font size and text contained. * * @param \PhpOffice\PhpSpreadsheet\Style\Font $font Font object - * @param \PhpOffice\PhpSpreadsheet\RichText|string $cellText Text to calculate width + * @param RichText|string $cellText Text to calculate width * @param int $rotation Rotation angle * @param \PhpOffice\PhpSpreadsheet\Style\Font|null $defaultFont Font object * @@ -245,7 +248,7 @@ class Font public static function calculateColumnWidth(\PhpOffice\PhpSpreadsheet\Style\Font $font, $cellText = '', $rotation = 0, \PhpOffice\PhpSpreadsheet\Style\Font $defaultFont = null) { // If it is rich text, use plain text - if ($cellText instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if ($cellText instanceof RichText) { $cellText = $cellText->getPlainText(); } @@ -268,7 +271,7 @@ class Font // Width of text in pixels excl. padding // and addition because Excel adds some padding, just use approx width of 'n' glyph $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + $columnWidthAdjust; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { $approximate = true; } } @@ -294,14 +297,14 @@ class Font * @param \PhpOffice\PhpSpreadsheet\Style\Font * @param int $rotation * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return int */ public static function getTextWidthPixelsExact($text, \PhpOffice\PhpSpreadsheet\Style\Font $font, $rotation = 0) { if (!function_exists('imagettfbbox')) { - throw new \PhpOffice\PhpSpreadsheet\Exception('GD library needs to be enabled'); + throw new PhpSpreadsheetException('GD library needs to be enabled'); } // font size should really be supplied in pixels in GD2, @@ -421,7 +424,7 @@ class Font public static function getTrueTypeFontFileFromFont($font) { if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Valid directory to TrueType Font files not specified'); + throw new PhpSpreadsheetException('Valid directory to TrueType Font files not specified'); } $name = $font->getName(); @@ -510,7 +513,7 @@ class Font ); break; default: - throw new \PhpOffice\PhpSpreadsheet\Exception('Unknown font name "' . $name . '". Cannot map to TrueType font file'); + throw new PhpSpreadsheetException('Unknown font name "' . $name . '". Cannot map to TrueType font file'); break; } @@ -518,7 +521,7 @@ class Font // Check if file actually exists if (!file_exists($fontFile)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('TrueType Font file not found'); + throw new PhpSpreadsheetException('TrueType Font file not found'); } return $fontFile; diff --git a/src/PhpSpreadsheet/Shared/JAMA/CholeskyDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/CholeskyDecomposition.php index 99d20d8f..6cf68ced 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/CholeskyDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/CholeskyDecomposition.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared\JAMA; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; + /** * Cholesky decomposition class. * @@ -137,8 +139,8 @@ class CholeskyDecomposition return new Matrix($X, $this->m, $nx); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MatrixSPDException)); + throw new CalculationException(Matrix::MATRIX_SPD_EXCEPTION); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MATRIX_DIMENSION_EXCEPTION)); + throw new CalculationException(Matrix::MATRIX_DIMENSION_EXCEPTION); } } diff --git a/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php index 094ded83..93e9fd58 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php @@ -778,7 +778,7 @@ class EigenvalueDecomposition } } - // end hqr2 + // end hqr2 /** * Constructor: Check for symmetry, then construct the eigenvalue decomposition. diff --git a/src/PhpSpreadsheet/Shared/JAMA/LUDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/LUDecomposition.php index bf4b1636..624e39f1 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/LUDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/LUDecomposition.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared\JAMA; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; + /** * For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n * unit lower triangular matrix L, an n-by-n upper triangular matrix U, @@ -124,7 +126,7 @@ class LUDecomposition } } } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(Matrix::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(Matrix::ARGUMENT_TYPE_EXCEPTION); } } @@ -233,7 +235,7 @@ class LUDecomposition return $d; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(Matrix::MATRIX_DIMENSION_EXCEPTION); + throw new CalculationException(Matrix::MATRIX_DIMENSION_EXCEPTION); } // function det() @@ -243,8 +245,8 @@ class LUDecomposition * * @param $B a Matrix with as many rows as A and any number of columns * - * @throws \PhpOffice\PhpSpreadsheet\Calculation\Exception illegalArgumentException Matrix row dimensions must agree - * @throws \PhpOffice\PhpSpreadsheet\Calculation\Exception runtimeException Matrix is singular + * @throws CalculationException illegalArgumentException Matrix row dimensions must agree + * @throws CalculationException runtimeException Matrix is singular * * @return X so that L*U*X = B(piv,:) */ @@ -277,8 +279,8 @@ class LUDecomposition return $X; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::MATRIX_SINGULAR_EXCEPTION); + throw new CalculationException(self::MATRIX_SINGULAR_EXCEPTION); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::MATRIX_SQUARE_EXCEPTION); + throw new CalculationException(self::MATRIX_SQUARE_EXCEPTION); } } diff --git a/src/PhpSpreadsheet/Shared/JAMA/Matrix.php b/src/PhpSpreadsheet/Shared/JAMA/Matrix.php index c1e096dc..e2f4ffb0 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/Matrix.php +++ b/src/PhpSpreadsheet/Shared/JAMA/Matrix.php @@ -13,6 +13,10 @@ namespace PhpOffice\PhpSpreadsheet\Shared\JAMA; * @license PHP v3.0 * @see http://math.nist.gov/javanumerics/jama/ */ +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; + class Matrix { const POLYMORPHIC_ARGUMENT_EXCEPTION = 'Invalid argument pattern for polymorphic function.'; @@ -20,6 +24,7 @@ class Matrix const ARGUMENT_BOUNDS_EXCEPTION = 'Invalid argument range.'; const MATRIX_DIMENSION_EXCEPTION = 'Matrix dimensions are not equal.'; const ARRAY_LENGTH_EXCEPTION = 'Array length must be a multiple of m.'; + const MATRIX_SPD_EXCEPTION = 'Can only perform operation on symmetric positive definite matrix.'; /** * Matrix storage. @@ -86,15 +91,15 @@ class Matrix } } } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARRAY_LENGTH_EXCEPTION); + throw new CalculationException(self::ARRAY_LENGTH_EXCEPTION); } break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } } @@ -167,12 +172,12 @@ class Matrix if ($i0 >= 0) { $m = $this->m - $i0; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } if ($j0 >= 0) { $n = $this->n - $j0; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } $R = new self($m, $n); for ($i = $i0; $i < $this->m; ++$i) { @@ -189,12 +194,12 @@ class Matrix if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } if (($jF > $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } $R = new self($m + 1, $n + 1); for ($i = $i0; $i <= $iF; ++$i) { @@ -211,12 +216,12 @@ class Matrix if (count($RL) > 0) { $m = count($RL); } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } if (count($CL) > 0) { $n = count($CL); } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } $R = new self($m, $n); for ($i = 0; $i < $m; ++$i) { @@ -233,12 +238,12 @@ class Matrix if (($iF > $i0) && ($this->m >= $iF) && ($i0 >= 0)) { $m = $iF - $i0; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } if (count($CL) > 0) { $n = count($CL); } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } $R = new self($m, $n); for ($i = $i0; $i < $iF; ++$i) { @@ -255,12 +260,12 @@ class Matrix if (count($RL) > 0) { $m = count($RL); } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } if (($jF >= $j0) && ($this->n >= $jF) && ($j0 >= 0)) { $n = $jF - $j0; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_BOUNDS_EXCEPTION); + throw new CalculationException(self::ARGUMENT_BOUNDS_EXCEPTION); } $R = new self($m, $n + 1); for ($i = 0; $i < $m; ++$i) { @@ -272,11 +277,11 @@ class Matrix return $R; break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } } @@ -295,9 +300,9 @@ class Matrix if (($this->m == $B->getRowDimension()) && ($this->n == $B->getColumnDimension())) { return true; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::MATRIX_DIMENSION_EXCEPTION); + throw new CalculationException(self::MATRIX_DIMENSION_EXCEPTION); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } // function checkMatrixDimensions() @@ -376,7 +381,7 @@ class Matrix return $this->getMatrix($i0, 0, $i0 + 1, $this->n); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } /** @@ -398,7 +403,7 @@ class Matrix return $this->getMatrix(0, $j0, $this->m, $j0 + 1); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } /** @@ -470,14 +475,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -489,7 +494,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -511,14 +516,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -528,23 +533,23 @@ class Matrix $value = $M->get($i, $j); if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { $this->A[$i][$j] = trim($this->A[$i][$j], '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]); + $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); } if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { $value = trim($value, '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value); + $validValues &= StringHelper::convertToNumberIfFraction($value); } if ($validValues) { $this->A[$i][$j] += $value; } else { - $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN(); + $this->A[$i][$j] = Functions::NAN(); } } } return $this; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -566,14 +571,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -585,7 +590,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -607,14 +612,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -624,23 +629,23 @@ class Matrix $value = $M->get($i, $j); if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { $this->A[$i][$j] = trim($this->A[$i][$j], '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]); + $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); } if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { $value = trim($value, '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value); + $validValues &= StringHelper::convertToNumberIfFraction($value); } if ($validValues) { $this->A[$i][$j] -= $value; } else { - $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN(); + $this->A[$i][$j] = Functions::NAN(); } } } return $this; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -663,14 +668,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -682,7 +687,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -705,14 +710,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -722,23 +727,23 @@ class Matrix $value = $M->get($i, $j); if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { $this->A[$i][$j] = trim($this->A[$i][$j], '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]); + $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); } if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { $value = trim($value, '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value); + $validValues &= StringHelper::convertToNumberIfFraction($value); } if ($validValues) { $this->A[$i][$j] *= $value; } else { - $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN(); + $this->A[$i][$j] = Functions::NAN(); } } } return $this; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -761,14 +766,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -778,11 +783,11 @@ class Matrix $value = $M->get($i, $j); if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { $this->A[$i][$j] = trim($this->A[$i][$j], '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]); + $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); } if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { $value = trim($value, '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value); + $validValues &= StringHelper::convertToNumberIfFraction($value); } if ($validValues) { if ($value == 0) { @@ -792,14 +797,14 @@ class Matrix $M->set($i, $j, $this->A[$i][$j] / $value); } } else { - $M->set($i, $j, \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN()); + $M->set($i, $j, Functions::NAN()); } } } return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -822,14 +827,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -841,7 +846,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -864,14 +869,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -883,7 +888,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -906,14 +911,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -925,7 +930,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -947,7 +952,7 @@ class Matrix if ($args[0] instanceof self) { $B = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } if ($this->n == $B->m) { $C = new self($this->m, $B->n); @@ -967,7 +972,7 @@ class Matrix return $C; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MatrixDimensionMismatch)); + throw new CalculationException(self::MATRIX_DIMENSION_EXCEPTION); case 'array': $B = new self($args[0]); if ($this->n == $B->m) { @@ -984,7 +989,7 @@ class Matrix return $C; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MatrixDimensionMismatch)); + throw new CalculationException(self::MATRIX_DIMENSION_EXCEPTION); case 'integer': $C = new self($this->A); for ($i = 0; $i < $C->m; ++$i) { @@ -1013,10 +1018,10 @@ class Matrix return $C; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } } @@ -1039,14 +1044,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -1056,23 +1061,23 @@ class Matrix $value = $M->get($i, $j); if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { $this->A[$i][$j] = trim($this->A[$i][$j], '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($this->A[$i][$j]); + $validValues &= StringHelper::convertToNumberIfFraction($this->A[$i][$j]); } if ((is_string($value)) && (strlen($value) > 0) && (!is_numeric($value))) { $value = trim($value, '"'); - $validValues &= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertToNumberIfFraction($value); + $validValues &= StringHelper::convertToNumberIfFraction($value); } if ($validValues) { $this->A[$i][$j] = pow($this->A[$i][$j], $value); } else { - $this->A[$i][$j] = \PhpOffice\PhpSpreadsheet\Calculation\Functions::NAN(); + $this->A[$i][$j] = Functions::NAN(); } } } return $this; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -1094,14 +1099,14 @@ class Matrix if ($args[0] instanceof self) { $M = $args[0]; } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(self::ARGUMENT_TYPE_EXCEPTION); } break; case 'array': $M = new self($args[0]); break; default: - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); break; } $this->checkMatrixDimensions($M); @@ -1113,7 +1118,7 @@ class Matrix return $this; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** diff --git a/src/PhpSpreadsheet/Shared/JAMA/QRDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/QRDecomposition.php index 21644dab..55beef8b 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/QRDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/QRDecomposition.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared\JAMA; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; + /** * For an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n * orthogonal matrix Q and an n-by-n upper triangular matrix R so that @@ -95,7 +97,7 @@ class QRDecomposition $this->Rdiag[$k] = -$nrm; } } else { - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(Matrix::ARGUMENT_TYPE_EXCEPTION); + throw new CalculationException(Matrix::ARGUMENT_TYPE_EXCEPTION); } } @@ -246,8 +248,8 @@ class QRDecomposition return $X->getMatrix(0, $this->n - 1, 0, $nx); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::MATRIX_RANK_EXCEPTION); + throw new CalculationException(self::MATRIX_RANK_EXCEPTION); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(Matrix::MATRIX_DIMENSION_EXCEPTION); + throw new CalculationException(Matrix::MATRIX_DIMENSION_EXCEPTION); } } diff --git a/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php index cfd20113..9d383202 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php @@ -436,8 +436,6 @@ class SingularValueDecomposition } // end while } - // end constructor - /** * Return the left singular vectors. * diff --git a/src/PhpSpreadsheet/Shared/JAMA/utils/Error.php b/src/PhpSpreadsheet/Shared/JAMA/utils/Error.php deleted file mode 100644 index 8aa78c55..00000000 --- a/src/PhpSpreadsheet/Shared/JAMA/utils/Error.php +++ /dev/null @@ -1,79 +0,0 @@ -_file_handle = $fh; $signature = fread($fh, 8); if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) { - throw new \PhpOffice\PhpSpreadsheet\Reader\Exception("File doesn't seem to be an OLE container."); + throw new ReaderException("File doesn't seem to be an OLE container."); } fseek($fh, 28); if (fread($fh, 2) != "\xFE\xFF") { // This shouldn't be a problem in practice - throw new \PhpOffice\PhpSpreadsheet\Reader\Exception('Only Little-Endian encoding is supported.'); + throw new ReaderException('Only Little-Endian encoding is supported.'); } // Size of blocks and short blocks in bytes $this->bigBlockSize = pow(2, self::_readInt2($fh)); @@ -212,7 +215,7 @@ class OLE { static $isRegistered = false; if (!$isRegistered) { - stream_wrapper_register('ole-chainedblockstream', \PhpOffice\PhpSpreadsheet\Shared\OLE\ChainedBlockStream::class); + stream_wrapper_register('ole-chainedblockstream', ChainedBlockStream::class); $isRegistered = true; } diff --git a/src/PhpSpreadsheet/Shared/OLE/PPS.php b/src/PhpSpreadsheet/Shared/OLE/PPS.php index fdc3a879..c5b91999 100644 --- a/src/PhpSpreadsheet/Shared/OLE/PPS.php +++ b/src/PhpSpreadsheet/Shared/OLE/PPS.php @@ -20,6 +20,7 @@ namespace PhpOffice\PhpSpreadsheet\Shared\OLE; // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // +use PhpOffice\PhpSpreadsheet\Shared\OLE; /** * Class for creating PPS's for OLE containers. @@ -188,8 +189,8 @@ class PPS . "\xc0\x00\x00\x00" // 92 . "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root . "\x00\x00\x00\x00" // 100 - . \PhpOffice\PhpSpreadsheet\Shared\OLE::localDateToOLE($this->Time1st) // 108 - . \PhpOffice\PhpSpreadsheet\Shared\OLE::localDateToOLE($this->Time2nd) // 116 + . OLE::localDateToOLE($this->Time1st) // 108 + . OLE::localDateToOLE($this->Time2nd) // 116 . pack('V', isset($this->startBlock) ? $this->startBlock : 0) // 120 . pack('V', $this->Size) // 124 . pack('V', 0); // 128 diff --git a/src/PhpSpreadsheet/Shared/OLE/PPS/File.php b/src/PhpSpreadsheet/Shared/OLE/PPS/File.php index 1df6c73f..ffaf7e0c 100644 --- a/src/PhpSpreadsheet/Shared/OLE/PPS/File.php +++ b/src/PhpSpreadsheet/Shared/OLE/PPS/File.php @@ -20,6 +20,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared\OLE\PPS; // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // +use PhpOffice\PhpSpreadsheet\Shared\OLE; +use PhpOffice\PhpSpreadsheet\Shared\OLE\PPS; /** * Class for creating File PPS's for OLE containers. @@ -28,7 +30,7 @@ namespace PhpOffice\PhpSpreadsheet\Shared\OLE\PPS; * * @category PhpSpreadsheet */ -class File extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS +class File extends PPS { /** * The constructor. @@ -39,7 +41,7 @@ class File extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS */ public function __construct($name) { - parent::__construct(null, $name, \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_FILE, null, null, null, null, null, '', []); + parent::__construct(null, $name, OLE::OLE_PPS_TYPE_FILE, null, null, null, null, null, '', []); } /** diff --git a/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php b/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php index 00b5710e..7e411397 100644 --- a/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php +++ b/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php @@ -20,6 +20,9 @@ namespace PhpOffice\PhpSpreadsheet\Shared\OLE\PPS; // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // +use PhpOffice\PhpSpreadsheet\Shared\OLE; +use PhpOffice\PhpSpreadsheet\Shared\OLE\PPS; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; /** * Class for creating Root PPS's for OLE containers. @@ -28,7 +31,7 @@ namespace PhpOffice\PhpSpreadsheet\Shared\OLE\PPS; * * @category PhpSpreadsheet */ -class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS +class Root extends PPS { /** * Directory for temporary files. @@ -46,7 +49,7 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS { $this->_tempDir = \PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir(); - parent::__construct(null, \PhpOffice\PhpSpreadsheet\Shared\OLE::ascToUcs('Root Entry'), \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_ROOT, null, null, null, $time_1st, $time_2nd, null, $raChild); + parent::__construct(null, OLE::ascToUcs('Root Entry'), OLE::OLE_PPS_TYPE_ROOT, null, null, null, $time_1st, $time_2nd, null, $raChild); } /** @@ -58,7 +61,7 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS * * @param string|resource $filename the name of the file or stream where to save the OLE container * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return bool true on success */ @@ -83,17 +86,17 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS $this->_tmp_filename = tempnam($this->tempDirectory, 'OLE_PPS_Root'); $this->_FILEH_ = fopen($this->_tmp_filename, 'w+b'); if ($this->_FILEH_ == false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Can't create temporary file."); + throw new WriterException("Can't create temporary file."); } } else { $this->_FILEH_ = fopen($filename, 'wb'); } if ($this->_FILEH_ == false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Can't open $filename. It may be in use or protected."); + throw new WriterException("Can't open $filename. It may be in use or protected."); } // Make an array of PPS's (for Save) $aList = []; - \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS::_savePpsSetPnt($aList, [$this]); + PPS::_savePpsSetPnt($aList, [$this]); // calculate values for header list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo); // Save Header @@ -131,9 +134,9 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS $iSBcnt = 0; $iCount = count($raList); for ($i = 0; $i < $iCount; ++$i) { - if ($raList[$i]->Type == \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_FILE) { + if ($raList[$i]->Type == OLE::OLE_PPS_TYPE_FILE) { $raList[$i]->Size = $raList[$i]->getDataLen(); - if ($raList[$i]->Size < \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) { + if ($raList[$i]->Size < OLE::OLE_DATA_SIZE_SMALL) { $iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE) + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) ? 1 : 0); } else { @@ -143,12 +146,12 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS } } $iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE; - $iSlCnt = floor($this->_BIG_BLOCK_SIZE / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE); + $iSlCnt = floor($this->_BIG_BLOCK_SIZE / OLE::OLE_LONG_INT_SIZE); $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt) ? 1 : 0); $iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) + (($iSmallLen % $this->_BIG_BLOCK_SIZE) ? 1 : 0)); $iCnt = count($raList); - $iBdCnt = $this->_BIG_BLOCK_SIZE / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_SIZE; + $iBdCnt = $this->_BIG_BLOCK_SIZE / OLE::OLE_PPS_SIZE; $iPPScnt = (floor($iCnt / $iBdCnt) + (($iCnt % $iBdCnt) ? 1 : 0)); return [$iSBDcnt, $iBBcnt, $iPPScnt]; @@ -182,8 +185,8 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS $FILE = $this->_FILEH_; // Calculate Basic Setting - $iBlCnt = $this->_BIG_BLOCK_SIZE / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; - $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; + $iBlCnt = $this->_BIG_BLOCK_SIZE / OLE::OLE_LONG_INT_SIZE; + $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE::OLE_LONG_INT_SIZE; $iBdExL = 0; $iAll = $iBBcnt + $iPPScnt + $iSBDcnt; @@ -263,9 +266,9 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS // cycle through PPS's $iCount = count($raList); for ($i = 0; $i < $iCount; ++$i) { - if ($raList[$i]->Type != \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_DIR) { + if ($raList[$i]->Type != OLE::OLE_PPS_TYPE_DIR) { $raList[$i]->Size = $raList[$i]->getDataLen(); - if (($raList[$i]->Size >= \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) || (($raList[$i]->Type == \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) { + if (($raList[$i]->Size >= OLE::OLE_DATA_SIZE_SMALL) || (($raList[$i]->Type == OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) { fwrite($FILE, $raList[$i]->_data); if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) { @@ -295,11 +298,11 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS $iCount = count($raList); for ($i = 0; $i < $iCount; ++$i) { // Make SBD, small data string - if ($raList[$i]->Type == \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_TYPE_FILE) { + if ($raList[$i]->Type == OLE::OLE_PPS_TYPE_FILE) { if ($raList[$i]->Size <= 0) { continue; } - if ($raList[$i]->Size < \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL) { + if ($raList[$i]->Size < OLE::OLE_DATA_SIZE_SMALL) { $iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE) + (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) ? 1 : 0); // Add to SBD @@ -320,7 +323,7 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS } } } - $iSbCnt = floor($this->_BIG_BLOCK_SIZE / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE); + $iSbCnt = floor($this->_BIG_BLOCK_SIZE / OLE::OLE_LONG_INT_SIZE); if ($iSmBlk % $iSbCnt) { $iB = $iSbCnt - ($iSmBlk % $iSbCnt); for ($i = 0; $i < $iB; ++$i) { @@ -345,9 +348,9 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS } // Adjust for Block $iCnt = count($raList); - $iBCnt = $this->_BIG_BLOCK_SIZE / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_SIZE; + $iBCnt = $this->_BIG_BLOCK_SIZE / OLE::OLE_PPS_SIZE; if ($iCnt % $iBCnt) { - fwrite($this->_FILEH_, str_repeat("\x00", ($iBCnt - ($iCnt % $iBCnt)) * \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_PPS_SIZE)); + fwrite($this->_FILEH_, str_repeat("\x00", ($iBCnt - ($iCnt % $iBCnt)) * OLE::OLE_PPS_SIZE)); } } @@ -362,8 +365,8 @@ class Root extends \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS { $FILE = $this->_FILEH_; // Calculate Basic Setting - $iBbCnt = $this->_BIG_BLOCK_SIZE / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; - $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_LONG_INT_SIZE; + $iBbCnt = $this->_BIG_BLOCK_SIZE / OLE::OLE_LONG_INT_SIZE; + $i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE::OLE_LONG_INT_SIZE; $iBdExL = 0; $iAll = $iBsize + $iPpsCnt + $iSbdSize; diff --git a/src/PhpSpreadsheet/Shared/OLERead.php b/src/PhpSpreadsheet/Shared/OLERead.php index 515a1fa3..ffd3af9d 100644 --- a/src/PhpSpreadsheet/Shared/OLERead.php +++ b/src/PhpSpreadsheet/Shared/OLERead.php @@ -26,16 +26,12 @@ namespace PhpOffice\PhpSpreadsheet\Shared; * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -defined('IDENTIFIER_OLE') || - define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1)); +use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; class OLERead { private $data = ''; - // OLE identifier - const IDENTIFIER_OLE = IDENTIFIER_OLE; - // Size of a sector = 512 bytes const BIG_BLOCK_SIZE = 0x200; @@ -71,7 +67,7 @@ class OLERead * * @param $pFilename string Filename * - * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception + * @throws ReaderException */ public function read($pFilename) { @@ -82,8 +78,9 @@ class OLERead $this->data = file_get_contents($pFilename, false, null, 0, 8); // Check OLE identifier - if ($this->data != self::IDENTIFIER_OLE) { - throw new \PhpOffice\PhpSpreadsheet\Reader\Exception('The filename ' . $pFilename . ' is not recognised as an OLE file'); + $identifierOle = pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1); + if ($this->data != $identifierOle) { + throw new ReaderException('The filename ' . $pFilename . ' is not recognised as an OLE file'); } // Get the file data @@ -303,10 +300,10 @@ class OLERead { if (trim($data) == '') { // No data provided - throw new \PhpOffice\PhpSpreadsheet\Reader\Exception('Parameter data is empty.'); + throw new ReaderException('Parameter data is empty.'); } elseif ($pos < 0) { // Invalid position - throw new \PhpOffice\PhpSpreadsheet\Reader\Exception('Parameter pos=' . $pos . ' is invalid.'); + throw new ReaderException('Parameter pos=' . $pos . ' is invalid.'); } $len = strlen($data); diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index b1d51250..8eb66423 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use PhpOffice\PhpSpreadsheet\Calculation; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -298,11 +300,12 @@ class StringHelper return true; } - public static function buildCharacterSets() + private static function buildCharacterSets() { if (empty(self::$controlCharacters)) { self::buildControlCharacters(); } + if (empty(self::$SYLKCharacters)) { self::buildSYLKCharacters(); } @@ -325,6 +328,8 @@ class StringHelper */ public static function controlCharacterOOXML2PHP($value) { + self::buildCharacterSets(); + return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value); } @@ -345,6 +350,8 @@ class StringHelper */ public static function controlCharacterPHP2OOXML($value) { + self::buildCharacterSets(); + return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value); } @@ -588,7 +595,7 @@ class StringHelper if (preg_match('/^' . self::STRING_REGEXP_FRACTION . '$/i', $operand, $match)) { $sign = ($match[1] == '-') ? '-' : '+'; $fractionFormula = '=' . $sign . $match[2] . $sign . $match[3]; - $operand = \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue($fractionFormula); + $operand = Calculation::getInstance()->_calculateFormulaValue($fractionFormula); return true; } @@ -621,7 +628,7 @@ class StringHelper } /** - * Set the decimal separator. Only used by \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString() + * Set the decimal separator. Only used by NumberFormat::toFormattedString() * to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. * * @param string $pValue Character for decimal separator @@ -654,7 +661,7 @@ class StringHelper } /** - * Set the thousands separator. Only used by \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString() + * Set the thousands separator. Only used by NumberFormat::toFormattedString() * to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. * * @param string $pValue Character for thousands separator @@ -692,7 +699,7 @@ class StringHelper } /** - * Set the currency code. Only used by \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString() + * Set the currency code. Only used by NumberFormat::toFormattedString() * to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. * * @param string $pValue Character for currency code @@ -711,6 +718,8 @@ class StringHelper */ public static function SYLKtoUTF8($pValue) { + self::buildCharacterSets(); + // If there is no escape character in the string there is nothing to do if (strpos($pValue, '') === false) { return $pValue; diff --git a/src/PhpSpreadsheet/Shared/TimeZone.php b/src/PhpSpreadsheet/Shared/TimeZone.php index 46348cae..ac49c282 100644 --- a/src/PhpSpreadsheet/Shared/TimeZone.php +++ b/src/PhpSpreadsheet/Shared/TimeZone.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use DateTimeZone; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -43,7 +46,7 @@ class TimeZone */ private static function validateTimeZone($timezone) { - if (in_array($timezone, \DateTimeZone::listIdentifiers())) { + if (in_array($timezone, DateTimeZone::listIdentifiers())) { return true; } @@ -85,7 +88,7 @@ class TimeZone * @param string $timezone The timezone for finding the adjustment to UST * @param int $timestamp PHP date/time value * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return int Number of seconds for timezone adjustment */ @@ -93,7 +96,7 @@ class TimeZone { if ($timezone !== null) { if (!self::validateTimezone($timezone)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid timezone ' . $timezone); + throw new PhpSpreadsheetException('Invalid timezone ' . $timezone); } } else { $timezone = self::$timezone; @@ -103,7 +106,7 @@ class TimeZone return 0; } - $objTimezone = new \DateTimeZone($timezone); + $objTimezone = new DateTimeZone($timezone); $transitions = $objTimezone->getTransitions($timestamp, $timestamp); return (count($transitions) > 0) ? $transitions[0]['offset'] : 0; diff --git a/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php b/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php index 822a3e70..24d2bd8a 100644 --- a/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php +++ b/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared\Trend; +use PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * diff --git a/src/PhpSpreadsheet/Shared/XMLWriter.php b/src/PhpSpreadsheet/Shared/XMLWriter.php index 8390c765..02ebd99d 100644 --- a/src/PhpSpreadsheet/Shared/XMLWriter.php +++ b/src/PhpSpreadsheet/Shared/XMLWriter.php @@ -2,14 +2,6 @@ namespace PhpOffice\PhpSpreadsheet\Shared; -if (!defined('DATE_W3C')) { - define('DATE_W3C', 'Y-m-d\TH:i:sP'); -} - -if (!defined('DEBUGMODE_ENABLED')) { - define('DEBUGMODE_ENABLED', false); -} - /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -34,6 +26,8 @@ if (!defined('DEBUGMODE_ENABLED')) { */ class XMLWriter extends \XMLWriter { + public static $debugEnabled = false; + /** Temporary storage method */ const STORAGE_MEMORY = 1; const STORAGE_DISK = 2; @@ -71,7 +65,7 @@ class XMLWriter extends \XMLWriter } // Set default values - if (DEBUGMODE_ENABLED) { + if (self::$debugEnabled) { $this->setIndent(true); } } diff --git a/src/PhpSpreadsheet/Shared/Xls.php b/src/PhpSpreadsheet/Shared/Xls.php index de7c29e5..1c8797dc 100644 --- a/src/PhpSpreadsheet/Shared/Xls.php +++ b/src/PhpSpreadsheet/Shared/Xls.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Shared; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -31,7 +34,7 @@ class Xls * x is the width in intrinsic Excel units (measuring width in number of normal characters) * This holds for Arial 10. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $sheet The sheet + * @param Worksheet $sheet The sheet * @param string $col The column * * @return int The width in pixels @@ -48,15 +51,15 @@ class Xls // then we have column dimension with explicit width $columnDimension = $columnDimensions[$col]; $width = $columnDimension->getWidth(); - $pixelWidth = \PhpOffice\PhpSpreadsheet\Shared\Drawing::cellDimensionToPixels($width, $font); + $pixelWidth = Drawing::cellDimensionToPixels($width, $font); } elseif ($sheet->getDefaultColumnDimension()->getWidth() != -1) { // then we have default column dimension with explicit width $defaultColumnDimension = $sheet->getDefaultColumnDimension(); $width = $defaultColumnDimension->getWidth(); - $pixelWidth = \PhpOffice\PhpSpreadsheet\Shared\Drawing::cellDimensionToPixels($width, $font); + $pixelWidth = Drawing::cellDimensionToPixels($width, $font); } else { // we don't even have any default column dimension. Width depends on default font - $pixelWidth = \PhpOffice\PhpSpreadsheet\Shared\Font::getDefaultColumnWidthByFont($font, true); + $pixelWidth = Font::getDefaultColumnWidthByFont($font, true); } // now find the effective column width in pixels @@ -74,7 +77,7 @@ class Xls * the relationship is: y = 4/3x. If the height hasn't been set by the user we * use the default value. If the row is hidden we use a value of zero. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $sheet The sheet + * @param Worksheet $sheet The sheet * @param int $row The row index (1-based) * * @return int The width in pixels @@ -96,11 +99,11 @@ class Xls // then we have a default row dimension with explicit height $defaultRowDimension = $sheet->getDefaultRowDimension(); $rowHeight = $defaultRowDimension->getRowHeight(); - $pixelRowHeight = \PhpOffice\PhpSpreadsheet\Shared\Drawing::pointsToPixels($rowHeight); + $pixelRowHeight = Drawing::pointsToPixels($rowHeight); } else { // we don't even have any default row dimension. Height depends on default font - $pointRowHeight = \PhpOffice\PhpSpreadsheet\Shared\Font::getDefaultRowHeightByFont($font); - $pixelRowHeight = \PhpOffice\PhpSpreadsheet\Shared\Font::fontSizeToPixels($pointRowHeight); + $pointRowHeight = Font::getDefaultRowHeightByFont($font); + $pixelRowHeight = Font::fontSizeToPixels($pointRowHeight); } // now find the effective row height in pixels @@ -117,7 +120,7 @@ class Xls * Get the horizontal distance in pixels between two anchors * The distanceX is found as sum of all the spanning columns widths minus correction for the two offsets. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $sheet + * @param Worksheet $sheet * @param string $startColumn * @param int $startOffsetX Offset within start cell measured in 1/1024 of the cell width * @param string $endColumn @@ -125,15 +128,15 @@ class Xls * * @return int Horizontal measured in pixels */ - public static function getDistanceX(\PhpOffice\PhpSpreadsheet\Worksheet $sheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0) + public static function getDistanceX(Worksheet $sheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0) { $distanceX = 0; // add the widths of the spanning columns - $startColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($startColumn) - 1; // 1-based - $endColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($endColumn) - 1; // 1-based + $startColumnIndex = Cell::columnIndexFromString($startColumn) - 1; // 1-based + $endColumnIndex = Cell::columnIndexFromString($endColumn) - 1; // 1-based for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) { - $distanceX += self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($i)); + $distanceX += self::sizeCol($sheet, Cell::stringFromColumnIndex($i)); } // correct for offsetX in startcell @@ -149,7 +152,7 @@ class Xls * Get the vertical distance in pixels between two anchors * The distanceY is found as sum of all the spanning rows minus two offsets. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $sheet + * @param Worksheet $sheet * @param int $startRow (1-based) * @param int $startOffsetY Offset within start cell measured in 1/256 of the cell height * @param int $endRow (1-based) @@ -157,7 +160,7 @@ class Xls * * @return int Vertical distance measured in pixels */ - public static function getDistanceY(\PhpOffice\PhpSpreadsheet\Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0) + public static function getDistanceY(Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0) { $distanceY = 0; @@ -219,7 +222,7 @@ class Xls * W is the width of the cell * H is the height of the cell * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $sheet + * @param Worksheet $sheet * @param string $coordinates E.g. 'A1' * @param int $offsetX Horizontal offset in pixels * @param int $offsetY Vertical offset in pixels @@ -230,8 +233,8 @@ class Xls */ public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height) { - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($coordinates); - $col_start = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1; + list($column, $row) = Cell::coordinateFromString($coordinates); + $col_start = Cell::columnIndexFromString($column) - 1; $row_start = $row - 1; $x1 = $offsetX; @@ -242,7 +245,7 @@ class Xls $row_end = $row_start; // Row containing bottom right corner of object // Zero the specified offset if greater than the cell dimensions - if ($x1 >= self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start))) { + if ($x1 >= self::sizeCol($sheet, Cell::stringFromColumnIndex($col_start))) { $x1 = 0; } if ($y1 >= self::sizeRow($sheet, $row_start + 1)) { @@ -253,8 +256,8 @@ class Xls $height = $height + $y1 - 1; // Subtract the underlying cell widths to find the end cell of the image - while ($width >= self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end))) { - $width -= self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end)); + while ($width >= self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end))) { + $width -= self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end)); ++$col_end; } @@ -266,10 +269,10 @@ class Xls // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell // with zero height or width. - if (self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start)) == 0) { + if (self::sizeCol($sheet, Cell::stringFromColumnIndex($col_start)) == 0) { return; } - if (self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end)) == 0) { + if (self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end)) == 0) { return; } if (self::sizeRow($sheet, $row_start + 1) == 0) { @@ -280,13 +283,13 @@ class Xls } // Convert the pixel values to the percentage value expected by Excel - $x1 = $x1 / self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start)) * 1024; + $x1 = $x1 / self::sizeCol($sheet, Cell::stringFromColumnIndex($col_start)) * 1024; $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256; - $x2 = ($width + 1) / self::sizeCol($sheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object + $x2 = ($width + 1) / self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object - $startCoordinates = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start) . ($row_start + 1); - $endCoordinates = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end) . ($row_end + 1); + $startCoordinates = Cell::stringFromColumnIndex($col_start) . ($row_start + 1); + $endCoordinates = Cell::stringFromColumnIndex($col_end) . ($row_end + 1); $twoAnchor = [ 'startCoordinates' => $startCoordinates, diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index 2724286b..f78d94d9 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -371,7 +371,7 @@ class Spreadsheet */ public function __construct() { - $this->uniqueID = uniqid(); + $this->uniqueID = uniqid('', true); $this->calculationEngine = new Calculation($this); // Initialise worksheet collection and add one worksheet diff --git a/src/PhpSpreadsheet/Style.php b/src/PhpSpreadsheet/Style.php index 65902077..235d4a15 100644 --- a/src/PhpSpreadsheet/Style.php +++ b/src/PhpSpreadsheet/Style.php @@ -177,20 +177,20 @@ class Style extends Style\Supervisor implements IComparable * 'bold' => true, * 'italic' => false, * 'underline' => \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE, - * 'strike' => false, + * 'strikethrough' => false, * 'color' => array( * 'rgb' => '808080' * ) * ), * 'borders' => array( * 'bottom' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'borderStyle' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) * ), * 'top' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'borderStyle' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) @@ -241,15 +241,15 @@ class Style extends Style\Supervisor implements IComparable // ADVANCED MODE: if ($pAdvanced && isset($pStyles['borders'])) { - // 'allborders' is a shorthand property for 'outline' and 'inside' and + // 'allBorders' is a shorthand property for 'outline' and 'inside' and // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['allborders'])) { + if (isset($pStyles['borders']['allBorders'])) { foreach (['outline', 'inside'] as $component) { if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['allborders']; + $pStyles['borders'][$component] = $pStyles['borders']['allBorders']; } } - unset($pStyles['borders']['allborders']); // not needed any more + unset($pStyles['borders']['allBorders']); // not needed any more } // 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left' // it applies to components that have not been set explicitly @@ -452,8 +452,8 @@ class Style extends Style\Supervisor implements IComparable if (isset($pStyles['alignment'])) { $this->getAlignment()->applyFromArray($pStyles['alignment']); } - if (isset($pStyles['numberformat'])) { - $this->getNumberFormat()->applyFromArray($pStyles['numberformat']); + if (isset($pStyles['numberFormat'])) { + $this->getNumberFormat()->applyFromArray($pStyles['numberFormat']); } if (isset($pStyles['protection'])) { $this->getProtection()->applyFromArray($pStyles['protection']); diff --git a/src/PhpSpreadsheet/Style/Alignment.php b/src/PhpSpreadsheet/Style/Alignment.php index 6ee25160..7f6c171c 100644 --- a/src/PhpSpreadsheet/Style/Alignment.php +++ b/src/PhpSpreadsheet/Style/Alignment.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Alignment extends Supervisor implements IComparable { /* Horizontal alignment styles */ const HORIZONTAL_GENERAL = 'general'; @@ -95,7 +98,7 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara * * @var int */ - protected $readorder = 0; + protected $readOrder = 0; /** * Create a new Alignment. @@ -144,21 +147,20 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray( * array( * 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, * 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, - * 'rotation' => 0, - * 'wrap' => TRUE + * 'textRotation' => 0, + * 'wrapText' => TRUE * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Alignment */ @@ -174,11 +176,11 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara if (isset($pStyles['vertical'])) { $this->setVertical($pStyles['vertical']); } - if (isset($pStyles['rotation'])) { - $this->setTextRotation($pStyles['rotation']); + if (isset($pStyles['textRotation'])) { + $this->setTextRotation($pStyles['textRotation']); } - if (isset($pStyles['wrap'])) { - $this->setWrapText($pStyles['wrap']); + if (isset($pStyles['wrapText'])) { + $this->setWrapText($pStyles['wrapText']); } if (isset($pStyles['shrinkToFit'])) { $this->setShrinkToFit($pStyles['shrinkToFit']); @@ -186,8 +188,8 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara if (isset($pStyles['indent'])) { $this->setIndent($pStyles['indent']); } - if (isset($pStyles['readorder'])) { - $this->setReadorder($pStyles['readorder']); + if (isset($pStyles['readOrder'])) { + $this->setReadOrder($pStyles['readOrder']); } } @@ -287,7 +289,7 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara * * @param int $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Alignment */ @@ -301,13 +303,13 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara // Set rotation if (($pValue >= -90 && $pValue <= 90) || $pValue == -165) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['rotation' => $pValue]); + $styleArray = $this->getStyleArray(['textRotation' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->textRotation = $pValue; } } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Text rotation should be a value between -90 and 90.'); + throw new PhpSpreadsheetException('Text rotation should be a value between -90 and 90.'); } return $this; @@ -340,7 +342,7 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara $pValue = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['wrap' => $pValue]); + $styleArray = $this->getStyleArray(['wrapText' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->wrapText = $pValue; @@ -430,13 +432,13 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara * * @return int */ - public function getReadorder() + public function getReadOrder() { if ($this->isSupervisor) { - return $this->getSharedComponent()->getReadorder(); + return $this->getSharedComponent()->getReadOrder(); } - return $this->readorder; + return $this->readOrder; } /** @@ -446,16 +448,16 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara * * @return Alignment */ - public function setReadorder($pValue) + public function setReadOrder($pValue) { if ($pValue < 0 || $pValue > 2) { $pValue = 0; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['readorder' => $pValue]); + $styleArray = $this->getStyleArray(['readOrder' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->readorder = $pValue; + $this->readOrder = $pValue; } return $this; @@ -479,7 +481,7 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara ($this->wrapText ? 't' : 'f') . ($this->shrinkToFit ? 't' : 'f') . $this->indent . - $this->readorder . + $this->readOrder . __CLASS__ ); } diff --git a/src/PhpSpreadsheet/Style/Border.php b/src/PhpSpreadsheet/Style/Border.php index 9c2d8891..b5169897 100644 --- a/src/PhpSpreadsheet/Style/Border.php +++ b/src/PhpSpreadsheet/Style/Border.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Border extends Supervisor implements IComparable { /* Border style */ const BORDER_NONE = 'none'; @@ -107,7 +110,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * Get the shared style component for the currently active cell in currently active sheet. * Only used for style supervisor. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ @@ -119,7 +122,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable case 'inside': case 'outline': case 'vertical': - throw new \PhpOffice\PhpSpreadsheet\Exception('Cannot get shared component for a pseudo-border.'); + throw new PhpSpreadsheetException('Cannot get shared component for a pseudo-border.'); break; case 'bottom': return $this->parent->getSharedComponent()->getBottom(); @@ -143,22 +146,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable */ public function getStyleArray($array) { - switch ($this->parentPropertyName) { - case 'allborders': - case 'bottom': - case 'diagonal': - case 'horizontal': - case 'inside': - case 'left': - case 'outline': - case 'right': - case 'top': - case 'vertical': - $key = strtolower($this->parentPropertyName); - break; - } - - return $this->parent->getStyleArray([$key => $array]); + return $this->parent->getStyleArray([$this->parentPropertyName => $array]); } /** @@ -167,7 +155,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray( * array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'borderStyle' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) @@ -177,7 +165,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ @@ -186,8 +174,8 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable if ($this->isSupervisor) { $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); } else { - if (isset($pStyles['style'])) { - $this->setBorderStyle($pStyles['style']); + if (isset($pStyles['borderStyle'])) { + $this->setBorderStyle($pStyles['borderStyle']); } if (isset($pStyles['color'])) { $this->getColor()->applyFromArray($pStyles['color']); @@ -228,7 +216,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable $pValue = self::BORDER_MEDIUM; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['style' => $pValue]); + $styleArray = $this->getStyleArray(['borderStyle' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->borderStyle = $pValue; @@ -252,7 +240,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param Color $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ diff --git a/src/PhpSpreadsheet/Style/Borders.php b/src/PhpSpreadsheet/Style/Borders.php index 06268d8b..a23bfb92 100644 --- a/src/PhpSpreadsheet/Style/Borders.php +++ b/src/PhpSpreadsheet/Style/Borders.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Borders extends Supervisor implements IComparable { /* Diagonal directions */ const DIAGONAL_NONE = 0; @@ -75,21 +78,21 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl protected $diagonalDirection; /** - * All borders psedo-border. Only applies to supervisor. + * All borders pseudo-border. Only applies to supervisor. * * @var Border */ protected $allBorders; /** - * Outline psedo-border. Only applies to supervisor. + * Outline pseudo-border. Only applies to supervisor. * * @var Border */ protected $outline; /** - * Inside psedo-border. Only applies to supervisor. + * Inside pseudo-border. Only applies to supervisor. * * @var Border */ @@ -180,18 +183,17 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( * array( * 'bottom' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'borderStyle' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) * ), * 'top' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'borderStyle' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) @@ -202,19 +204,19 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl * * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( * array( - * 'allborders' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'allBorders' => array( + * 'borderStyle' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) * ) * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Borders */ @@ -238,14 +240,14 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl if (isset($pStyles['diagonal'])) { $this->getDiagonal()->applyFromArray($pStyles['diagonal']); } - if (isset($pStyles['diagonaldirection'])) { - $this->setDiagonalDirection($pStyles['diagonaldirection']); + if (isset($pStyles['diagonalDirection'])) { + $this->setDiagonalDirection($pStyles['diagonalDirection']); } - if (isset($pStyles['allborders'])) { - $this->getLeft()->applyFromArray($pStyles['allborders']); - $this->getRight()->applyFromArray($pStyles['allborders']); - $this->getTop()->applyFromArray($pStyles['allborders']); - $this->getBottom()->applyFromArray($pStyles['allborders']); + if (isset($pStyles['allBorders'])) { + $this->getLeft()->applyFromArray($pStyles['allBorders']); + $this->getRight()->applyFromArray($pStyles['allBorders']); + $this->getTop()->applyFromArray($pStyles['allBorders']); + $this->getBottom()->applyFromArray($pStyles['allBorders']); } } @@ -305,14 +307,14 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl /** * Get AllBorders (pseudo-border). Only applies to supervisor. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ public function getAllBorders() { if (!$this->isSupervisor) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Can only get pseudo-border for supervisor.'); + throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.'); } return $this->allBorders; @@ -321,14 +323,14 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl /** * Get Outline (pseudo-border). Only applies to supervisor. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * - * @return bool + * @return Border */ public function getOutline() { if (!$this->isSupervisor) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Can only get pseudo-border for supervisor.'); + throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.'); } return $this->outline; @@ -337,14 +339,14 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl /** * Get Inside (pseudo-border). Only applies to supervisor. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * - * @return bool + * @return Border */ public function getInside() { if (!$this->isSupervisor) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Can only get pseudo-border for supervisor.'); + throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.'); } return $this->inside; @@ -353,14 +355,14 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl /** * Get Vertical (pseudo-border). Only applies to supervisor. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ public function getVertical() { if (!$this->isSupervisor) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Can only get pseudo-border for supervisor.'); + throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.'); } return $this->vertical; @@ -369,14 +371,14 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl /** * Get Horizontal (pseudo-border). Only applies to supervisor. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ public function getHorizontal() { if (!$this->isSupervisor) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Can only get pseudo-border for supervisor.'); + throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.'); } return $this->horizontal; @@ -409,7 +411,7 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl $pValue = self::DIAGONAL_NONE; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['diagonaldirection' => $pValue]); + $styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->diagonalDirection = $pValue; diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 3fdd6308..59578791 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Color extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Color extends Supervisor implements IComparable { /* Colors */ const COLOR_BLACK = 'FF000000'; @@ -124,31 +127,18 @@ class Color extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable */ public function getStyleArray($array) { - switch ($this->parentPropertyName) { - case 'endColor': - $key = 'endcolor'; - break; - case 'color': - $key = 'color'; - break; - case 'startColor': - $key = 'startcolor'; - break; - } - - return $this->parent->getStyleArray([$key => $array]); + return $this->parent->getStyleArray([$this->parentPropertyName => $array]); } /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray( array('rgb' => '808080') ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Color */ diff --git a/src/PhpSpreadsheet/Style/Conditional.php b/src/PhpSpreadsheet/Style/Conditional.php index 84578411..7ce31c31 100644 --- a/src/PhpSpreadsheet/Style/Conditional.php +++ b/src/PhpSpreadsheet/Style/Conditional.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; +use PhpOffice\PhpSpreadsheet\Style; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +28,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Conditional implements \PhpOffice\PhpSpreadsheet\IComparable +class Conditional implements IComparable { /* Condition types */ const CONDITION_NONE = 'none'; @@ -92,7 +96,7 @@ class Conditional implements \PhpOffice\PhpSpreadsheet\IComparable $this->operatorType = self::OPERATOR_NONE; $this->text = null; $this->condition = []; - $this->style = new \PhpOffice\PhpSpreadsheet\Style(false, true); + $this->style = new Style(false, true); } /** @@ -221,13 +225,13 @@ class Conditional implements \PhpOffice\PhpSpreadsheet\IComparable /** * Set Style. * - * @param \PhpOffice\PhpSpreadsheet\Style $pValue + * @param Style $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Conditional */ - public function setStyle(\PhpOffice\PhpSpreadsheet\Style $pValue = null) + public function setStyle(Style $pValue = null) { $this->style = $pValue; diff --git a/src/PhpSpreadsheet/Style/Fill.php b/src/PhpSpreadsheet/Style/Fill.php index 9cbf6841..a9a3111a 100644 --- a/src/PhpSpreadsheet/Style/Fill.php +++ b/src/PhpSpreadsheet/Style/Fill.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Fill extends Supervisor implements IComparable { /* Fill types */ const FILL_NONE = 'none'; @@ -131,25 +134,24 @@ class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getFill()->applyFromArray( * array( - * 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR, + * 'fillType' => Fill::FILL_GRADIENT_LINEAR, * 'rotation' => 0, - * 'startcolor' => array( + * 'startColor' => array( * 'rgb' => '000000' * ), - * 'endcolor' => array( + * 'endColor' => array( * 'argb' => 'FFFFFFFF' * ) * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Fill */ @@ -158,17 +160,17 @@ class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable if ($this->isSupervisor) { $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); } else { - if (isset($pStyles['type'])) { - $this->setFillType($pStyles['type']); + if (isset($pStyles['fillType'])) { + $this->setFillType($pStyles['fillType']); } if (isset($pStyles['rotation'])) { $this->setRotation($pStyles['rotation']); } - if (isset($pStyles['startcolor'])) { - $this->getStartColor()->applyFromArray($pStyles['startcolor']); + if (isset($pStyles['startColor'])) { + $this->getStartColor()->applyFromArray($pStyles['startColor']); } - if (isset($pStyles['endcolor'])) { - $this->getEndColor()->applyFromArray($pStyles['endcolor']); + if (isset($pStyles['endColor'])) { + $this->getEndColor()->applyFromArray($pStyles['endColor']); } if (isset($pStyles['color'])) { $this->getStartColor()->applyFromArray($pStyles['color']); @@ -203,7 +205,7 @@ class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable public function setFillType($pValue) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['type' => $pValue]); + $styleArray = $this->getStyleArray(['fillType' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->fillType = $pValue; @@ -260,7 +262,7 @@ class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param Color $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Fill */ @@ -294,7 +296,7 @@ class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param Color $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Fill */ diff --git a/src/PhpSpreadsheet/Style/Font.php b/src/PhpSpreadsheet/Style/Font.php index 3436382a..d13b3172 100644 --- a/src/PhpSpreadsheet/Style/Font.php +++ b/src/PhpSpreadsheet/Style/Font.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Font extends Supervisor implements IComparable { /* Underline types */ const UNDERLINE_NONE = 'none'; @@ -66,14 +69,14 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @var bool */ - protected $superScript = false; + protected $superscript = false; /** * Subscript. * * @var bool */ - protected $subScript = false; + protected $subscript = false; /** * Underline. @@ -117,8 +120,8 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable $this->size = null; $this->bold = null; $this->italic = null; - $this->superScript = null; - $this->subScript = null; + $this->superscript = null; + $this->subscript = null; $this->underline = null; $this->strikethrough = null; $this->color = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional); @@ -156,7 +159,6 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->applyFromArray( * array( @@ -164,17 +166,17 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * 'bold' => TRUE, * 'italic' => FALSE, * 'underline' => \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE, - * 'strike' => FALSE, + * 'strikethrough' => FALSE, * 'color' => array( * 'rgb' => '808080' * ) * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Font */ @@ -192,17 +194,17 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable if (isset($pStyles['italic'])) { $this->setItalic($pStyles['italic']); } - if (isset($pStyles['superScript'])) { - $this->setSuperScript($pStyles['superScript']); + if (isset($pStyles['superscript'])) { + $this->setSuperscript($pStyles['superscript']); } - if (isset($pStyles['subScript'])) { - $this->setSubScript($pStyles['subScript']); + if (isset($pStyles['subscript'])) { + $this->setSubscript($pStyles['subscript']); } if (isset($pStyles['underline'])) { $this->setUnderline($pStyles['underline']); } - if (isset($pStyles['strike'])) { - $this->setStrikethrough($pStyles['strike']); + if (isset($pStyles['strikethrough'])) { + $this->setStrikethrough($pStyles['strikethrough']); } if (isset($pStyles['color'])) { $this->getColor()->applyFromArray($pStyles['color']); @@ -360,74 +362,74 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable } /** - * Get SuperScript. + * Get Superscript. * * @return bool */ - public function getSuperScript() + public function getSuperscript() { if ($this->isSupervisor) { - return $this->getSharedComponent()->getSuperScript(); + return $this->getSharedComponent()->getSuperscript(); } - return $this->superScript; + return $this->superscript; } /** - * Set SuperScript. + * Set Superscript. * * @param bool $pValue * * @return Font */ - public function setSuperScript($pValue) + public function setSuperscript($pValue) { if ($pValue == '') { $pValue = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['superScript' => $pValue]); + $styleArray = $this->getStyleArray(['superscript' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->superScript = $pValue; - $this->subScript = !$pValue; + $this->superscript = $pValue; + $this->subscript = !$pValue; } return $this; } /** - * Get SubScript. + * Get Subscript. * * @return bool */ - public function getSubScript() + public function getSubscript() { if ($this->isSupervisor) { - return $this->getSharedComponent()->getSubScript(); + return $this->getSharedComponent()->getSubscript(); } - return $this->subScript; + return $this->subscript; } /** - * Set SubScript. + * Set Subscript. * * @param bool $pValue * * @return Font */ - public function setSubScript($pValue) + public function setSubscript($pValue) { if ($pValue == '') { $pValue = false; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['subScript' => $pValue]); + $styleArray = $this->getStyleArray(['subscript' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { - $this->subScript = $pValue; - $this->superScript = !$pValue; + $this->subscript = $pValue; + $this->superscript = !$pValue; } return $this; @@ -524,7 +526,7 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param Color $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Font */ @@ -559,8 +561,8 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable $this->size . ($this->bold ? 't' : 'f') . ($this->italic ? 't' : 'f') . - ($this->superScript ? 't' : 'f') . - ($this->subScript ? 't' : 'f') . + ($this->superscript ? 't' : 'f') . + ($this->subscript ? 't' : 'f') . $this->underline . ($this->strikethrough ? 't' : 'f') . $this->color->getHashCode() . diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 779fb2f9..ecd5778a 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -2,6 +2,12 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +30,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class NumberFormat extends Supervisor implements IComparable { /* Pre-defined formats */ const FORMAT_GENERAL = 'General'; @@ -135,23 +141,22 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp */ public function getStyleArray($array) { - return ['numberformat' => $array]; + return ['numberFormat' => $array]; } /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getNumberFormat()->applyFromArray( * array( - * 'code' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE + * 'formatCode' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return NumberFormat */ @@ -160,8 +165,8 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp if ($this->isSupervisor) { $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); } else { - if (isset($pStyles['code'])) { - $this->setFormatCode($pStyles['code']); + if (isset($pStyles['formatCode'])) { + $this->setFormatCode($pStyles['formatCode']); } } @@ -198,7 +203,7 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp $pValue = self::FORMAT_GENERAL; } if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['code' => $pValue]); + $styleArray = $this->getStyleArray(['formatCode' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->formatCode = $pValue; @@ -232,7 +237,7 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp public function setBuiltInFormatCode($pValue) { if ($this->isSupervisor) { - $styleArray = $this->getStyleArray(['code' => self::builtInFormatCode($pValue)]); + $styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($pValue)]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->builtInFormatCode = $pValue; @@ -493,7 +498,7 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp // escape any quoted characters so that DateTime format() will render them correctly $format = preg_replace_callback('/"(.*)"/U', ['self', 'escapeQuotesCallback'], $format); - $dateObj = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value); + $dateObj = Date::excelToDateTimeObject($value); $value = $dateObj->format($format); } @@ -502,7 +507,7 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp if ($format === self::FORMAT_PERCENTAGE) { $value = round((100 * $value), 0) . '%'; } else { - if (preg_match('/\.[#0]+/i', $format, $m)) { + if (preg_match('/\.[#0]+/', $format, $m)) { $s = substr($m[0], 0, 1) . (strlen($m[0]) - 1); $format = str_replace($m[0], $s, $format); } @@ -524,7 +529,7 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp $decimalLength = strlen($decimalPart); $decimalDivisor = pow(10, $decimalLength); - $GCD = \PhpOffice\PhpSpreadsheet\Calculation\MathTrig::GCD($decimalPart, $decimalDivisor); + $GCD = MathTrig::GCD($decimalPart, $decimalDivisor); $adjustedDecimalPart = $decimalPart / $GCD; $adjustedDecimalDivisor = $decimalDivisor / $GCD; @@ -717,8 +722,8 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp $value = number_format( $value, strlen($right), - \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getDecimalSeparator(), - \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getThousandsSeparator() + StringHelper::getDecimalSeparator(), + StringHelper::getThousandsSeparator() ); $value = preg_replace($number_regex, $value, $format); } else { @@ -741,7 +746,7 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp $currencyCode = $m[1]; list($currencyCode) = explode('-', $currencyCode); if ($currencyCode == '') { - $currencyCode = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::getCurrencyCode(); + $currencyCode = StringHelper::getCurrencyCode(); } $value = preg_replace('/\[\$([^\]]*)\]/u', $currencyCode, $value); } diff --git a/src/PhpSpreadsheet/Style/Protection.php b/src/PhpSpreadsheet/Style/Protection.php index 848ac1be..1ad71588 100644 --- a/src/PhpSpreadsheet/Style/Protection.php +++ b/src/PhpSpreadsheet/Style/Protection.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Style; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Protection extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable +class Protection extends Supervisor implements IComparable { /** Protection styles */ const PROTECTION_INHERIT = 'inherit'; @@ -92,7 +95,6 @@ class Protection extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompar /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray( * array( @@ -100,11 +102,11 @@ class Protection extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompar * 'hidden' => FALSE * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Protection */ diff --git a/src/PhpSpreadsheet/Style/Supervisor.php b/src/PhpSpreadsheet/Style/Supervisor.php index d3b07929..b8c51f65 100644 --- a/src/PhpSpreadsheet/Style/Supervisor.php +++ b/src/PhpSpreadsheet/Style/Supervisor.php @@ -56,7 +56,7 @@ abstract class Supervisor /** * Bind parent. Only used for supervisor. * - * @param \PhpOffice\PhpSpreadsheet\Style $parent + * @param Style $parent * @param null|mixed $parentPropertyName * * @return Supervisor diff --git a/src/PhpSpreadsheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet.php index 4a6799d3..32bcf2ca 100644 --- a/src/PhpSpreadsheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet.php @@ -825,52 +825,54 @@ class Worksheet implements IComparable * Set title. * * @param string $pValue String containing the dimension of this worksheet - * @param string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should + * @param bool $updateFormulaCellReferences Flag indicating whether cell references in formulae should * be updated to reflect the new sheet name. * This should be left as the default true, unless you are * certain that no formula cells on any worksheet contain * references to this worksheet + * @param bool $validate False to skip validation of new title. WARNING: This should only be set + * at parse time (by Readers), where titles can be assumed to be valid. * * @return Worksheet */ - public function setTitle($pValue, $updateFormulaCellReferences = true) + public function setTitle($pValue, $updateFormulaCellReferences = true, $validate = true) { // Is this a 'rename' or not? if ($this->getTitle() == $pValue) { return $this; } - // Syntax check - self::checkSheetTitle($pValue); - // Old title $oldTitle = $this->getTitle(); - if ($this->parent) { - // Is there already such sheet name? - if ($this->parent->sheetNameExists($pValue)) { - // Use name, but append with lowest possible integer + if ($validate) { + // Syntax check + self::checkSheetTitle($pValue); - if (Shared\StringHelper::countCharacters($pValue) > 29) { - $pValue = Shared\StringHelper::substring($pValue, 0, 29); - } - $i = 1; - while ($this->parent->sheetNameExists($pValue . ' ' . $i)) { - ++$i; - if ($i == 10) { - if (Shared\StringHelper::countCharacters($pValue) > 28) { - $pValue = Shared\StringHelper::substring($pValue, 0, 28); - } - } elseif ($i == 100) { - if (Shared\StringHelper::countCharacters($pValue) > 27) { - $pValue = Shared\StringHelper::substring($pValue, 0, 27); + if ($this->parent) { + // Is there already such sheet name? + if ($this->parent->sheetNameExists($pValue)) { + // Use name, but append with lowest possible integer + + if (Shared\StringHelper::countCharacters($pValue) > 29) { + $pValue = Shared\StringHelper::substring($pValue, 0, 29); + } + $i = 1; + while ($this->parent->sheetNameExists($pValue . ' ' . $i)) { + ++$i; + if ($i == 10) { + if (Shared\StringHelper::countCharacters($pValue) > 28) { + $pValue = Shared\StringHelper::substring($pValue, 0, 28); + } + } elseif ($i == 100) { + if (Shared\StringHelper::countCharacters($pValue) > 27) { + $pValue = Shared\StringHelper::substring($pValue, 0, 27); + } } } + + $pValue .= " $i"; } - - $altTitle = $pValue . ' ' . $i; - - return $this->setTitle($altTitle, $updateFormulaCellReferences); } } @@ -1161,7 +1163,6 @@ class Worksheet implements IComparable * @param int $pRow Numeric row coordinate of the cell * @param mixed $pValue Value of the cell * @param string $pDataType Explicit data type, see Cell\DataType::TYPE_* - * @param bool $returnCell Return the worksheet (false, default) or the cell (true) * * @return Worksheet */ @@ -1657,7 +1658,7 @@ class Worksheet implements IComparable * * @param int $pColumn Numeric column coordinate of the cell (A = 0) * @param int $pRow Numeric row coordinate of the cell - * @param int $pBreak Break type (type of \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_*) + * @param int $pBreak Break type (type of Worksheet::BREAK_*) * * @return Worksheet */ @@ -2976,51 +2977,55 @@ class Worksheet implements IComparable /** * Define the code name of the sheet. * - * @param null|string Same rule as Title minus space not allowed (but, like Excel, change silently space to underscore) - * @param null|mixed $pValue + * @param string $pValue Same rule as Title minus space not allowed (but, like Excel, change + * silently space to underscore) + * @param bool $validate False to skip validation of new title. WARNING: This should only be set + * at parse time (by Readers), where titles can be assumed to be valid. * * @throws Exception * * @return objWorksheet */ - public function setCodeName($pValue) + public function setCodeName($pValue, $validate = true) { // Is this a 'rename' or not? if ($this->getCodeName() == $pValue) { return $this; } - $pValue = str_replace(' ', '_', $pValue); //Excel does this automatically without flinching, we are doing the same - // Syntax check - // throw an exception if not valid - self::checkSheetCodeName($pValue); - // We use the same code that setTitle to find a valid codeName else not using a space (Excel don't like) but a '_' + if ($validate) { + $pValue = str_replace(' ', '_', $pValue); //Excel does this automatically without flinching, we are doing the same - if ($this->getParent()) { - // Is there already such sheet name? - if ($this->getParent()->sheetCodeNameExists($pValue)) { - // Use name, but append with lowest possible integer + // Syntax check + // throw an exception if not valid + self::checkSheetCodeName($pValue); - if (Shared\StringHelper::countCharacters($pValue) > 29) { - $pValue = Shared\StringHelper::substring($pValue, 0, 29); - } - $i = 1; - while ($this->getParent()->sheetCodeNameExists($pValue . '_' . $i)) { - ++$i; - if ($i == 10) { - if (Shared\StringHelper::countCharacters($pValue) > 28) { - $pValue = Shared\StringHelper::substring($pValue, 0, 28); - } - } elseif ($i == 100) { - if (Shared\StringHelper::countCharacters($pValue) > 27) { - $pValue = Shared\StringHelper::substring($pValue, 0, 27); + // We use the same code that setTitle to find a valid codeName else not using a space (Excel don't like) but a '_' + + if ($this->getParent()) { + // Is there already such sheet name? + if ($this->getParent()->sheetCodeNameExists($pValue)) { + // Use name, but append with lowest possible integer + + if (Shared\StringHelper::countCharacters($pValue) > 29) { + $pValue = Shared\StringHelper::substring($pValue, 0, 29); + } + $i = 1; + while ($this->getParent()->sheetCodeNameExists($pValue . '_' . $i)) { + ++$i; + if ($i == 10) { + if (Shared\StringHelper::countCharacters($pValue) > 28) { + $pValue = Shared\StringHelper::substring($pValue, 0, 28); + } + } elseif ($i == 100) { + if (Shared\StringHelper::countCharacters($pValue) > 27) { + $pValue = Shared\StringHelper::substring($pValue, 0, 27); + } } } - } - $pValue = $pValue . '_' . $i; // ok, we have a valid name - //codeName is'nt used in formula : no need to call for an update - //return $this->setTitle($altTitle, $updateFormulaCellReferences); + $pValue = $pValue . '_' . $i; // ok, we have a valid name + } } } diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index a9298433..c3d783da 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php @@ -2,6 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\DateTime; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,7 +37,7 @@ class AutoFilter /** * Autofilter Worksheet. * - * @var \PhpOffice\PhpSpreadsheet\Worksheet + * @var Worksheet */ private $workSheet; @@ -51,9 +59,9 @@ class AutoFilter * Create a new AutoFilter. * * @param string $pRange Cell range (i.e. A1:E10) - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet + * @param Worksheet $pSheet */ - public function __construct($pRange = '', \PhpOffice\PhpSpreadsheet\Worksheet $pSheet = null) + public function __construct($pRange = '', Worksheet $pSheet = null) { $this->range = $pRange; $this->workSheet = $pSheet; @@ -62,7 +70,7 @@ class AutoFilter /** * Get AutoFilter Parent Worksheet. * - * @return \PhpOffice\PhpSpreadsheet\Worksheet + * @return Worksheet */ public function getParent() { @@ -72,11 +80,11 @@ class AutoFilter /** * Set AutoFilter Parent Worksheet. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet + * @param Worksheet $pSheet * * @return AutoFilter */ - public function setParent(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet = null) + public function setParent(Worksheet $pSheet = null) { $this->workSheet = $pSheet; @@ -98,7 +106,7 @@ class AutoFilter * * @param string $pRange Cell range (i.e. A1:E10) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter */ @@ -115,7 +123,7 @@ class AutoFilter } elseif (empty($pRange)) { $this->range = ''; } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Autofilter must be set on a range of cells.'); + throw new PhpSpreadsheetException('Autofilter must be set on a range of cells.'); } if (empty($pRange)) { @@ -123,9 +131,9 @@ class AutoFilter $this->columns = []; } else { // Discard any column rules that are no longer valid within this range - list($rangeStart, $rangeEnd) = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($this->range); + list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); foreach ($this->columns as $key => $value) { - $colIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($key); + $colIndex = Cell::columnIndexFromString($key); if (($rangeStart[0] > $colIndex) || ($rangeEnd[0] < $colIndex)) { unset($this->columns[$key]); } @@ -138,7 +146,7 @@ class AutoFilter /** * Get all AutoFilter Columns. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter\Column[] */ @@ -152,20 +160,20 @@ class AutoFilter * * @param string $column Column name (e.g. A) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return int The column offset within the autofilter range */ public function testColumnInRange($column) { if (empty($this->range)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('No autofilter range is defined.'); + throw new PhpSpreadsheetException('No autofilter range is defined.'); } - $columnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column); - list($rangeStart, $rangeEnd) = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($this->range); + $columnIndex = Cell::columnIndexFromString($column); + list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); if (($rangeStart[0] > $columnIndex) || ($rangeEnd[0] < $columnIndex)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Column is outside of current autofilter range.'); + throw new PhpSpreadsheetException('Column is outside of current autofilter range.'); } return $columnIndex - $rangeStart[0]; @@ -176,7 +184,7 @@ class AutoFilter * * @param string $pColumn Column name (e.g. A) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return int The offset of the specified column within the autofilter range */ @@ -190,7 +198,7 @@ class AutoFilter * * @param string $pColumn Column name (e.g. A) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter\Column */ @@ -210,14 +218,14 @@ class AutoFilter * * @param int $pColumnOffset Column offset within range (starting from 0) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter\Column */ public function getColumnByOffset($pColumnOffset) { - list($rangeStart, $rangeEnd) = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($this->range); - $pColumn = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1); + list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); + $pColumn = Cell::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1); return $this->getColumn($pColumn); } @@ -228,7 +236,7 @@ class AutoFilter * @param AutoFilter\Column|string $pColumn * A simple string containing a Column ID like 'A' is permitted * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter */ @@ -239,7 +247,7 @@ class AutoFilter } elseif (is_object($pColumn) && ($pColumn instanceof AutoFilter\Column)) { $column = $pColumn->getColumnIndex(); } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Column is not within the autofilter range.'); + throw new PhpSpreadsheetException('Column is not within the autofilter range.'); } $this->testColumnInRange($column); @@ -259,7 +267,7 @@ class AutoFilter * * @param string $pColumn Column name (e.g. A) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter */ @@ -340,7 +348,7 @@ class AutoFilter } if (is_numeric($cellValue)) { - $dateValue = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($cellValue); + $dateValue = Date::excelToTimestamp($cellValue); if ($cellValue < 1) { // Just the time part $dtVal = date('His', $dateValue); @@ -460,7 +468,7 @@ class AutoFilter } if (is_numeric($cellValue)) { - $dateValue = date('m', \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($cellValue)); + $dateValue = date('m', Date::excelToTimestamp($cellValue)); if (in_array($dateValue, $monthSet)) { return true; } @@ -487,12 +495,12 @@ class AutoFilter */ private function dynamicFilterDateRange($dynamicRuleType, &$filterColumn) { - $rDateType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(); - \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC); + $rDateType = Functions::getReturnDateType(); + Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC); $val = $maxVal = null; $ruleValues = []; - $baseDate = \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATENOW(); + $baseDate = DateTime::DATENOW(); // Calculate start/end dates for the required date range based on current date switch ($dynamicRuleType) { case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK: @@ -525,41 +533,41 @@ class AutoFilter case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_TODAY: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW: - $maxVal = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPtoExcel(strtotime('+1 day', $baseDate)); - $val = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($baseDate); + $maxVal = (int) Date::PHPtoExcel(strtotime('+1 day', $baseDate)); + $val = (int) Date::PHPToExcel($baseDate); break; case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE: - $maxVal = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPtoExcel(strtotime('+1 day', $baseDate)); - $val = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1, date('Y', $baseDate))); + $maxVal = (int) Date::PHPtoExcel(strtotime('+1 day', $baseDate)); + $val = (int) Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1, date('Y', $baseDate))); break; case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISYEAR: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR: - $maxVal = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(gmmktime(0, 0, 0, 31, 12, date('Y', $baseDate))); + $maxVal = (int) Date::PHPToExcel(gmmktime(0, 0, 0, 31, 12, date('Y', $baseDate))); ++$maxVal; - $val = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1, date('Y', $baseDate))); + $val = (int) Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1, date('Y', $baseDate))); break; case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISQUARTER: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER: $thisMonth = date('m', $baseDate); $thisQuarter = floor(--$thisMonth / 3); - $maxVal = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPtoExcel(gmmktime(0, 0, 0, date('t', $baseDate), (1 + $thisQuarter) * 3, date('Y', $baseDate))); + $maxVal = (int) Date::PHPtoExcel(gmmktime(0, 0, 0, date('t', $baseDate), (1 + $thisQuarter) * 3, date('Y', $baseDate))); ++$maxVal; - $val = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1 + $thisQuarter * 3, date('Y', $baseDate))); + $val = (int) Date::PHPToExcel(gmmktime(0, 0, 0, 1, 1 + $thisQuarter * 3, date('Y', $baseDate))); break; case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISMONTH: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH: - $maxVal = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPtoExcel(gmmktime(0, 0, 0, date('t', $baseDate), date('m', $baseDate), date('Y', $baseDate))); + $maxVal = (int) Date::PHPtoExcel(gmmktime(0, 0, 0, date('t', $baseDate), date('m', $baseDate), date('Y', $baseDate))); ++$maxVal; - $val = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate))); + $val = (int) Date::PHPToExcel(gmmktime(0, 0, 0, 1, date('m', $baseDate), date('Y', $baseDate))); break; case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_THISWEEK: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK: case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK: $dayOfWeek = date('w', $baseDate); - $val = (int) \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($baseDate) - $dayOfWeek; + $val = (int) Date::PHPToExcel($baseDate) - $dayOfWeek; $maxVal = $val + 7; break; } @@ -582,7 +590,7 @@ class AutoFilter // Set the rules for identifying rows for hide/show $ruleValues[] = ['operator' => AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL, 'value' => $val]; $ruleValues[] = ['operator' => AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_LESSTHAN, 'value' => $maxVal]; - \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($rDateType); + Functions::setReturnDateType($rDateType); return ['method' => 'filterTestInCustomDataSet', 'arguments' => ['filterRules' => $ruleValues, 'join' => AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND]]; } @@ -590,7 +598,7 @@ class AutoFilter private function calculateTopTenValue($columnID, $startRow, $endRow, $ruleType, $ruleValue) { $range = $columnID . $startRow . ':' . $columnID . $endRow; - $dataValues = \PhpOffice\PhpSpreadsheet\Calculation\Functions::flattenArray($this->workSheet->rangeToArray($range, null, true, false)); + $dataValues = Functions::flattenArray($this->workSheet->rangeToArray($range, null, true, false)); $dataValues = array_filter($dataValues); if ($ruleType == AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) { @@ -605,13 +613,13 @@ class AutoFilter /** * Apply the AutoFilter rules to the AutoFilter Range. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return AutoFilter */ public function showHideRows() { - list($rangeStart, $rangeEnd) = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($this->range); + list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); // The heading row should always be visible $this->workSheet->getRowDimension($rangeStart[1])->setVisible(true); @@ -621,6 +629,7 @@ class AutoFilter $rules = $filterColumn->getRules(); switch ($filterColumn->getFilterType()) { case AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER: + $ruleType = null; $ruleValues = []; // Build a list of the filter value selections foreach ($rules as $rule) { @@ -692,7 +701,6 @@ class AutoFilter $ruleValues = []; // Build a list of the filter value selections foreach ($rules as $rule) { - $ruleType = $rule->getRuleType(); $ruleValue = $rule->getValue(); if (!is_numeric($ruleValue)) { // Convert to a regexp allowing for regexp reserved characters, wildcards and escaped wildcards @@ -721,7 +729,7 @@ class AutoFilter // Number (Average) based // Calculate the average $averageFormula = '=AVERAGE(' . $columnID . ($rangeStart[1] + 1) . ':' . $columnID . $rangeEnd[1] . ')'; - $average = \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->calculateFormula($averageFormula, null, $this->workSheet->getCell('A1')); + $average = Calculation::getInstance()->calculateFormula($averageFormula, null, $this->workSheet->getCell('A1')); // Set above/below rule based on greaterThan or LessTan $operator = ($dynamicRuleType === AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_ABOVEAVERAGE) ? AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_GREATERTHAN diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php b/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php index 305d70bf..11698ff8 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -68,7 +71,7 @@ class Column /** * Autofilter. * - * @var \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter + * @var AutoFilter */ private $parent; @@ -111,9 +114,9 @@ class Column * Create a new Column. * * @param string $pColumn Column (e.g. A) - * @param \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter $pParent Autofilter for this column + * @param AutoFilter $pParent Autofilter for this column */ - public function __construct($pColumn, \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter $pParent = null) + public function __construct($pColumn, AutoFilter $pParent = null) { $this->columnIndex = $pColumn; $this->parent = $pParent; @@ -134,7 +137,7 @@ class Column * * @param string $pColumn Column (e.g. A) * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Column */ @@ -154,7 +157,7 @@ class Column /** * Get this Column's AutoFilter Parent. * - * @return \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter + * @return AutoFilter */ public function getParent() { @@ -168,7 +171,7 @@ class Column * * @return Column */ - public function setParent(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter $pParent = null) + public function setParent(AutoFilter $pParent = null) { $this->parent = $pParent; @@ -190,14 +193,14 @@ class Column * * @param string $pFilterType * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Column */ public function setFilterType($pFilterType) { if (!in_array($pFilterType, self::$filterTypes)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid filter type for column AutoFilter.'); + throw new PhpSpreadsheetException('Invalid filter type for column AutoFilter.'); } $this->filterType = $pFilterType; @@ -220,7 +223,7 @@ class Column * * @param string $pJoin And/Or * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Column */ @@ -229,7 +232,7 @@ class Column // Lowercase And/Or $pJoin = strtolower($pJoin); if (!in_array($pJoin, self::$ruleJoins)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid rule connection for column AutoFilter.'); + throw new PhpSpreadsheetException('Invalid rule connection for column AutoFilter.'); } $this->join = $pJoin; @@ -242,7 +245,7 @@ class Column * * @param string[] $attributes * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Column */ @@ -259,7 +262,7 @@ class Column * @param string $pName Attribute Name * @param string $pValue Attribute Value * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Column */ @@ -299,7 +302,7 @@ class Column /** * Get all AutoFilter Column Rules. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Column\Rule[] */ diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php b/src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php index bdf6fd52..37f52cbf 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -222,7 +225,7 @@ class Rule /** * Autofilter Column. * - * @var \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column + * @var Column */ private $parent = null; @@ -257,9 +260,9 @@ class Rule /** * Create a new Rule. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column $pParent + * @param Column $pParent */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column $pParent = null) + public function __construct(Column $pParent = null) { $this->parent = $pParent; } @@ -279,14 +282,14 @@ class Rule * * @param string $pRuleType see self::AUTOFILTER_RULETYPE_* * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Rule */ public function setRuleType($pRuleType) { if (!in_array($pRuleType, self::$ruleTypes)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid rule type for column AutoFilter Rule.'); + throw new PhpSpreadsheetException('Invalid rule type for column AutoFilter Rule.'); } $this->ruleType = $pRuleType; @@ -309,7 +312,7 @@ class Rule * * @param string|string[] $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Rule */ @@ -328,7 +331,7 @@ class Rule } } if (count($pValue) == 0) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid rule value for column AutoFilter Rule.'); + throw new PhpSpreadsheetException('Invalid rule value for column AutoFilter Rule.'); } // Set the dateTime grouping that we've anticipated $this->setGrouping(self::$dateTimeGroups[$grouping]); @@ -353,7 +356,7 @@ class Rule * * @param string $pOperator see self::AUTOFILTER_COLUMN_RULE_* * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Rule */ @@ -364,7 +367,7 @@ class Rule } if ((!in_array($pOperator, self::$operators)) && (!in_array($pOperator, self::$topTenValue))) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid operator for column AutoFilter Rule.'); + throw new PhpSpreadsheetException('Invalid operator for column AutoFilter Rule.'); } $this->operator = $pOperator; @@ -386,7 +389,7 @@ class Rule * * @param string $pGrouping * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Rule */ @@ -396,7 +399,7 @@ class Rule (!in_array($pGrouping, self::$dateTimeGroups)) && (!in_array($pGrouping, self::$dynamicTypes)) && (!in_array($pGrouping, self::$topTenType))) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid rule type for column AutoFilter Rule.'); + throw new PhpSpreadsheetException('Invalid rule type for column AutoFilter Rule.'); } $this->grouping = $pGrouping; @@ -410,7 +413,7 @@ class Rule * @param string|string[] $pValue * @param string $pGrouping * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Rule */ @@ -431,7 +434,7 @@ class Rule /** * Get this Rule's AutoFilter Column Parent. * - * @return \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column + * @return Column */ public function getParent() { @@ -445,7 +448,7 @@ class Rule * * @return Rule */ - public function setParent(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column $pParent = null) + public function setParent(Column $pParent = null) { $this->parent = $pParent; diff --git a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php index 9f975309..c9a2921d 100644 --- a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +28,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable +class BaseDrawing implements IComparable { /** * Image counter. @@ -135,7 +139,8 @@ class BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable $this->rotation = 0; $this->shadow = new Drawing\Shadow(); - // Set image index++self::$imageCounter; + // Set image index + ++self::$imageCounter; $this->imageIndex = self::$imageCounter; } @@ -210,14 +215,14 @@ class BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable /** * Set Worksheet. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pValue + * @param Worksheet $pValue * @param bool $pOverrideOld If a Worksheet has already been assigned, overwrite it and remove image from old Worksheet? * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return BaseDrawing */ - public function setWorksheet(\PhpOffice\PhpSpreadsheet\Worksheet $pValue = null, $pOverrideOld = false) + public function setWorksheet(Worksheet $pValue = null, $pOverrideOld = false) { if (is_null($this->worksheet)) { // Add drawing to \PhpOffice\PhpSpreadsheet\Worksheet @@ -240,7 +245,7 @@ class BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable // Set new \PhpOffice\PhpSpreadsheet\Worksheet $this->setWorksheet($pValue); } else { - throw new \PhpOffice\PhpSpreadsheet\Exception("A \PhpOffice\PhpSpreadsheet\Worksheet has already been assigned. Drawings can only exist on one \PhpOffice\PhpSpreadsheet\Worksheet."); + throw new PhpSpreadsheetException("A Worksheet has already been assigned. Drawings can only exist on one \PhpOffice\PhpSpreadsheet\Worksheet."); } } @@ -479,7 +484,7 @@ class BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable * * @param Drawing\Shadow $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return BaseDrawing */ diff --git a/src/PhpSpreadsheet/Worksheet/CellIterator.php b/src/PhpSpreadsheet/Worksheet/CellIterator.php index cc3b10ea..195307f0 100644 --- a/src/PhpSpreadsheet/Worksheet/CellIterator.php +++ b/src/PhpSpreadsheet/Worksheet/CellIterator.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -27,7 +29,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; abstract class CellIterator { /** - * \PhpOffice\PhpSpreadsheet\Worksheet to iterate. + * Worksheet to iterate. * * @var \PhpOffice\PhpSpreadsheet\Worksheet */ @@ -68,7 +70,7 @@ abstract class CellIterator /** * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ abstract protected function adjustForExistingOnlyRange(); @@ -77,7 +79,7 @@ abstract class CellIterator * * @param bool $value * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ public function setIterateOnlyExistingCells($value) { diff --git a/src/PhpSpreadsheet/Worksheet/Column.php b/src/PhpSpreadsheet/Worksheet/Column.php index d1e40750..12aa2a40 100644 --- a/src/PhpSpreadsheet/Worksheet/Column.php +++ b/src/PhpSpreadsheet/Worksheet/Column.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -43,10 +45,10 @@ class Column /** * Create a new column. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $parent + * @param Worksheet $parent * @param string $columnIndex */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet $parent = null, $columnIndex = 'A') + public function __construct(Worksheet $parent = null, $columnIndex = 'A') { // Set parent and column index $this->parent = $parent; diff --git a/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php b/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php index 8fcef2fb..1538b825 100644 --- a/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php +++ b/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -50,16 +54,16 @@ class ColumnCellIterator extends CellIterator implements \Iterator /** * Create a new row iterator. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $subject The worksheet to iterate over + * @param Worksheet $subject The worksheet to iterate over * @param string $columnIndex The column that we want to iterate * @param int $startRow The row number at which to start iterating * @param int $endRow Optionally, the row number at which to stop iterating */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet $subject = null, $columnIndex = 'A', $startRow = 1, $endRow = null) + public function __construct(Worksheet $subject = null, $columnIndex = 'A', $startRow = 1, $endRow = null) { // Set subject $this->subject = $subject; - $this->columnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($columnIndex) - 1; + $this->columnIndex = Cell::columnIndexFromString($columnIndex) - 1; $this->resetEnd($endRow); $this->resetStart($startRow); } @@ -77,7 +81,7 @@ class ColumnCellIterator extends CellIterator implements \Iterator * * @param int $startRow The row number at which to start iterating * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return ColumnCellIterator */ @@ -95,7 +99,7 @@ class ColumnCellIterator extends CellIterator implements \Iterator * * @param int $endRow The row number at which to stop iterating * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return ColumnCellIterator */ @@ -112,16 +116,16 @@ class ColumnCellIterator extends CellIterator implements \Iterator * * @param int $row The row number to set the current pointer at * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return ColumnCellIterator */ public function seek($row = 1) { if (($row < $this->startRow) || ($row > $this->endRow)) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Row $row is out of range ({$this->startRow} - {$this->endRow})"); + throw new PhpSpreadsheetException("Row $row is out of range ({$this->startRow} - {$this->endRow})"); } elseif ($this->onlyExistingCells && !($this->subject->cellExistsByColumnAndRow($this->columnIndex, $row))) { - throw new \PhpOffice\PhpSpreadsheet\Exception('In "IterateOnlyExistingCells" mode and Cell does not exist'); + throw new PhpSpreadsheetException('In "IterateOnlyExistingCells" mode and Cell does not exist'); } $this->position = $row; @@ -139,7 +143,7 @@ class ColumnCellIterator extends CellIterator implements \Iterator /** * Return the current cell in this worksheet column. * - * @return null|\PhpOffice\PhpSpreadsheet\Cell + * @return null|Cell */ public function current() { @@ -174,7 +178,7 @@ class ColumnCellIterator extends CellIterator implements \Iterator public function prev() { if ($this->position <= $this->startRow) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); + throw new PhpSpreadsheetException("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); } do { @@ -197,7 +201,7 @@ class ColumnCellIterator extends CellIterator implements \Iterator /** * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ protected function adjustForExistingOnlyRange() { @@ -207,14 +211,14 @@ class ColumnCellIterator extends CellIterator implements \Iterator ++$this->startRow; } if ($this->startRow > $this->endRow) { - throw new \PhpOffice\PhpSpreadsheet\Exception('No cells exist within the specified range'); + throw new PhpSpreadsheetException('No cells exist within the specified range'); } while ((!$this->subject->cellExistsByColumnAndRow($this->columnIndex, $this->endRow)) && ($this->endRow >= $this->startRow)) { --$this->endRow; } if ($this->endRow < $this->startRow) { - throw new \PhpOffice\PhpSpreadsheet\Exception('No cells exist within the specified range'); + throw new PhpSpreadsheetException('No cells exist within the specified range'); } } } diff --git a/src/PhpSpreadsheet/Worksheet/ColumnIterator.php b/src/PhpSpreadsheet/Worksheet/ColumnIterator.php index 9dfc6db9..77e931cb 100644 --- a/src/PhpSpreadsheet/Worksheet/ColumnIterator.php +++ b/src/PhpSpreadsheet/Worksheet/ColumnIterator.php @@ -4,23 +4,22 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Exception; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * @category PhpSpreadsheet * @@ -30,7 +29,7 @@ use PhpOffice\PhpSpreadsheet\Exception; class ColumnIterator implements \Iterator { /** - * \PhpOffice\PhpSpreadsheet\Worksheet to iterate. + * Worksheet to iterate. * * @var \PhpOffice\PhpSpreadsheet\Worksheet */ @@ -60,11 +59,11 @@ class ColumnIterator implements \Iterator /** * Create a new column iterator. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $subject The worksheet to iterate over + * @param Worksheet $subject The worksheet to iterate over * @param string $startColumn The column address at which to start iterating * @param string $endColumn Optionally, the column address at which to stop iterating */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet $subject, $startColumn = 'A', $endColumn = null) + public function __construct(Worksheet $subject, $startColumn = 'A', $endColumn = null) { // Set subject $this->subject = $subject; @@ -91,7 +90,7 @@ class ColumnIterator implements \Iterator */ public function resetStart($startColumn = 'A') { - $startColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($startColumn) - 1; + $startColumnIndex = Cell::columnIndexFromString($startColumn) - 1; if ($startColumnIndex > Cell::columnIndexFromString($this->subject->getHighestColumn()) - 1) { throw new Exception("Start column ({$startColumn}) is beyond highest column ({$this->subject->getHighestColumn()})"); } @@ -115,7 +114,7 @@ class ColumnIterator implements \Iterator public function resetEnd($endColumn = null) { $endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn(); - $this->endColumn = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($endColumn) - 1; + $this->endColumn = Cell::columnIndexFromString($endColumn) - 1; return $this; } @@ -125,15 +124,15 @@ class ColumnIterator implements \Iterator * * @param string $column The column address to set the current pointer at * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return ColumnIterator */ public function seek($column = 'A') { - $column = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1; + $column = Cell::columnIndexFromString($column) - 1; if (($column < $this->startColumn) || ($column > $this->endColumn)) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Column $column is out of range ({$this->startColumn} - {$this->endColumn})"); + throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumn} - {$this->endColumn})"); } $this->position = $column; @@ -155,7 +154,7 @@ class ColumnIterator implements \Iterator */ public function current() { - return new Column($this->subject, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->position)); + return new Column($this->subject, Cell::stringFromColumnIndex($this->position)); } /** @@ -165,7 +164,7 @@ class ColumnIterator implements \Iterator */ public function key() { - return \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->position); + return Cell::stringFromColumnIndex($this->position); } /** @@ -179,18 +178,13 @@ class ColumnIterator implements \Iterator /** * Set the iterator to its previous value. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ public function prev() { if ($this->position <= $this->startColumn) { - throw new \PhpOffice\PhpSpreadsheet\Exception( - 'Column is already at the beginning of range (' . - \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->endColumn) . ' - ' . - \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->endColumn) . ')' - ); + throw new PhpSpreadsheetException('Column is already at the beginning of range (' . Cell::stringFromColumnIndex($this->endColumn) . ' - ' . Cell::stringFromColumnIndex($this->endColumn) . ')'); } - --$this->position; } diff --git a/src/PhpSpreadsheet/Worksheet/Dimension.php b/src/PhpSpreadsheet/Worksheet/Dimension.php index 2ff18512..0f172d36 100644 --- a/src/PhpSpreadsheet/Worksheet/Dimension.php +++ b/src/PhpSpreadsheet/Worksheet/Dimension.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -101,19 +103,18 @@ abstract class Dimension /** * Set Outline Level. - * - * Value must be between 0 and 7 + * Value must be between 0 and 7. * * @param int $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Dimension */ public function setOutlineLevel($pValue) { if ($pValue < 0 || $pValue > 7) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Outline level must range between 0 and 7.'); + throw new PhpSpreadsheetException('Outline level must range between 0 and 7.'); } $this->outlineLevel = $pValue; diff --git a/src/PhpSpreadsheet/Worksheet/Drawing.php b/src/PhpSpreadsheet/Worksheet/Drawing.php index 8154e501..3341ac9d 100644 --- a/src/PhpSpreadsheet/Worksheet/Drawing.php +++ b/src/PhpSpreadsheet/Worksheet/Drawing.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Drawing extends BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable +class Drawing extends BaseDrawing implements IComparable { /** * Path. @@ -96,7 +99,7 @@ class Drawing extends BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparab * @param string $pValue File path * @param bool $pVerifyFile Verify file * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Drawing */ @@ -111,7 +114,7 @@ class Drawing extends BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparab list($this->width, $this->height) = getimagesize($pValue); } } else { - throw new \PhpOffice\PhpSpreadsheet\Exception("File $pValue not found!"); + throw new PhpSpreadsheetException("File $pValue not found!"); } } else { $this->path = $pValue; diff --git a/src/PhpSpreadsheet/Worksheet/Drawing/Shadow.php b/src/PhpSpreadsheet/Worksheet/Drawing/Shadow.php index 54f23a83..22a70289 100644 --- a/src/PhpSpreadsheet/Worksheet/Drawing/Shadow.php +++ b/src/PhpSpreadsheet/Worksheet/Drawing/Shadow.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet\Drawing; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; +use PhpOffice\PhpSpreadsheet\Style\Color; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +28,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet\Drawing; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Shadow implements \PhpOffice\PhpSpreadsheet\IComparable +class Shadow implements IComparable { /* Shadow alignment */ const SHADOW_BOTTOM = 'b'; @@ -78,7 +82,7 @@ class Shadow implements \PhpOffice\PhpSpreadsheet\IComparable /** * Color. * - * @var \PhpOffice\PhpSpreadsheet\Style\Color + * @var Color */ private $color; @@ -100,7 +104,7 @@ class Shadow implements \PhpOffice\PhpSpreadsheet\IComparable $this->distance = 2; $this->direction = 0; $this->alignment = self::SHADOW_BOTTOM_RIGHT; - $this->color = new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK); + $this->color = new Color(Color::COLOR_BLACK); $this->alpha = 50; } @@ -227,7 +231,7 @@ class Shadow implements \PhpOffice\PhpSpreadsheet\IComparable /** * Get Color. * - * @return \PhpOffice\PhpSpreadsheet\Style\Color + * @return Color */ public function getColor() { @@ -237,13 +241,13 @@ class Shadow implements \PhpOffice\PhpSpreadsheet\IComparable /** * Set Color. * - * @param \PhpOffice\PhpSpreadsheet\Style\Color $pValue + * @param Color $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Shadow */ - public function setColor(\PhpOffice\PhpSpreadsheet\Style\Color $pValue = null) + public function setColor(Color $pValue = null) { $this->color = $pValue; diff --git a/src/PhpSpreadsheet/Worksheet/HeaderFooter.php b/src/PhpSpreadsheet/Worksheet/HeaderFooter.php index 92760132..4b58ac49 100644 --- a/src/PhpSpreadsheet/Worksheet/HeaderFooter.php +++ b/src/PhpSpreadsheet/Worksheet/HeaderFooter.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -424,7 +426,7 @@ class HeaderFooter * @param HeaderFooterDrawing $image * @param string $location * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return HeaderFooter */ @@ -440,7 +442,7 @@ class HeaderFooter * * @param string $location * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return HeaderFooter */ @@ -458,7 +460,7 @@ class HeaderFooter * * @param HeaderFooterDrawing[] $images * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return HeaderFooter */ diff --git a/src/PhpSpreadsheet/Worksheet/HeaderFooterDrawing.php b/src/PhpSpreadsheet/Worksheet/HeaderFooterDrawing.php index 6db76ff5..274339dd 100644 --- a/src/PhpSpreadsheet/Worksheet/HeaderFooterDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/HeaderFooterDrawing.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class HeaderFooterDrawing extends Drawing implements \PhpOffice\PhpSpreadsheet\IComparable +class HeaderFooterDrawing extends Drawing implements IComparable { /** * Path. @@ -318,7 +321,7 @@ class HeaderFooterDrawing extends Drawing implements \PhpOffice\PhpSpreadsheet\I * @param string $pValue File path * @param bool $pVerifyFile Verify file * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return HeaderFooterDrawing */ @@ -333,7 +336,7 @@ class HeaderFooterDrawing extends Drawing implements \PhpOffice\PhpSpreadsheet\I list($this->width, $this->height) = getimagesize($pValue); } } else { - throw new \PhpOffice\PhpSpreadsheet\Exception("File $pValue not found!"); + throw new PhpSpreadsheetException("File $pValue not found!"); } } else { $this->path = $pValue; diff --git a/src/PhpSpreadsheet/Worksheet/Iterator.php b/src/PhpSpreadsheet/Worksheet/Iterator.php index c7cdbc19..d7406aec 100644 --- a/src/PhpSpreadsheet/Worksheet/Iterator.php +++ b/src/PhpSpreadsheet/Worksheet/Iterator.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,7 +31,7 @@ class Iterator implements \Iterator /** * Spreadsheet to iterate. * - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $subject; @@ -43,9 +45,9 @@ class Iterator implements \Iterator /** * Create a new worksheet iterator. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $subject + * @param Spreadsheet $subject */ - public function __construct(\PhpOffice\PhpSpreadsheet\Spreadsheet $subject = null) + public function __construct(Spreadsheet $subject = null) { // Set subject $this->subject = $subject; diff --git a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php index b543b8d0..f085d0e1 100644 --- a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\IComparable; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -24,7 +26,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class MemoryDrawing extends BaseDrawing implements \PhpOffice\PhpSpreadsheet\IComparable +class MemoryDrawing extends BaseDrawing implements IComparable { /* Rendering functions */ const RENDERING_DEFAULT = 'imagepng'; diff --git a/src/PhpSpreadsheet/Worksheet/PageSetup.php b/src/PhpSpreadsheet/Worksheet/PageSetup.php index 8e40ca1d..f001ecaf 100644 --- a/src/PhpSpreadsheet/Worksheet/PageSetup.php +++ b/src/PhpSpreadsheet/Worksheet/PageSetup.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -335,14 +338,13 @@ class PageSetup /** * Set Scale. - * * Print scaling. Valid values range from 10 to 400 - * This setting is overridden when fitToWidth and/or fitToHeight are in use + * This setting is overridden when fitToWidth and/or fitToHeight are in use. * * @param int|null $pValue * @param bool $pUpdate Update fitToPage so scaling applies rather than fitToHeight / fitToWidth * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return PageSetup */ @@ -356,7 +358,7 @@ class PageSetup $this->fitToPage = false; } } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Scale must not be negative'); + throw new PhpSpreadsheetException('Scale must not be negative'); } return $this; @@ -608,7 +610,7 @@ class PageSetup * Otherwise, the specific range identified by the value of $index will be returned * Print areas are numbered from 1 * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return string */ @@ -621,7 +623,7 @@ class PageSetup if (isset($printAreas[$index - 1])) { return $printAreas[$index - 1]; } - throw new \PhpOffice\PhpSpreadsheet\Exception('Requested Print Area does not exist'); + throw new PhpSpreadsheetException('Requested Print Area does not exist'); } /** @@ -687,18 +689,18 @@ class PageSetup * Default behaviour, or the "O" method, overwrites existing print area * The "I" method, inserts the new print area before any specified index, or at the end of the list * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return PageSetup */ public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) { if (strpos($value, '!') !== false) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Cell coordinate must not specify a worksheet.'); + throw new PhpSpreadsheetException('Cell coordinate must not specify a worksheet.'); } elseif (strpos($value, ':') === false) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Cell coordinate must be a range of cells.'); + throw new PhpSpreadsheetException('Cell coordinate must be a range of cells.'); } elseif (strpos($value, '$') !== false) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Cell coordinate must not be absolute.'); + throw new PhpSpreadsheetException('Cell coordinate must not be absolute.'); } $value = strtoupper($value); @@ -711,7 +713,7 @@ class PageSetup $index = count($printAreas) - abs($index) + 1; } if (($index <= 0) || ($index > count($printAreas))) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid index for setting print range.'); + throw new PhpSpreadsheetException('Invalid index for setting print range.'); } $printAreas[$index - 1] = $value; $this->printArea = implode(',', $printAreas); @@ -725,13 +727,13 @@ class PageSetup $index = abs($index) - 1; } if ($index > count($printAreas)) { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid index for setting print range.'); + throw new PhpSpreadsheetException('Invalid index for setting print range.'); } $printAreas = array_merge(array_slice($printAreas, 0, $index), [$value], array_slice($printAreas, $index)); $this->printArea = implode(',', $printAreas); } } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid method for setting print range.'); + throw new PhpSpreadsheetException('Invalid method for setting print range.'); } return $this; @@ -748,7 +750,7 @@ class PageSetup * list. * Print areas are numbered from 1 * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return PageSetup */ @@ -778,14 +780,14 @@ class PageSetup * Default behaviour, or the "O" method, overwrites existing print area * The "I" method, inserts the new print area before any specified index, or at the end of the list * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return PageSetup */ public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) { return $this->setPrintArea( - \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column1) . $row1 . ':' . \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column2) . $row2, + Cell::stringFromColumnIndex($column1) . $row1 . ':' . Cell::stringFromColumnIndex($column2) . $row2, $index, $method ); @@ -805,14 +807,14 @@ class PageSetup * list. * Print areas are numbered from 1 * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return PageSetup */ public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1) { return $this->setPrintArea( - \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column1) . $row1 . ':' . \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column2) . $row2, + Cell::stringFromColumnIndex($column1) . $row1 . ':' . Cell::stringFromColumnIndex($column2) . $row2, $index, self::SETPRINTRANGE_INSERT ); diff --git a/src/PhpSpreadsheet/Worksheet/Protection.php b/src/PhpSpreadsheet/Worksheet/Protection.php index ddb2dac3..ef96ba58 100644 --- a/src/PhpSpreadsheet/Worksheet/Protection.php +++ b/src/PhpSpreadsheet/Worksheet/Protection.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -582,7 +584,7 @@ class Protection public function setPassword($pValue, $pAlreadyHashed = false) { if (!$pAlreadyHashed) { - $pValue = \PhpOffice\PhpSpreadsheet\Shared\PasswordHasher::hashPassword($pValue); + $pValue = PasswordHasher::hashPassword($pValue); } $this->password = $pValue; diff --git a/src/PhpSpreadsheet/Worksheet/Row.php b/src/PhpSpreadsheet/Worksheet/Row.php index 5e565980..7a438e6f 100644 --- a/src/PhpSpreadsheet/Worksheet/Row.php +++ b/src/PhpSpreadsheet/Worksheet/Row.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -43,10 +45,10 @@ class Row /** * Create a new row. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $parent + * @param Worksheet $parent * @param int $rowIndex */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet $worksheet = null, $rowIndex = 1) + public function __construct(Worksheet $worksheet = null, $rowIndex = 1) { // Set parent and row index $this->worksheet = $worksheet; diff --git a/src/PhpSpreadsheet/Worksheet/RowCellIterator.php b/src/PhpSpreadsheet/Worksheet/RowCellIterator.php index 8ae0eb63..de111d42 100644 --- a/src/PhpSpreadsheet/Worksheet/RowCellIterator.php +++ b/src/PhpSpreadsheet/Worksheet/RowCellIterator.php @@ -2,22 +2,23 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * @category PhpSpreadsheet * @@ -50,12 +51,12 @@ class RowCellIterator extends CellIterator implements \Iterator /** * Create a new column iterator. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $subject The worksheet to iterate over + * @param Worksheet $subject The worksheet to iterate over * @param int $rowIndex The row that we want to iterate * @param string $startColumn The column address at which to start iterating * @param string $endColumn Optionally, the column address at which to stop iterating */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet $subject = null, $rowIndex = 1, $startColumn = 'A', $endColumn = null) + public function __construct(Worksheet $subject = null, $rowIndex = 1, $startColumn = 'A', $endColumn = null) { // Set subject and row index $this->subject = $subject; @@ -77,16 +78,16 @@ class RowCellIterator extends CellIterator implements \Iterator * * @param int $startColumn The column address at which to start iterating * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return RowCellIterator */ public function resetStart($startColumn = 'A') { - $startColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($startColumn) - 1; + $startColumnIndex = Cell::columnIndexFromString($startColumn) - 1; $this->startColumn = $startColumnIndex; $this->adjustForExistingOnlyRange(); - $this->seek(\PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->startColumn)); + $this->seek(Cell::stringFromColumnIndex($this->startColumn)); return $this; } @@ -96,14 +97,14 @@ class RowCellIterator extends CellIterator implements \Iterator * * @param string $endColumn The column address at which to stop iterating * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return RowCellIterator */ public function resetEnd($endColumn = null) { $endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn(); - $this->endColumn = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($endColumn) - 1; + $this->endColumn = Cell::columnIndexFromString($endColumn) - 1; $this->adjustForExistingOnlyRange(); return $this; @@ -114,17 +115,17 @@ class RowCellIterator extends CellIterator implements \Iterator * * @param string $column The column address to set the current pointer at * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return RowCellIterator */ public function seek($column = 'A') { - $column = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1; + $column = Cell::columnIndexFromString($column) - 1; if (($column < $this->startColumn) || ($column > $this->endColumn)) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Column $column is out of range ({$this->startColumn} - {$this->endColumn})"); + throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumn} - {$this->endColumn})"); } elseif ($this->onlyExistingCells && !($this->subject->cellExistsByColumnAndRow($column, $this->rowIndex))) { - throw new \PhpOffice\PhpSpreadsheet\Exception('In "IterateOnlyExistingCells" mode and Cell does not exist'); + throw new PhpSpreadsheetException('In "IterateOnlyExistingCells" mode and Cell does not exist'); } $this->position = $column; @@ -142,7 +143,7 @@ class RowCellIterator extends CellIterator implements \Iterator /** * Return the current cell in this worksheet row. * - * @return \PhpOffice\PhpSpreadsheet\Cell + * @return Cell */ public function current() { @@ -156,7 +157,7 @@ class RowCellIterator extends CellIterator implements \Iterator */ public function key() { - return \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->position); + return Cell::stringFromColumnIndex($this->position); } /** @@ -166,31 +167,22 @@ class RowCellIterator extends CellIterator implements \Iterator { do { ++$this->position; - } while (($this->onlyExistingCells) && - (!$this->subject->cellExistsByColumnAndRow($this->position, $this->rowIndex)) && - ($this->position <= $this->endColumn)); + } while (($this->onlyExistingCells) && (!$this->subject->cellExistsByColumnAndRow($this->position, $this->rowIndex)) && ($this->position <= $this->endColumn)); } /** * Set the iterator to its previous value. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ public function prev() { if ($this->position <= $this->startColumn) { - throw new \PhpOffice\PhpSpreadsheet\Exception( - 'Column is already at the beginning of range (' . - \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->endColumn) . ' - ' . - \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($this->endColumn) . ')' - ); + throw new PhpSpreadsheetException('Column is already at the beginning of range (' . Cell::stringFromColumnIndex($this->endColumn) . ' - ' . Cell::stringFromColumnIndex($this->endColumn) . ')'); } - do { --$this->position; - } while (($this->onlyExistingCells) && - (!$this->subject->cellExistsByColumnAndRow($this->position, $this->rowIndex)) && - ($this->position >= $this->startColumn)); + } while (($this->onlyExistingCells) && (!$this->subject->cellExistsByColumnAndRow($this->position, $this->rowIndex)) && ($this->position >= $this->startColumn)); } /** @@ -206,24 +198,22 @@ class RowCellIterator extends CellIterator implements \Iterator /** * Validate start/end values for "IterateOnlyExistingCells" mode, and adjust if necessary. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ protected function adjustForExistingOnlyRange() { if ($this->onlyExistingCells) { - while ((!$this->subject->cellExistsByColumnAndRow($this->startColumn, $this->rowIndex)) && - ($this->startColumn <= $this->endColumn)) { + while ((!$this->subject->cellExistsByColumnAndRow($this->startColumn, $this->rowIndex)) && ($this->startColumn <= $this->endColumn)) { ++$this->startColumn; } if ($this->startColumn > $this->endColumn) { - throw new \PhpOffice\PhpSpreadsheet\Exception('No cells exist within the specified range'); + throw new PhpSpreadsheetException('No cells exist within the specified range'); } - while ((!$this->subject->cellExistsByColumnAndRow($this->endColumn, $this->rowIndex)) && - ($this->endColumn >= $this->startColumn)) { + while ((!$this->subject->cellExistsByColumnAndRow($this->endColumn, $this->rowIndex)) && ($this->endColumn >= $this->startColumn)) { --$this->endColumn; } if ($this->endColumn < $this->startColumn) { - throw new \PhpOffice\PhpSpreadsheet\Exception('No cells exist within the specified range'); + throw new PhpSpreadsheetException('No cells exist within the specified range'); } } } diff --git a/src/PhpSpreadsheet/Worksheet/RowIterator.php b/src/PhpSpreadsheet/Worksheet/RowIterator.php index b92f8c9e..2aa63329 100644 --- a/src/PhpSpreadsheet/Worksheet/RowIterator.php +++ b/src/PhpSpreadsheet/Worksheet/RowIterator.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -27,7 +30,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; class RowIterator implements \Iterator { /** - * \PhpOffice\PhpSpreadsheet\Worksheet to iterate. + * Worksheet to iterate. * * @var \PhpOffice\PhpSpreadsheet\Worksheet */ @@ -57,11 +60,11 @@ class RowIterator implements \Iterator /** * Create a new row iterator. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $subject The worksheet to iterate over + * @param Worksheet $subject The worksheet to iterate over * @param int $startRow The row number at which to start iterating * @param int $endRow Optionally, the row number at which to stop iterating */ - public function __construct(\PhpOffice\PhpSpreadsheet\Worksheet $subject, $startRow = 1, $endRow = null) + public function __construct(Worksheet $subject, $startRow = 1, $endRow = null) { // Set subject $this->subject = $subject; @@ -82,14 +85,14 @@ class RowIterator implements \Iterator * * @param int $startRow The row number at which to start iterating * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return RowIterator */ public function resetStart($startRow = 1) { if ($startRow > $this->subject->getHighestRow()) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})"); + throw new PhpSpreadsheetException("Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})"); } $this->startRow = $startRow; @@ -120,14 +123,14 @@ class RowIterator implements \Iterator * * @param int $row The row number to set the current pointer at * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return RowIterator */ public function seek($row = 1) { if (($row < $this->startRow) || ($row > $this->endRow)) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Row $row is out of range ({$this->startRow} - {$this->endRow})"); + throw new PhpSpreadsheetException("Row $row is out of range ({$this->startRow} - {$this->endRow})"); } $this->position = $row; @@ -173,12 +176,12 @@ class RowIterator implements \Iterator /** * Set the iterator to its previous value. * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ public function prev() { if ($this->position <= $this->startRow) { - throw new \PhpOffice\PhpSpreadsheet\Exception("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); + throw new PhpSpreadsheetException("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); } --$this->position; diff --git a/src/PhpSpreadsheet/Worksheet/SheetView.php b/src/PhpSpreadsheet/Worksheet/SheetView.php index 7ce233ce..0966cbc3 100644 --- a/src/PhpSpreadsheet/Worksheet/SheetView.php +++ b/src/PhpSpreadsheet/Worksheet/SheetView.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -83,12 +85,11 @@ class SheetView /** * Set ZoomScale. - * * Valid values range from 10 to 400. * * @param int $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return SheetView */ @@ -99,7 +100,7 @@ class SheetView if (($pValue >= 1) || is_null($pValue)) { $this->zoomScale = $pValue; } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Scale must be greater than or equal to 1.'); + throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.'); } return $this; @@ -117,12 +118,11 @@ class SheetView /** * Set ZoomScale. - * * Valid values range from 10 to 400. * * @param int $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return SheetView */ @@ -131,7 +131,7 @@ class SheetView if (($pValue >= 1) || is_null($pValue)) { $this->zoomScaleNormal = $pValue; } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Scale must be greater than or equal to 1.'); + throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.'); } return $this; @@ -157,7 +157,7 @@ class SheetView * * @param string $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return SheetView */ @@ -170,7 +170,7 @@ class SheetView if (in_array($pValue, self::$sheetViewTypes)) { $this->sheetviewType = $pValue; } else { - throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid sheetview layout type.'); + throw new PhpSpreadsheetException('Invalid sheetview layout type.'); } return $this; diff --git a/src/PhpSpreadsheet/Writer/Csv.php b/src/PhpSpreadsheet/Writer/Csv.php index 4ed6f89d..4dfb498a 100644 --- a/src/PhpSpreadsheet/Writer/Csv.php +++ b/src/PhpSpreadsheet/Writer/Csv.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -86,9 +89,9 @@ class Csv extends BaseWriter implements IWriter /** * Create a new CSV. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet Spreadsheet object + * @param Spreadsheet $spreadsheet Spreadsheet object */ - public function __construct(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function __construct(Spreadsheet $spreadsheet) { $this->spreadsheet = $spreadsheet; } @@ -105,10 +108,10 @@ class Csv extends BaseWriter implements IWriter // Fetch sheet $sheet = $this->spreadsheet->getSheet($this->sheetIndex); - $saveDebugLog = \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadsheet)->getDebugLog()->getWriteDebugLog(); - \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog(false); - $saveArrayReturnType = \PhpOffice\PhpSpreadsheet\Calculation::getArrayReturnType(); - \PhpOffice\PhpSpreadsheet\Calculation::setArrayReturnType(\PhpOffice\PhpSpreadsheet\Calculation::RETURN_ARRAY_AS_VALUE); + $saveDebugLog = Calculation::getInstance($this->spreadsheet)->getDebugLog()->getWriteDebugLog(); + Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog(false); + $saveArrayReturnType = Calculation::getArrayReturnType(); + Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'wb+'); @@ -147,8 +150,8 @@ class Csv extends BaseWriter implements IWriter // Close file fclose($fileHandle); - \PhpOffice\PhpSpreadsheet\Calculation::setArrayReturnType($saveArrayReturnType); - \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); + Calculation::setArrayReturnType($saveArrayReturnType); + Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); } /** diff --git a/src/PhpSpreadsheet/Writer/Exception.php b/src/PhpSpreadsheet/Writer/Exception.php index b0f4d618..5c0a8023 100644 --- a/src/PhpSpreadsheet/Writer/Exception.php +++ b/src/PhpSpreadsheet/Writer/Exception.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -24,7 +26,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class Exception extends \PhpOffice\PhpSpreadsheet\Exception +class Exception extends PhpSpreadsheetException { /** * Error handler callback. diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index f87812c7..46aace25 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -3,9 +3,25 @@ namespace PhpOffice\PhpSpreadsheet\Writer; use PhpOffice\PhpSpreadsheet\Calculation; -use PhpOffice\PhpSpreadsheet\Shared\Font; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Chart; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\Drawing as SharedDrawing; +use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Shared\Font as SharedFont; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Borders; +use PhpOffice\PhpSpreadsheet\Style\Fill; +use PhpOffice\PhpSpreadsheet\Style\Font; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; +use PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; +use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; /** * Copyright (c) 2006 - 2015 Spreadsheet. @@ -83,7 +99,7 @@ class Html extends BaseWriter implements IWriter /** * Default font. * - * @var \PhpOffice\PhpSpreadsheet\Style\Font + * @var Font */ private $defaultFont; @@ -132,7 +148,7 @@ class Html extends BaseWriter implements IWriter /** * Create a new HTML. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet */ public function __construct(Spreadsheet $spreadsheet) { @@ -145,7 +161,7 @@ class Html extends BaseWriter implements IWriter * * @param string $pFilename * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ public function save($pFilename) { @@ -163,7 +179,7 @@ class Html extends BaseWriter implements IWriter // Open file $fileHandle = fopen($pFilename, 'wb+'); if ($fileHandle === false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not open file $pFilename for writing."); + throw new WriterException("Could not open file $pFilename for writing."); } // Write headers @@ -197,12 +213,12 @@ class Html extends BaseWriter implements IWriter private function mapVAlign($vAlign) { switch ($vAlign) { - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM: + case Alignment::VERTICAL_BOTTOM: return 'bottom'; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP: + case Alignment::VERTICAL_TOP: return 'top'; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER: - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY: + case Alignment::VERTICAL_CENTER: + case Alignment::VERTICAL_JUSTIFY: return 'middle'; default: return 'baseline'; @@ -219,16 +235,16 @@ class Html extends BaseWriter implements IWriter private function mapHAlign($hAlign) { switch ($hAlign) { - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL: + case Alignment::HORIZONTAL_GENERAL: return false; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT: + case Alignment::HORIZONTAL_LEFT: return 'left'; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT: + case Alignment::HORIZONTAL_RIGHT: return 'right'; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER: - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS: + case Alignment::HORIZONTAL_CENTER: + case Alignment::HORIZONTAL_CENTER_CONTINUOUS: return 'center'; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY: + case Alignment::HORIZONTAL_JUSTIFY: return 'justify'; default: return false; @@ -245,33 +261,33 @@ class Html extends BaseWriter implements IWriter private function mapBorderStyle($borderStyle) { switch ($borderStyle) { - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE: + case Border::BORDER_NONE: return 'none'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT: + case Border::BORDER_DASHDOT: return '1px dashed'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT: + case Border::BORDER_DASHDOTDOT: return '1px dotted'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED: + case Border::BORDER_DASHED: return '1px dashed'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED: + case Border::BORDER_DOTTED: return '1px dotted'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE: + case Border::BORDER_DOUBLE: return '3px double'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR: + case Border::BORDER_HAIR: return '1px solid'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM: + case Border::BORDER_MEDIUM: return '2px solid'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT: + case Border::BORDER_MEDIUMDASHDOT: return '2px dashed'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT: + case Border::BORDER_MEDIUMDASHDOTDOT: return '2px dotted'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED: + case Border::BORDER_MEDIUMDASHED: return '2px dashed'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT: + case Border::BORDER_SLANTDASHDOT: return '2px dashed'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK: + case Border::BORDER_THICK: return '3px solid'; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN: + case Border::BORDER_THIN: return '1px solid'; default: // map others to thin @@ -342,7 +358,7 @@ class Html extends BaseWriter implements IWriter * * @param bool $pIncludeStyles Include styles? * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ @@ -350,7 +366,7 @@ class Html extends BaseWriter implements IWriter { // Spreadsheet object known? if (is_null($this->spreadsheet)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Internal Spreadsheet object not set to an instance of an object.'); + throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Construct HTML @@ -402,7 +418,7 @@ class Html extends BaseWriter implements IWriter /** * Generate sheet data. * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ @@ -410,7 +426,7 @@ class Html extends BaseWriter implements IWriter { // Spreadsheet object known? if (is_null($this->spreadsheet)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Internal Spreadsheet object not set to an instance of an object.'); + throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Ensure that Spans have been calculated? @@ -437,10 +453,10 @@ class Html extends BaseWriter implements IWriter // Get worksheet dimension $dimension = explode(':', $sheet->calculateWorksheetDimension()); - $dimension[0] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($dimension[0]); - $dimension[0][0] = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($dimension[0][0]) - 1; - $dimension[1] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($dimension[1]); - $dimension[1][0] = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($dimension[1][0]) - 1; + $dimension[0] = Cell::coordinateFromString($dimension[0]); + $dimension[0][0] = Cell::columnIndexFromString($dimension[0][0]) - 1; + $dimension[1] = Cell::coordinateFromString($dimension[1]); + $dimension[1][0] = Cell::columnIndexFromString($dimension[1][0]) - 1; // row min,max $rowMin = $dimension[0][1]; @@ -484,7 +500,7 @@ class Html extends BaseWriter implements IWriter while ($column++ < $dimension[1][0]) { // Cell exists? if ($sheet->cellExistsByColumnAndRow($column, $row)) { - $rowData[$column] = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column) . $row; + $rowData[$column] = Cell::stringFromColumnIndex($column) . $row; } else { $rowData[$column] = ''; } @@ -522,7 +538,7 @@ class Html extends BaseWriter implements IWriter /** * Generate sheet tabs. * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ @@ -530,7 +546,7 @@ class Html extends BaseWriter implements IWriter { // Spreadsheet object known? if (is_null($this->spreadsheet)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Internal Spreadsheet object not set to an instance of an object.'); + throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Fetch sheets @@ -562,19 +578,19 @@ class Html extends BaseWriter implements IWriter return $html; } - private function extendRowsForChartsAndImages(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $row) + private function extendRowsForChartsAndImages(Worksheet $pSheet, $row) { $rowMax = $row; $colMax = 'A'; if ($this->includeCharts) { foreach ($pSheet->getChartCollection() as $chart) { - if ($chart instanceof \PhpOffice\PhpSpreadsheet\Chart) { + if ($chart instanceof Chart) { $chartCoordinates = $chart->getTopLeftPosition(); - $chartTL = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($chartCoordinates['cell']); - $chartCol = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($chartTL[0]); + $chartTL = Cell::coordinateFromString($chartCoordinates['cell']); + $chartCol = Cell::columnIndexFromString($chartTL[0]); if ($chartTL[1] > $rowMax) { $rowMax = $chartTL[1]; - if ($chartCol > \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($colMax)) { + if ($chartCol > Cell::columnIndexFromString($colMax)) { $colMax = $chartTL[0]; } } @@ -583,12 +599,12 @@ class Html extends BaseWriter implements IWriter } foreach ($pSheet->getDrawingCollection() as $drawing) { - if ($drawing instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing) { - $imageTL = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($drawing->getCoordinates()); - $imageCol = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($imageTL[0]); + if ($drawing instanceof Drawing) { + $imageTL = Cell::coordinateFromString($drawing->getCoordinates()); + $imageCol = Cell::columnIndexFromString($imageTL[0]); if ($imageTL[1] > $rowMax) { $rowMax = $imageTL[1]; - if ($imageCol > \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($colMax)) { + if ($imageCol > Cell::columnIndexFromString($colMax)) { $colMax = $imageTL[0]; } } @@ -623,21 +639,21 @@ class Html extends BaseWriter implements IWriter /** * Generate image tag in cell. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet + * @param Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet * @param string $coordinates Cell coordinates * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ - private function writeImageInCell(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $coordinates) + private function writeImageInCell(Worksheet $pSheet, $coordinates) { // Construct HTML $html = ''; // Write images foreach ($pSheet->getDrawingCollection() as $drawing) { - if ($drawing instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing) { + if ($drawing instanceof Drawing) { if ($drawing->getCoordinates() == $coordinates) { $filename = $drawing->getPath(); @@ -681,7 +697,7 @@ class Html extends BaseWriter implements IWriter $imageData . '" border="0" />'; $html .= ''; } - } elseif ($drawing instanceof \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing) { + } elseif ($drawing instanceof MemoryDrawing) { if ($drawing->getCoordinates() != $coordinates) { continue; } @@ -706,24 +722,24 @@ class Html extends BaseWriter implements IWriter /** * Generate chart tag in cell. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet + * @param Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet * @param string $coordinates Cell coordinates * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ - private function writeChartInCell(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $coordinates) + private function writeChartInCell(Worksheet $pSheet, $coordinates) { // Construct HTML $html = ''; // Write charts foreach ($pSheet->getChartCollection() as $chart) { - if ($chart instanceof \PhpOffice\PhpSpreadsheet\Chart) { + if ($chart instanceof Chart) { $chartCoordinates = $chart->getTopLeftPosition(); if ($chartCoordinates['cell'] == $coordinates) { - $chartFileName = \PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir() . '/' . uniqid() . '.png'; + $chartFileName = File::sysGetTempDir() . '/' . uniqid('', true) . '.png'; if (!$chart->render($chartFileName)) { return; } @@ -757,7 +773,7 @@ class Html extends BaseWriter implements IWriter * * @param bool $generateSurroundingHTML Generate surrounding HTML tags? (<style> and </style>) * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ @@ -765,7 +781,7 @@ class Html extends BaseWriter implements IWriter { // Spreadsheet object known? if (is_null($this->spreadsheet)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Internal Spreadsheet object not set to an instance of an object.'); + throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Build CSS @@ -801,7 +817,7 @@ class Html extends BaseWriter implements IWriter * * @param bool $generateSurroundingHTML Generate surrounding HTML style? (html { }) * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return array */ @@ -809,7 +825,7 @@ class Html extends BaseWriter implements IWriter { // Spreadsheet object known? if (is_null($this->spreadsheet)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Internal Spreadsheet object not set to an instance of an object.'); + throw new WriterException('Internal Spreadsheet object not set to an instance of an object.'); } // Cached? @@ -885,7 +901,7 @@ class Html extends BaseWriter implements IWriter $sheet->calculateColumnWidths(); // col elements, initialize - $highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($sheet->getHighestColumn()) - 1; + $highestColumnIndex = Cell::columnIndexFromString($sheet->getHighestColumn()) - 1; $column = -1; while ($column++ < $highestColumnIndex) { $this->columnWidths[$sheetIndex][$column] = 42; // approximation @@ -894,9 +910,9 @@ class Html extends BaseWriter implements IWriter // col elements, loop through columnDimensions and set width foreach ($sheet->getColumnDimensions() as $columnDimension) { - if (($width = \PhpOffice\PhpSpreadsheet\Shared\Drawing::cellDimensionToPixels($columnDimension->getWidth(), $this->defaultFont)) >= 0) { - $width = \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToPoints($width); - $column = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1; + if (($width = SharedDrawing::cellDimensionToPixels($columnDimension->getWidth(), $this->defaultFont)) >= 0) { + $width = SharedDrawing::pixelsToPoints($width); + $column = Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1; $this->columnWidths[$sheetIndex][$column] = $width; $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt'; @@ -914,7 +930,7 @@ class Html extends BaseWriter implements IWriter $css['table.sheet' . $sheetIndex . ' tr'] = []; if ($rowDimension->getRowHeight() == -1) { - $pt_height = Font::getDefaultRowHeightByFont($this->spreadsheet->getDefaultStyle()->getFont()); + $pt_height = SharedFont::getDefaultRowHeightByFont($this->spreadsheet->getDefaultStyle()->getFont()); } else { $pt_height = $rowDimension->getRowHeight(); } @@ -932,7 +948,7 @@ class Html extends BaseWriter implements IWriter $css['table.sheet' . $sheetIndex . ' tr.row' . $row] = []; if ($rowDimension->getRowHeight() == -1) { - $pt_height = Font::getDefaultRowHeightByFont($this->spreadsheet->getDefaultStyle()->getFont()); + $pt_height = SharedFont::getDefaultRowHeightByFont($this->spreadsheet->getDefaultStyle()->getFont()); } else { $pt_height = $rowDimension->getRowHeight(); } @@ -956,15 +972,12 @@ class Html extends BaseWriter implements IWriter /** * Create CSS style. * - * @param \PhpOffice\PhpSpreadsheet\Style $pStyle + * @param Style $pStyle * * @return array */ - private function createCSSStyle(\PhpOffice\PhpSpreadsheet\Style $pStyle) + private function createCSSStyle(Style $pStyle) { - // Construct CSS - $css = ''; - // Create CSS $css = array_merge( $this->createCSSStyleAlignment($pStyle->getAlignment()), @@ -980,11 +993,11 @@ class Html extends BaseWriter implements IWriter /** * Create CSS style (\PhpOffice\PhpSpreadsheet\Style\Alignment). * - * @param \PhpOffice\PhpSpreadsheet\Style\Alignment $pStyle \PhpOffice\PhpSpreadsheet\Style\Alignment + * @param Alignment $pStyle \PhpOffice\PhpSpreadsheet\Style\Alignment * * @return array */ - private function createCSSStyleAlignment(\PhpOffice\PhpSpreadsheet\Style\Alignment $pStyle) + private function createCSSStyleAlignment(Alignment $pStyle) { // Construct CSS $css = []; @@ -1004,11 +1017,11 @@ class Html extends BaseWriter implements IWriter /** * Create CSS style (\PhpOffice\PhpSpreadsheet\Style\Font). * - * @param \PhpOffice\PhpSpreadsheet\Style\Font $pStyle \PhpOffice\PhpSpreadsheet\Style\Font + * @param Font $pStyle * * @return array */ - private function createCSSStyleFont(\PhpOffice\PhpSpreadsheet\Style\Font $pStyle) + private function createCSSStyleFont(Font $pStyle) { // Construct CSS $css = []; @@ -1017,9 +1030,9 @@ class Html extends BaseWriter implements IWriter if ($pStyle->getBold()) { $css['font-weight'] = 'bold'; } - if ($pStyle->getUnderline() != \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) { + if ($pStyle->getUnderline() != Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) { $css['text-decoration'] = 'underline line-through'; - } elseif ($pStyle->getUnderline() != \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE) { + } elseif ($pStyle->getUnderline() != Font::UNDERLINE_NONE) { $css['text-decoration'] = 'underline'; } elseif ($pStyle->getStrikethrough()) { $css['text-decoration'] = 'line-through'; @@ -1036,13 +1049,13 @@ class Html extends BaseWriter implements IWriter } /** - * Create CSS style (\PhpOffice\PhpSpreadsheet\Style\Borders). + * Create CSS style (Borders). * - * @param \PhpOffice\PhpSpreadsheet\Style\Borders $pStyle \PhpOffice\PhpSpreadsheet\Style\Borders + * @param Borders $pStyle Borders * * @return array */ - private function createCSSStyleBorders(\PhpOffice\PhpSpreadsheet\Style\Borders $pStyle) + private function createCSSStyleBorders(Borders $pStyle) { // Construct CSS $css = []; @@ -1057,13 +1070,13 @@ class Html extends BaseWriter implements IWriter } /** - * Create CSS style (\PhpOffice\PhpSpreadsheet\Style\Border). + * Create CSS style (Border). * - * @param \PhpOffice\PhpSpreadsheet\Style\Border $pStyle \PhpOffice\PhpSpreadsheet\Style\Border + * @param Border $pStyle Border * * @return string */ - private function createCSSStyleBorder(\PhpOffice\PhpSpreadsheet\Style\Border $pStyle) + private function createCSSStyleBorder(Border $pStyle) { // Create CSS - add !important to non-none border styles for merged cells $borderStyle = $this->mapBorderStyle($pStyle->getBorderStyle()); @@ -1073,19 +1086,19 @@ class Html extends BaseWriter implements IWriter } /** - * Create CSS style (\PhpOffice\PhpSpreadsheet\Style\Fill). + * Create CSS style (Fill). * - * @param \PhpOffice\PhpSpreadsheet\Style\Fill $pStyle \PhpOffice\PhpSpreadsheet\Style\Fill + * @param Fill $pStyle Fill * * @return array */ - private function createCSSStyleFill(\PhpOffice\PhpSpreadsheet\Style\Fill $pStyle) + private function createCSSStyleFill(Fill $pStyle) { // Construct HTML $css = []; // Create CSS - $value = $pStyle->getFillType() == \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE ? + $value = $pStyle->getFillType() == Fill::FILL_NONE ? 'white' : '#' . $pStyle->getStartColor()->getRGB(); $css['background-color'] = $value; @@ -1108,9 +1121,9 @@ class Html extends BaseWriter implements IWriter /** * Generate table header. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet The worksheet for the table we are writing + * @param Worksheet $pSheet The worksheet for the table we are writing * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ @@ -1137,7 +1150,7 @@ class Html extends BaseWriter implements IWriter } // Write elements - $highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1; + $highestColumnIndex = Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1; $i = -1; while ($i++ < $highestColumnIndex) { if (!$this->isPdf) { @@ -1157,7 +1170,7 @@ class Html extends BaseWriter implements IWriter /** * Generate table footer. * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function generateTableFooter() { @@ -1169,16 +1182,16 @@ class Html extends BaseWriter implements IWriter /** * Generate row. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet + * @param Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet * @param array $pValues Array containing cells in a row * @param int $pRow Row number (0-based) * @param mixed $cellType eg: 'td' * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string */ - private function generateRow(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet, array $pValues, $pRow, $cellType) + private function generateRow(Worksheet $pSheet, array $pValues, $pRow, $cellType) { // Construct HTML $html = ''; @@ -1217,9 +1230,8 @@ class Html extends BaseWriter implements IWriter $colNum = 0; foreach ($pValues as $cellAddress) { $cell = ($cellAddress > '') ? $pSheet->getCell($cellAddress) : ''; - $coordinate = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($colNum) . ($pRow + 1); + $coordinate = Cell::stringFromColumnIndex($colNum) . ($pRow + 1); if (!$this->useInlineCss) { - $cssClass = ''; $cssClass = 'column' . $colNum; } else { $cssClass = []; @@ -1239,24 +1251,24 @@ class Html extends BaseWriter implements IWriter // initialize $cellData = ' '; - // \PhpOffice\PhpSpreadsheet\Cell - if ($cell instanceof \PhpOffice\PhpSpreadsheet\Cell) { + // Cell + if ($cell instanceof Cell) { $cellData = ''; if (is_null($cell->getParent())) { $cell->attach($pSheet); } // Value - if ($cell->getValue() instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if ($cell->getValue() instanceof RichText) { // Loop through rich text elements $elements = $cell->getValue()->getRichTextElements(); foreach ($elements as $element) { // Rich text start? - if ($element instanceof \PhpOffice\PhpSpreadsheet\RichText\Run) { + if ($element instanceof RichText\Run) { $cellData .= ''; - if ($element->getFont()->getSuperScript()) { + if ($element->getFont()->getSuperscript()) { $cellData .= ''; - } elseif ($element->getFont()->getSubScript()) { + } elseif ($element->getFont()->getSubscript()) { $cellData .= ''; } } @@ -1265,10 +1277,10 @@ class Html extends BaseWriter implements IWriter $cellText = $element->getText(); $cellData .= htmlspecialchars($cellText); - if ($element instanceof \PhpOffice\PhpSpreadsheet\RichText\Run) { - if ($element->getFont()->getSuperScript()) { + if ($element instanceof RichText\Run) { + if ($element->getFont()->getSuperscript()) { $cellData .= ''; - } elseif ($element->getFont()->getSubScript()) { + } elseif ($element->getFont()->getSubscript()) { $cellData .= ''; } @@ -1277,22 +1289,22 @@ class Html extends BaseWriter implements IWriter } } else { if ($this->preCalculateFormulas) { - $cellData = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString( + $cellData = NumberFormat::toFormattedString( $cell->getCalculatedValue(), $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(), [$this, 'formatColor'] ); } else { - $cellData = \PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString( + $cellData = NumberFormat::toFormattedString( $cell->getValue(), $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode(), [$this, 'formatColor'] ); } $cellData = htmlspecialchars($cellData); - if ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperScript()) { + if ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperscript()) { $cellData = '' . $cellData . ''; - } elseif ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSubScript()) { + } elseif ($pSheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSubscript()) { $cellData = '' . $cellData . ''; } } @@ -1321,7 +1333,7 @@ class Html extends BaseWriter implements IWriter // General horizontal alignment: Actual horizontal alignment depends on dataType $sharedStyle = $pSheet->getParent()->getCellXfByIndex($cell->getXfIndex()); - if ($sharedStyle->getAlignment()->getHorizontal() == \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL + if ($sharedStyle->getAlignment()->getHorizontal() == Alignment::HORIZONTAL_GENERAL && isset($this->cssStyles['.' . $cell->getDataType()]['text-align']) ) { $cssClass['text-align'] = $this->cssStyles['.' . $cell->getDataType()]['text-align']; @@ -1348,7 +1360,7 @@ class Html extends BaseWriter implements IWriter // Also apply style from last cell in merge to fix borders - // relies on !important for non-none border declarations in createCSSStyleBorder - $endCellCoord = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan); + $endCellCoord = Cell::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan); if (!$this->useInlineCss) { $cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex(); } @@ -1525,8 +1537,7 @@ class Html extends BaseWriter implements IWriter $color_regex = '/^\\[[a-zA-Z]+\\]/'; if (preg_match($color_regex, $pFormat, $matches)) { - $color = str_replace('[', '', $matches[0]); - $color = str_replace(']', '', $color); + $color = str_replace(['[', ']'], '', $matches[0]); $color = strtolower($color); } @@ -1559,15 +1570,15 @@ class Html extends BaseWriter implements IWriter // loop through all Excel merged cells foreach ($sheet->getMergeCells() as $cells) { - list($cells) = \PhpOffice\PhpSpreadsheet\Cell::splitRange($cells); + list($cells) = Cell::splitRange($cells); $first = $cells[0]; $last = $cells[1]; - list($fc, $fr) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($first); - $fc = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($fc) - 1; + list($fc, $fr) = Cell::coordinateFromString($first); + $fc = Cell::columnIndexFromString($fc) - 1; - list($lc, $lr) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($last); - $lc = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($lc) - 1; + list($lc, $lr) = Cell::coordinateFromString($last); + $lc = Cell::columnIndexFromString($lc) - 1; // loop through the individual cells in the individual merge $r = $fr - 1; @@ -1597,7 +1608,7 @@ class Html extends BaseWriter implements IWriter // Identify which rows should be omitted in HTML. These are the rows where all the cells // participate in a merge and the where base cells are somewhere above. - $countColumns = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($sheet->getHighestColumn()); + $countColumns = Cell::columnIndexFromString($sheet->getHighestColumn()); foreach ($candidateSpannedRow as $rowIndex) { if (isset($this->isSpannedCell[$sheetIndex][$rowIndex])) { if (count($this->isSpannedCell[$sheetIndex][$rowIndex]) == $countColumns) { @@ -1631,7 +1642,7 @@ class Html extends BaseWriter implements IWriter $this->spansAreCalculated = true; } - private function setMargins(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function setMargins(Worksheet $pSheet) { $htmlPage = '@page { '; $htmlBody = 'body { '; diff --git a/src/PhpSpreadsheet/Writer/Ods.php b/src/PhpSpreadsheet/Writer/Ods.php index f82d4a73..e56bdd52 100644 --- a/src/PhpSpreadsheet/Writer/Ods.php +++ b/src/PhpSpreadsheet/Writer/Ods.php @@ -2,7 +2,16 @@ namespace PhpOffice\PhpSpreadsheet\Writer; +use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; +use PhpOffice\PhpSpreadsheet\Writer\Ods\Content; +use PhpOffice\PhpSpreadsheet\Writer\Ods\Meta; +use PhpOffice\PhpSpreadsheet\Writer\Ods\MetaInf; +use PhpOffice\PhpSpreadsheet\Writer\Ods\Mimetype; +use PhpOffice\PhpSpreadsheet\Writer\Ods\Settings; +use PhpOffice\PhpSpreadsheet\Writer\Ods\Styles; +use PhpOffice\PhpSpreadsheet\Writer\Ods\Thumbnails; use ZipArchive; /** @@ -46,20 +55,20 @@ class Ods extends BaseWriter implements IWriter /** * Create a new Ods. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet */ - public function __construct(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function __construct(Spreadsheet $spreadsheet) { $this->setSpreadsheet($spreadsheet); $writerPartsArray = [ - 'content' => \PhpOffice\PhpSpreadsheet\Writer\Ods\Content::class, - 'meta' => \PhpOffice\PhpSpreadsheet\Writer\Ods\Meta::class, - 'meta_inf' => \PhpOffice\PhpSpreadsheet\Writer\Ods\MetaInf::class, - 'mimetype' => \PhpOffice\PhpSpreadsheet\Writer\Ods\Mimetype::class, - 'settings' => \PhpOffice\PhpSpreadsheet\Writer\Ods\Settings::class, - 'styles' => \PhpOffice\PhpSpreadsheet\Writer\Ods\Styles::class, - 'thumbnails' => \PhpOffice\PhpSpreadsheet\Writer\Ods\Thumbnails::class, + 'content' => Content::class, + 'meta' => Meta::class, + 'meta_inf' => MetaInf::class, + 'mimetype' => Mimetype::class, + 'settings' => Settings::class, + 'styles' => Styles::class, + 'thumbnails' => Thumbnails::class, ]; foreach ($writerPartsArray as $writer => $class) { @@ -88,12 +97,12 @@ class Ods extends BaseWriter implements IWriter * * @param string $pFilename * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ public function save($pFilename) { if (!$this->spreadSheet) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('PhpSpreadsheet object unassigned.'); + throw new WriterException('PhpSpreadsheet object unassigned.'); } // garbage collect @@ -102,7 +111,7 @@ class Ods extends BaseWriter implements IWriter // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { - $pFilename = @tempnam(\PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir(), 'phpxltmp'); + $pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp'); if ($pFilename == '') { $pFilename = $originalFilename; } @@ -120,13 +129,13 @@ class Ods extends BaseWriter implements IWriter // Close file if ($zip->close() === false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not close zip file $pFilename."); + throw new WriterException("Could not close zip file $pFilename."); } // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { if (copy($pFilename, $originalFilename) === false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not copy temporary zip file $pFilename to $originalFilename."); + throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename."); } @unlink($pFilename); } @@ -137,7 +146,7 @@ class Ods extends BaseWriter implements IWriter * * @param string $pFilename * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return ZipArchive */ @@ -152,7 +161,7 @@ class Ods extends BaseWriter implements IWriter // Try opening the ZIP file if ($zip->open($pFilename, ZipArchive::OVERWRITE) !== true) { if ($zip->open($pFilename, ZipArchive::CREATE) !== true) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not open $pFilename for writing."); + throw new WriterException("Could not open $pFilename for writing."); } } @@ -162,7 +171,7 @@ class Ods extends BaseWriter implements IWriter /** * Get Spreadsheet object. * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return Spreadsheet */ @@ -171,19 +180,19 @@ class Ods extends BaseWriter implements IWriter if ($this->spreadSheet !== null) { return $this->spreadSheet; } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('No PhpSpreadsheet assigned.'); + throw new WriterException('No PhpSpreadsheet assigned.'); } /** * Set Spreadsheet object. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet PhpSpreadsheet object + * @param Spreadsheet $spreadsheet PhpSpreadsheet object * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return self */ - public function setSpreadsheet(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function setSpreadsheet(Spreadsheet $spreadsheet) { $this->spreadSheet = $spreadsheet; diff --git a/src/PhpSpreadsheet/Writer/Ods/Cell/Comment.php b/src/PhpSpreadsheet/Writer/Ods/Cell/Comment.php index 0ccf5618..f38a3c06 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Cell/Comment.php +++ b/src/PhpSpreadsheet/Writer/Ods/Cell/Comment.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods\Cell; -/** +/* * PhpSpreadsheet. * * Copyright (c) 2006 - 2015 PhpSpreadsheet @@ -26,6 +26,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods\Cell; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; /** * @category PhpSpreadsheet @@ -35,7 +37,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods\Cell; */ class Comment { - public static function write(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Cell $cell) + public static function write(XMLWriter $objWriter, Cell $cell) { $comments = $cell->getWorksheet()->getComments(); if (!isset($comments[$cell->getCoordinate()])) { diff --git a/src/PhpSpreadsheet/Writer/Ods/Content.php b/src/PhpSpreadsheet/Writer/Ods/Content.php index b8597028..bd5db3e3 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Content.php +++ b/src/PhpSpreadsheet/Writer/Ods/Content.php @@ -224,10 +224,13 @@ class Content extends WriterPart throw new Exception('Writing of error not implemented yet.'); break; case DataType::TYPE_FORMULA: - try { - $formulaValue = $cell->getCalculatedValue(); - } catch (\Exception $e) { - $formulaValue = $cell->getValue(); + $formulaValue = $cell->getValue(); + if ($this->getParentWriter()->getPreCalculateFormulas()) { + try { + $formulaValue = $cell->getCalculatedValue(); + } catch (Exception $e) { + // don't do anything + } } $objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue()); if (is_numeric($formulaValue)) { diff --git a/src/PhpSpreadsheet/Writer/Ods/Meta.php b/src/PhpSpreadsheet/Writer/Ods/Meta.php index 4a57ac69..d00c479b 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Meta.php +++ b/src/PhpSpreadsheet/Writer/Ods/Meta.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,13 +32,13 @@ class Meta extends WriterPart /** * Write meta.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function write(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet = null) + public function write(Spreadsheet $spreadsheet = null) { if (!$spreadsheet) { $spreadsheet = $this->getParentWriter()->getSpreadsheet(); @@ -43,9 +46,9 @@ class Meta extends WriterPart $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Ods/MetaInf.php b/src/PhpSpreadsheet/Writer/Ods/MetaInf.php index c712e7cd..9cd0dc6c 100644 --- a/src/PhpSpreadsheet/Writer/Ods/MetaInf.php +++ b/src/PhpSpreadsheet/Writer/Ods/MetaInf.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,13 +32,13 @@ class MetaInf extends WriterPart /** * Write META-INF/manifest.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeManifest(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet = null) + public function writeManifest(Spreadsheet $spreadsheet = null) { if (!$spreadsheet) { $spreadsheet = $this->getParentWriter()->getSpreadsheet(); @@ -43,9 +46,9 @@ class MetaInf extends WriterPart $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Ods/Mimetype.php b/src/PhpSpreadsheet/Writer/Ods/Mimetype.php index f3bf03b5..7733f4d8 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Mimetype.php +++ b/src/PhpSpreadsheet/Writer/Ods/Mimetype.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,13 +29,13 @@ class Mimetype extends WriterPart /** * Write mimetype to plain text format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function write(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet = null) + public function write(Spreadsheet $spreadsheet = null) { return 'application/vnd.oasis.opendocument.spreadsheet'; } diff --git a/src/PhpSpreadsheet/Writer/Ods/Settings.php b/src/PhpSpreadsheet/Writer/Ods/Settings.php index dd77ae54..cea7c725 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Settings.php +++ b/src/PhpSpreadsheet/Writer/Ods/Settings.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,13 +32,13 @@ class Settings extends WriterPart /** * Write settings.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function write(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet = null) + public function write(Spreadsheet $spreadsheet = null) { if (!$spreadsheet) { $spreadsheet = $this->getParentWriter()->getSpreadsheet(); @@ -43,9 +46,9 @@ class Settings extends WriterPart $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Ods/Styles.php b/src/PhpSpreadsheet/Writer/Ods/Styles.php index 5219f106..a9ea8e86 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Styles.php +++ b/src/PhpSpreadsheet/Writer/Ods/Styles.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,13 +32,13 @@ class Styles extends WriterPart /** * Write styles.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function write(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet = null) + public function write(Spreadsheet $spreadsheet = null) { if (!$spreadsheet) { $spreadsheet = $this->getParentWriter()->getSpreadsheet(); @@ -43,9 +46,9 @@ class Styles extends WriterPart $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Ods/Thumbnails.php b/src/PhpSpreadsheet/Writer/Ods/Thumbnails.php index df5642fb..b2e38ea5 100644 --- a/src/PhpSpreadsheet/Writer/Ods/Thumbnails.php +++ b/src/PhpSpreadsheet/Writer/Ods/Thumbnails.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,13 +31,13 @@ class Thumbnails extends WriterPart /** * Write Thumbnails/thumbnail.png to PNG format. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeThumbnail(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet = null) + public function writeThumbnail(Spreadsheet $spreadsheet = null) { return ''; } diff --git a/src/PhpSpreadsheet/Writer/Ods/WriterPart.php b/src/PhpSpreadsheet/Writer/Ods/WriterPart.php index b07b38cb..04fd0fdb 100644 --- a/src/PhpSpreadsheet/Writer/Ods/WriterPart.php +++ b/src/PhpSpreadsheet/Writer/Ods/WriterPart.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Ods; +use PhpOffice\PhpSpreadsheet\Writer\Ods; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,7 +31,7 @@ abstract class WriterPart /** * Parent Ods object. * - * @var \PhpOffice\PhpSpreadsheet\Writer\Ods + * @var Ods */ private $parentWriter; @@ -38,7 +40,7 @@ abstract class WriterPart * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Writer\Ods + * @return Ods */ public function getParentWriter() { @@ -48,9 +50,9 @@ abstract class WriterPart /** * Set parent Ods writer. * - * @param \PhpOffice\PhpSpreadsheet\Writer\Ods $writer + * @param Ods $writer */ - public function __construct(\PhpOffice\PhpSpreadsheet\Writer\Ods $writer) + public function __construct(Ods $writer) { $this->parentWriter = $writer; } diff --git a/src/PhpSpreadsheet/Writer/Pdf.php b/src/PhpSpreadsheet/Writer/Pdf.php index eeec2334..48e585b2 100644 --- a/src/PhpSpreadsheet/Writer/Pdf.php +++ b/src/PhpSpreadsheet/Writer/Pdf.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer; +use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Spreadsheet; /** @@ -38,13 +39,13 @@ class Pdf implements IWriter /** * Instantiate a new renderer of the configured type within this container class. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet PhpSpreadsheet object + * @param Spreadsheet $spreadsheet PhpSpreadsheet object * * @throws Exception when PDF library is not configured */ public function __construct(Spreadsheet $spreadsheet) { - $pdfLibraryName = \PhpOffice\PhpSpreadsheet\Settings::getPdfRendererName(); + $pdfLibraryName = Settings::getPdfRendererName(); if (is_null($pdfLibraryName)) { throw new Exception('PDF Rendering library has not been defined.'); } diff --git a/src/PhpSpreadsheet/Writer/Pdf/Core.php b/src/PhpSpreadsheet/Writer/Pdf/Core.php index 084b514c..d8eeb00a 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/Core.php +++ b/src/PhpSpreadsheet/Writer/Pdf/Core.php @@ -2,6 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; +use PhpOffice\PhpSpreadsheet\Writer\Html; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -24,7 +31,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html +abstract class Core extends Html { /** * Temporary storage directory. @@ -67,84 +74,84 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html * @var array */ protected static $paperSizes = [ - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LETTER => 'LETTER', // (8.5 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LETTER_SMALL => 'LETTER', // (8.5 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_TABLOID => [792.00, 1224.00], // (11 in. by 17 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LEDGER => [1224.00, 792.00], // (17 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LEGAL => 'LEGAL', // (8.5 in. by 14 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_STATEMENT => [396.00, 612.00], // (5.5 in. by 8.5 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_EXECUTIVE => 'EXECUTIVE', // (7.25 in. by 10.5 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A3 => 'A3', // (297 mm by 420 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4 => 'A4', // (210 mm by 297 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4_SMALL => 'A4', // (210 mm by 297 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A5 => 'A5', // (148 mm by 210 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_B4 => 'B4', // (250 mm by 353 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_B5 => 'B5', // (176 mm by 250 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_FOLIO => 'FOLIO', // (8.5 in. by 13 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_QUARTO => [609.45, 779.53], // (215 mm by 275 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_STANDARD_1 => [720.00, 1008.00], // (10 in. by 14 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_STANDARD_2 => [792.00, 1224.00], // (11 in. by 17 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_NOTE => 'LETTER', // (8.5 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_NO9_ENVELOPE => [279.00, 639.00], // (3.875 in. by 8.875 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_NO10_ENVELOPE => [297.00, 684.00], // (4.125 in. by 9.5 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_NO11_ENVELOPE => [324.00, 747.00], // (4.5 in. by 10.375 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_NO12_ENVELOPE => [342.00, 792.00], // (4.75 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_NO14_ENVELOPE => [360.00, 828.00], // (5 in. by 11.5 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_C => [1224.00, 1584.00], // (17 in. by 22 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_D => [1584.00, 2448.00], // (22 in. by 34 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_E => [2448.00, 3168.00], // (34 in. by 44 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_DL_ENVELOPE => [311.81, 623.62], // (110 mm by 220 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_C5_ENVELOPE => 'C5', // (162 mm by 229 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_C3_ENVELOPE => 'C3', // (324 mm by 458 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_C4_ENVELOPE => 'C4', // (229 mm by 324 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_C6_ENVELOPE => 'C6', // (114 mm by 162 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_C65_ENVELOPE => [323.15, 649.13], // (114 mm by 229 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_B4_ENVELOPE => 'B4', // (250 mm by 353 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_B5_ENVELOPE => 'B5', // (176 mm by 250 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_B6_ENVELOPE => [498.90, 354.33], // (176 mm by 125 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_ITALY_ENVELOPE => [311.81, 651.97], // (110 mm by 230 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_MONARCH_ENVELOPE => [279.00, 540.00], // (3.875 in. by 7.5 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_6_3_4_ENVELOPE => [261.00, 468.00], // (3.625 in. by 6.5 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_US_STANDARD_FANFOLD => [1071.00, 792.00], // (14.875 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_GERMAN_STANDARD_FANFOLD => [612.00, 864.00], // (8.5 in. by 12 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_GERMAN_LEGAL_FANFOLD => 'FOLIO', // (8.5 in. by 13 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_ISO_B4 => 'B4', // (250 mm by 353 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_JAPANESE_DOUBLE_POSTCARD => [566.93, 419.53], // (200 mm by 148 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_STANDARD_PAPER_1 => [648.00, 792.00], // (9 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_STANDARD_PAPER_2 => [720.00, 792.00], // (10 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_STANDARD_PAPER_3 => [1080.00, 792.00], // (15 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_INVITE_ENVELOPE => [623.62, 623.62], // (220 mm by 220 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LETTER_EXTRA_PAPER => [667.80, 864.00], // (9.275 in. by 12 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LEGAL_EXTRA_PAPER => [667.80, 1080.00], // (9.275 in. by 15 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_TABLOID_EXTRA_PAPER => [841.68, 1296.00], // (11.69 in. by 18 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4_EXTRA_PAPER => [668.98, 912.76], // (236 mm by 322 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LETTER_TRANSVERSE_PAPER => [595.80, 792.00], // (8.275 in. by 11 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4_TRANSVERSE_PAPER => 'A4', // (210 mm by 297 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER => [667.80, 864.00], // (9.275 in. by 12 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_SUPERA_SUPERA_A4_PAPER => [643.46, 1009.13], // (227 mm by 356 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_SUPERB_SUPERB_A3_PAPER => [864.57, 1380.47], // (305 mm by 487 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_LETTER_PLUS_PAPER => [612.00, 913.68], // (8.5 in. by 12.69 in.) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4_PLUS_PAPER => [595.28, 935.43], // (210 mm by 330 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A5_TRANSVERSE_PAPER => 'A5', // (148 mm by 210 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_JIS_B5_TRANSVERSE_PAPER => [515.91, 728.50], // (182 mm by 257 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A3_EXTRA_PAPER => [912.76, 1261.42], // (322 mm by 445 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A5_EXTRA_PAPER => [493.23, 666.14], // (174 mm by 235 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_ISO_B5_EXTRA_PAPER => [569.76, 782.36], // (201 mm by 276 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A2_PAPER => 'A2', // (420 mm by 594 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A3_TRANSVERSE_PAPER => 'A3', // (297 mm by 420 mm) - \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER => [912.76, 1261.42], // (322 mm by 445 mm) + PageSetup::PAPERSIZE_LETTER => 'LETTER', // (8.5 in. by 11 in.) + PageSetup::PAPERSIZE_LETTER_SMALL => 'LETTER', // (8.5 in. by 11 in.) + PageSetup::PAPERSIZE_TABLOID => [792.00, 1224.00], // (11 in. by 17 in.) + PageSetup::PAPERSIZE_LEDGER => [1224.00, 792.00], // (17 in. by 11 in.) + PageSetup::PAPERSIZE_LEGAL => 'LEGAL', // (8.5 in. by 14 in.) + PageSetup::PAPERSIZE_STATEMENT => [396.00, 612.00], // (5.5 in. by 8.5 in.) + PageSetup::PAPERSIZE_EXECUTIVE => 'EXECUTIVE', // (7.25 in. by 10.5 in.) + PageSetup::PAPERSIZE_A3 => 'A3', // (297 mm by 420 mm) + PageSetup::PAPERSIZE_A4 => 'A4', // (210 mm by 297 mm) + PageSetup::PAPERSIZE_A4_SMALL => 'A4', // (210 mm by 297 mm) + PageSetup::PAPERSIZE_A5 => 'A5', // (148 mm by 210 mm) + PageSetup::PAPERSIZE_B4 => 'B4', // (250 mm by 353 mm) + PageSetup::PAPERSIZE_B5 => 'B5', // (176 mm by 250 mm) + PageSetup::PAPERSIZE_FOLIO => 'FOLIO', // (8.5 in. by 13 in.) + PageSetup::PAPERSIZE_QUARTO => [609.45, 779.53], // (215 mm by 275 mm) + PageSetup::PAPERSIZE_STANDARD_1 => [720.00, 1008.00], // (10 in. by 14 in.) + PageSetup::PAPERSIZE_STANDARD_2 => [792.00, 1224.00], // (11 in. by 17 in.) + PageSetup::PAPERSIZE_NOTE => 'LETTER', // (8.5 in. by 11 in.) + PageSetup::PAPERSIZE_NO9_ENVELOPE => [279.00, 639.00], // (3.875 in. by 8.875 in.) + PageSetup::PAPERSIZE_NO10_ENVELOPE => [297.00, 684.00], // (4.125 in. by 9.5 in.) + PageSetup::PAPERSIZE_NO11_ENVELOPE => [324.00, 747.00], // (4.5 in. by 10.375 in.) + PageSetup::PAPERSIZE_NO12_ENVELOPE => [342.00, 792.00], // (4.75 in. by 11 in.) + PageSetup::PAPERSIZE_NO14_ENVELOPE => [360.00, 828.00], // (5 in. by 11.5 in.) + PageSetup::PAPERSIZE_C => [1224.00, 1584.00], // (17 in. by 22 in.) + PageSetup::PAPERSIZE_D => [1584.00, 2448.00], // (22 in. by 34 in.) + PageSetup::PAPERSIZE_E => [2448.00, 3168.00], // (34 in. by 44 in.) + PageSetup::PAPERSIZE_DL_ENVELOPE => [311.81, 623.62], // (110 mm by 220 mm) + PageSetup::PAPERSIZE_C5_ENVELOPE => 'C5', // (162 mm by 229 mm) + PageSetup::PAPERSIZE_C3_ENVELOPE => 'C3', // (324 mm by 458 mm) + PageSetup::PAPERSIZE_C4_ENVELOPE => 'C4', // (229 mm by 324 mm) + PageSetup::PAPERSIZE_C6_ENVELOPE => 'C6', // (114 mm by 162 mm) + PageSetup::PAPERSIZE_C65_ENVELOPE => [323.15, 649.13], // (114 mm by 229 mm) + PageSetup::PAPERSIZE_B4_ENVELOPE => 'B4', // (250 mm by 353 mm) + PageSetup::PAPERSIZE_B5_ENVELOPE => 'B5', // (176 mm by 250 mm) + PageSetup::PAPERSIZE_B6_ENVELOPE => [498.90, 354.33], // (176 mm by 125 mm) + PageSetup::PAPERSIZE_ITALY_ENVELOPE => [311.81, 651.97], // (110 mm by 230 mm) + PageSetup::PAPERSIZE_MONARCH_ENVELOPE => [279.00, 540.00], // (3.875 in. by 7.5 in.) + PageSetup::PAPERSIZE_6_3_4_ENVELOPE => [261.00, 468.00], // (3.625 in. by 6.5 in.) + PageSetup::PAPERSIZE_US_STANDARD_FANFOLD => [1071.00, 792.00], // (14.875 in. by 11 in.) + PageSetup::PAPERSIZE_GERMAN_STANDARD_FANFOLD => [612.00, 864.00], // (8.5 in. by 12 in.) + PageSetup::PAPERSIZE_GERMAN_LEGAL_FANFOLD => 'FOLIO', // (8.5 in. by 13 in.) + PageSetup::PAPERSIZE_ISO_B4 => 'B4', // (250 mm by 353 mm) + PageSetup::PAPERSIZE_JAPANESE_DOUBLE_POSTCARD => [566.93, 419.53], // (200 mm by 148 mm) + PageSetup::PAPERSIZE_STANDARD_PAPER_1 => [648.00, 792.00], // (9 in. by 11 in.) + PageSetup::PAPERSIZE_STANDARD_PAPER_2 => [720.00, 792.00], // (10 in. by 11 in.) + PageSetup::PAPERSIZE_STANDARD_PAPER_3 => [1080.00, 792.00], // (15 in. by 11 in.) + PageSetup::PAPERSIZE_INVITE_ENVELOPE => [623.62, 623.62], // (220 mm by 220 mm) + PageSetup::PAPERSIZE_LETTER_EXTRA_PAPER => [667.80, 864.00], // (9.275 in. by 12 in.) + PageSetup::PAPERSIZE_LEGAL_EXTRA_PAPER => [667.80, 1080.00], // (9.275 in. by 15 in.) + PageSetup::PAPERSIZE_TABLOID_EXTRA_PAPER => [841.68, 1296.00], // (11.69 in. by 18 in.) + PageSetup::PAPERSIZE_A4_EXTRA_PAPER => [668.98, 912.76], // (236 mm by 322 mm) + PageSetup::PAPERSIZE_LETTER_TRANSVERSE_PAPER => [595.80, 792.00], // (8.275 in. by 11 in.) + PageSetup::PAPERSIZE_A4_TRANSVERSE_PAPER => 'A4', // (210 mm by 297 mm) + PageSetup::PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER => [667.80, 864.00], // (9.275 in. by 12 in.) + PageSetup::PAPERSIZE_SUPERA_SUPERA_A4_PAPER => [643.46, 1009.13], // (227 mm by 356 mm) + PageSetup::PAPERSIZE_SUPERB_SUPERB_A3_PAPER => [864.57, 1380.47], // (305 mm by 487 mm) + PageSetup::PAPERSIZE_LETTER_PLUS_PAPER => [612.00, 913.68], // (8.5 in. by 12.69 in.) + PageSetup::PAPERSIZE_A4_PLUS_PAPER => [595.28, 935.43], // (210 mm by 330 mm) + PageSetup::PAPERSIZE_A5_TRANSVERSE_PAPER => 'A5', // (148 mm by 210 mm) + PageSetup::PAPERSIZE_JIS_B5_TRANSVERSE_PAPER => [515.91, 728.50], // (182 mm by 257 mm) + PageSetup::PAPERSIZE_A3_EXTRA_PAPER => [912.76, 1261.42], // (322 mm by 445 mm) + PageSetup::PAPERSIZE_A5_EXTRA_PAPER => [493.23, 666.14], // (174 mm by 235 mm) + PageSetup::PAPERSIZE_ISO_B5_EXTRA_PAPER => [569.76, 782.36], // (201 mm by 276 mm) + PageSetup::PAPERSIZE_A2_PAPER => 'A2', // (420 mm by 594 mm) + PageSetup::PAPERSIZE_A3_TRANSVERSE_PAPER => 'A3', // (297 mm by 420 mm) + PageSetup::PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER => [912.76, 1261.42], // (322 mm by 445 mm) ]; /** * Create a new PDF Writer instance. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet Spreadsheet object + * @param Spreadsheet $spreadsheet Spreadsheet object */ - public function __construct(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function __construct(Spreadsheet $spreadsheet) { parent::__construct($spreadsheet); $this->setUseInlineCss(true); - $this->tempDir = \PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir(); + $this->tempDir = File::sysGetTempDir(); } /** @@ -186,7 +193,7 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html /** * Set Paper Size. * - * @param string $pValue Paper size see \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_* + * @param string $pValue Paper size see PageSetup::PAPERSIZE_* * * @return self */ @@ -210,7 +217,7 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html /** * Set Orientation. * - * @param string $pValue Page orientation see \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_* + * @param string $pValue Page orientation see PageSetup::ORIENTATION_* * * @return self */ @@ -236,7 +243,7 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html * * @param string $pValue Temporary storage directory * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception when directory does not exist + * @throws WriterException when directory does not exist * * @return self */ @@ -245,7 +252,7 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html if (is_dir($pValue)) { $this->tempDir = $pValue; } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Directory does not exist: $pValue"); + throw new WriterException("Directory does not exist: $pValue"); } return $this; @@ -256,20 +263,20 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html * * @param string $pFilename Name of the file to save as * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ protected function prepareForSave($pFilename) { // garbage collect $this->spreadsheet->garbageCollect(); - $this->saveArrayReturnType = \PhpOffice\PhpSpreadsheet\Calculation::getArrayReturnType(); - \PhpOffice\PhpSpreadsheet\Calculation::setArrayReturnType(\PhpOffice\PhpSpreadsheet\Calculation::RETURN_ARRAY_AS_VALUE); + $this->saveArrayReturnType = Calculation::getArrayReturnType(); + Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not open file $pFilename for writing."); + throw new WriterException("Could not open file $pFilename for writing."); } // Set PDF @@ -285,13 +292,13 @@ abstract class Core extends \PhpOffice\PhpSpreadsheet\Writer\Html * * @param resource $fileHandle * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ protected function restoreStateAfterSave($fileHandle) { // Close file fclose($fileHandle); - \PhpOffice\PhpSpreadsheet\Calculation::setArrayReturnType($this->saveArrayReturnType); + Calculation::setArrayReturnType($this->saveArrayReturnType); } } diff --git a/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php b/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php index 2ddba79e..75456b8b 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php +++ b/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; +use PhpOffice\PhpSpreadsheet\Writer\IWriter; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class DomPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter +class DomPDF extends Core implements IWriter { /** * Save Spreadsheet to file. @@ -43,12 +46,12 @@ class DomPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() - == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins(); } else { $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() - == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); } @@ -57,8 +60,8 @@ class DomPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter // Override Page Orientation if (!is_null($this->getOrientation())) { - $orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_DEFAULT) - ? \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT + $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_DEFAULT) + ? PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } // Override Paper Size diff --git a/src/PhpSpreadsheet/Writer/Pdf/MPDF.php b/src/PhpSpreadsheet/Writer/Pdf/MPDF.php index 06cb83e1..425b132e 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/MPDF.php +++ b/src/PhpSpreadsheet/Writer/Pdf/MPDF.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; +use PhpOffice\PhpSpreadsheet\Writer\IWriter; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -24,7 +28,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class MPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter +class MPDF extends Core implements IWriter { /** * Save Spreadsheet to file. @@ -32,7 +36,7 @@ class MPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter * @param string $pFilename Name of the file to save as * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException */ public function save($pFilename) { @@ -44,12 +48,12 @@ class MPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter // Check for paper size and page orientation if (null === $this->getSheetIndex()) { $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() - == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins(); } else { $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() - == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); } @@ -57,8 +61,8 @@ class MPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter // Override Page Orientation if (null !== $this->getOrientation()) { - $orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_DEFAULT) - ? \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT + $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_DEFAULT) + ? PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } $orientation = strtoupper($orientation); diff --git a/src/PhpSpreadsheet/Writer/Pdf/TcPDF.php b/src/PhpSpreadsheet/Writer/Pdf/TcPDF.php index 858ff27e..33fc48a0 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/TcPDF.php +++ b/src/PhpSpreadsheet/Writer/Pdf/TcPDF.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; +use PhpOffice\PhpSpreadsheet\Writer\IWriter; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -24,7 +27,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ -class TcPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter +class TcPDF extends Core implements IWriter { /** * Save Spreadsheet to file. @@ -43,19 +46,19 @@ class TcPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() - == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins(); } else { $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() - == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); } // Override Page Orientation if (!is_null($this->getOrientation())) { - $orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) + $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; } diff --git a/src/PhpSpreadsheet/Writer/Xls.php b/src/PhpSpreadsheet/Writer/Xls.php index 30698647..8f08ba48 100644 --- a/src/PhpSpreadsheet/Writer/Xls.php +++ b/src/PhpSpreadsheet/Writer/Xls.php @@ -2,6 +2,28 @@ namespace PhpOffice\PhpSpreadsheet\Writer; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\Drawing as SharedDrawing; +use PhpOffice\PhpSpreadsheet\Shared\Escher; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip; +use PhpOffice\PhpSpreadsheet\Shared\OLE; +use PhpOffice\PhpSpreadsheet\Shared\OLE\PPS\File; +use PhpOffice\PhpSpreadsheet\Shared\OLE\PPS\Root; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing; +use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; +use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; +use RuntimeException; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,7 +51,7 @@ class Xls extends BaseWriter implements IWriter /** * PhpSpreadsheet object. * - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $spreadsheet; @@ -92,9 +114,9 @@ class Xls extends BaseWriter implements IWriter /** * Create a new Xls Writer. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet PhpSpreadsheet object + * @param Spreadsheet $spreadsheet PhpSpreadsheet object */ - public function __construct(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function __construct(Spreadsheet $spreadsheet) { $this->spreadsheet = $spreadsheet; @@ -113,10 +135,10 @@ class Xls extends BaseWriter implements IWriter // garbage collect $this->spreadsheet->garbageCollect(); - $saveDebugLog = \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadsheet)->getDebugLog()->getWriteDebugLog(); - \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog(false); - $saveDateReturnType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(); - \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL); + $saveDebugLog = Calculation::getInstance($this->spreadsheet)->getDebugLog()->getWriteDebugLog(); + Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog(false); + $saveDateReturnType = Functions::getReturnDateType(); + Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); // initialize colors array $this->colors = []; @@ -151,10 +173,10 @@ class Xls extends BaseWriter implements IWriter foreach ($this->writerWorksheets[$i]->phpSheet->getCoordinates() as $coordinate) { $cell = $this->writerWorksheets[$i]->phpSheet->getCell($coordinate); $cVal = $cell->getValue(); - if ($cVal instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if ($cVal instanceof RichText) { $elements = $cVal->getRichTextElements(); foreach ($elements as $element) { - if ($element instanceof \PhpOffice\PhpSpreadsheet\RichText\Run) { + if ($element instanceof RichText\Run) { $font = $element->getFont(); $this->writerWorksheets[$i]->fontHashIndex[$font->getHashCode()] = $this->writerWorkbook->addFont($font); } @@ -165,7 +187,7 @@ class Xls extends BaseWriter implements IWriter // initialize OLE file $workbookStreamName = 'Workbook'; - $OLE = new \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS\File(\PhpOffice\PhpSpreadsheet\Shared\OLE::ascToUcs($workbookStreamName)); + $OLE = new File(OLE::ascToUcs($workbookStreamName)); // Write the worksheet streams before the global workbook stream, // because the byte sizes of these are needed in the global workbook stream @@ -186,14 +208,14 @@ class Xls extends BaseWriter implements IWriter $this->documentSummaryInformation = $this->writeDocumentSummaryInformation(); // initialize OLE Document Summary Information if (isset($this->documentSummaryInformation) && !empty($this->documentSummaryInformation)) { - $OLE_DocumentSummaryInformation = new \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS\File(\PhpOffice\PhpSpreadsheet\Shared\OLE::ascToUcs(chr(5) . 'DocumentSummaryInformation')); + $OLE_DocumentSummaryInformation = new File(OLE::ascToUcs(chr(5) . 'DocumentSummaryInformation')); $OLE_DocumentSummaryInformation->append($this->documentSummaryInformation); } $this->summaryInformation = $this->writeSummaryInformation(); // initialize OLE Summary Information if (isset($this->summaryInformation) && !empty($this->summaryInformation)) { - $OLE_SummaryInformation = new \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS\File(\PhpOffice\PhpSpreadsheet\Shared\OLE::ascToUcs(chr(5) . 'SummaryInformation')); + $OLE_SummaryInformation = new File(OLE::ascToUcs(chr(5) . 'SummaryInformation')); $OLE_SummaryInformation->append($this->summaryInformation); } @@ -208,12 +230,12 @@ class Xls extends BaseWriter implements IWriter $arrRootData[] = $OLE_DocumentSummaryInformation; } - $root = new \PhpOffice\PhpSpreadsheet\Shared\OLE\PPS\Root(time(), time(), $arrRootData); + $root = new Root(time(), time(), $arrRootData); // save the OLE file $res = $root->save($pFilename); - \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($saveDateReturnType); - \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); + Functions::setReturnDateType($saveDateReturnType); + Calculation::getInstance($this->spreadsheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); } /** @@ -239,10 +261,10 @@ class Xls extends BaseWriter implements IWriter } // create intermediate Escher object - $escher = new \PhpOffice\PhpSpreadsheet\Shared\Escher(); + $escher = new Escher(); // dgContainer - $dgContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer(); + $dgContainer = new DgContainer(); // set the drawing index (we use sheet index + 1) $dgId = $sheet->getParent()->getIndex($sheet) + 1; @@ -250,11 +272,11 @@ class Xls extends BaseWriter implements IWriter $escher->setDgContainer($dgContainer); // spgrContainer - $spgrContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer(); + $spgrContainer = new SpgrContainer(); $dgContainer->setSpgrContainer($spgrContainer); // add one shape which is the group shape - $spContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer(); + $spContainer = new SpContainer(); $spContainer->setSpgr(true); $spContainer->setSpType(0); $spContainer->setSpId(($sheet->getParent()->getIndex($sheet) + 1) << 10); @@ -270,7 +292,7 @@ class Xls extends BaseWriter implements IWriter ++$countShapes[$sheetIndex]; // add the shape - $spContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer(); + $spContainer = new SpContainer(); // set the shape type $spContainer->setSpType(0x004B); @@ -312,7 +334,7 @@ class Xls extends BaseWriter implements IWriter // AutoFilters if (!empty($filterRange)) { - $rangeBounds = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($filterRange); + $rangeBounds = Cell::rangeBoundaries($filterRange); $iNumColStart = $rangeBounds[0][0]; $iNumColEnd = $rangeBounds[1][0]; @@ -321,14 +343,14 @@ class Xls extends BaseWriter implements IWriter ++$countShapes[$sheetIndex]; // create an Drawing Object for the dropdown - $oDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing(); + $oDrawing = new BaseDrawing(); // get the coordinates of drawing - $cDrawing = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($iInc - 1) . $rangeBounds[0][1]; + $cDrawing = Cell::stringFromColumnIndex($iInc - 1) . $rangeBounds[0][1]; $oDrawing->setCoordinates($cDrawing); $oDrawing->setWorksheet($sheet); // add the shape - $spContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer(); + $spContainer = new SpContainer(); // set the shape type $spContainer->setSpType(0x00C9); // set the shape flag @@ -352,7 +374,7 @@ class Xls extends BaseWriter implements IWriter $spContainer->setOPT(0x03BF, 0x000A0000); // Group Shape -> fPrint // set coordinates and offsets, client anchor - $endCoordinates = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($iInc - 1); + $endCoordinates = Cell::stringFromColumnIndex($iInc - 1); $endCoordinates .= $rangeBounds[0][1] + 1; $spContainer->setStartCoordinates($cDrawing); @@ -400,10 +422,10 @@ class Xls extends BaseWriter implements IWriter } // if we reach here, then there are drawings in the workbook - $escher = new \PhpOffice\PhpSpreadsheet\Shared\Escher(); + $escher = new Escher(); // dggContainer - $dggContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer(); + $dggContainer = new DggContainer(); $escher->setDggContainer($dggContainer); // set IDCLs (identifier clusters) @@ -435,40 +457,40 @@ class Xls extends BaseWriter implements IWriter $dggContainer->setCSpSaved($totalCountShapes + $countDrawings); // total number of shapes incl. one group shapes per drawing // bstoreContainer - $bstoreContainer = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer(); + $bstoreContainer = new BstoreContainer(); $dggContainer->setBstoreContainer($bstoreContainer); // the BSE's (all the images) foreach ($this->spreadsheet->getAllsheets() as $sheet) { foreach ($sheet->getDrawingCollection() as $drawing) { if (!extension_loaded('gd')) { - throw new \RuntimeException('Saving images in xls requires gd extension'); + throw new RuntimeException('Saving images in xls requires gd extension'); } - if ($drawing instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing) { + if ($drawing instanceof Drawing) { $filename = $drawing->getPath(); list($imagesx, $imagesy, $imageFormat) = getimagesize($filename); switch ($imageFormat) { case 1: // GIF, not supported by BIFF8, we convert to PNG - $blipType = \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_PNG; + $blipType = BSE::BLIPTYPE_PNG; ob_start(); imagepng(imagecreatefromgif($filename)); $blipData = ob_get_contents(); ob_end_clean(); break; case 2: // JPEG - $blipType = \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_JPEG; + $blipType = BSE::BLIPTYPE_JPEG; $blipData = file_get_contents($filename); break; case 3: // PNG - $blipType = \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_PNG; + $blipType = BSE::BLIPTYPE_PNG; $blipData = file_get_contents($filename); break; case 6: // Windows DIB (BMP), we convert to PNG - $blipType = \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_PNG; + $blipType = BSE::BLIPTYPE_PNG; ob_start(); - imagepng(\PhpOffice\PhpSpreadsheet\Shared\Drawing::imagecreatefrombmp($filename)); + imagepng(SharedDrawing::imagecreatefrombmp($filename)); $blipData = ob_get_contents(); ob_end_clean(); break; @@ -476,24 +498,24 @@ class Xls extends BaseWriter implements IWriter continue 2; } - $blip = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip(); + $blip = new Blip(); $blip->setData($blipData); - $BSE = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE(); + $BSE = new BSE(); $BSE->setBlipType($blipType); $BSE->setBlip($blip); $bstoreContainer->addBSE($BSE); - } elseif ($drawing instanceof \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing) { + } elseif ($drawing instanceof MemoryDrawing) { switch ($drawing->getRenderingFunction()) { - case \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG: - $blipType = \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_JPEG; + case MemoryDrawing::RENDERING_JPEG: + $blipType = BSE::BLIPTYPE_JPEG; $renderingFunction = 'imagejpeg'; break; - case \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_GIF: - case \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_PNG: - case \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_DEFAULT: - $blipType = \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_PNG; + case MemoryDrawing::RENDERING_GIF: + case MemoryDrawing::RENDERING_PNG: + case MemoryDrawing::RENDERING_DEFAULT: + $blipType = BSE::BLIPTYPE_PNG; $renderingFunction = 'imagepng'; break; } @@ -503,10 +525,10 @@ class Xls extends BaseWriter implements IWriter $blipData = ob_get_contents(); ob_end_clean(); - $blip = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip(); + $blip = new Blip(); $blip->setData($blipData); - $BSE = new \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE(); + $BSE = new BSE(); $BSE->setBlipType($blipType); $BSE->setBlip($blip); @@ -847,7 +869,7 @@ class Xls extends BaseWriter implements IWriter 'summary' => ['pack' => 'V', 'data' => 0x0C], 'offset' => ['pack' => 'V'], 'type' => ['pack' => 'V', 'data' => 0x40], // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) - 'data' => ['data' => \PhpOffice\PhpSpreadsheet\Shared\OLE::localDateToOLE($dataProp)], + 'data' => ['data' => OLE::localDateToOLE($dataProp)], ]; ++$dataSection_NumProps; } @@ -858,7 +880,7 @@ class Xls extends BaseWriter implements IWriter 'summary' => ['pack' => 'V', 'data' => 0x0D], 'offset' => ['pack' => 'V'], 'type' => ['pack' => 'V', 'data' => 0x40], // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) - 'data' => ['data' => \PhpOffice\PhpSpreadsheet\Shared\OLE::localDateToOLE($dataProp)], + 'data' => ['data' => OLE::localDateToOLE($dataProp)], ]; ++$dataSection_NumProps; } diff --git a/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php b/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php index a45ba07b..e250254c 100644 --- a/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php +++ b/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -117,7 +119,7 @@ class BIFFwriter $byte_order = 1; // Big Endian } else { // Give up. I'll fix this in a later version. - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Required floating point format not supported on this platform.'); + throw new WriterException('Required floating point format not supported on this platform.'); } self::$byteOrder = $byte_order; } diff --git a/src/PhpSpreadsheet/Writer/Xls/Escher.php b/src/PhpSpreadsheet/Writer/Xls/Escher.php index 8926b192..adff2ae9 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Escher.php +++ b/src/PhpSpreadsheet/Writer/Xls/Escher.php @@ -2,6 +2,15 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE; +use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -83,7 +92,7 @@ class Escher $this->spTypes = $writer->getSpTypes(); } break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer::class: + case DggContainer::class: // this is a container record // initialize @@ -136,7 +145,7 @@ class Escher $this->data = $header . $innerData; break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer::class: + case BstoreContainer::class: // this is a container record // initialize @@ -163,7 +172,7 @@ class Escher $this->data = $header . $innerData; break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::class: + case BSE::class: // this is a semi-container record // initialize @@ -212,12 +221,12 @@ class Escher $this->data .= $data; break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE\Blip::class: + case Blip::class: // this is an atom record // write the record switch ($this->object->getParent()->getBlipType()) { - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_JPEG: + case BSE::BLIPTYPE_JPEG: // initialize $innerData = ''; @@ -243,7 +252,7 @@ class Escher $this->data .= $innerData; break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer\BstoreContainer\BSE::BLIPTYPE_PNG: + case BSE::BLIPTYPE_PNG: // initialize $innerData = ''; @@ -271,7 +280,7 @@ class Escher break; } break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer::class: + case DgContainer::class: // this is a container record // initialize @@ -323,7 +332,7 @@ class Escher $this->data = $header . $innerData; break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer::class: + case SpgrContainer::class: // this is a container record // initialize @@ -362,7 +371,7 @@ class Escher $this->spOffsets = $spOffsets; $this->spTypes = $spTypes; break; - case \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer::class: + case SpContainer::class: // initialize $data = ''; @@ -425,8 +434,8 @@ class Escher $recType = 0xF010; // start coordinates - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($this->object->getStartCoordinates()); - $c1 = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1; + list($column, $row) = Cell::coordinateFromString($this->object->getStartCoordinates()); + $c1 = Cell::columnIndexFromString($column) - 1; $r1 = $row - 1; // start offsetX @@ -436,8 +445,8 @@ class Escher $startOffsetY = $this->object->getStartOffsetY(); // end coordinates - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($this->object->getEndCoordinates()); - $c2 = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1; + list($column, $row) = Cell::coordinateFromString($this->object->getEndCoordinates()); + $c2 = Cell::columnIndexFromString($column) - 1; $r2 = $row - 1; // end offsetX diff --git a/src/PhpSpreadsheet/Writer/Xls/Font.php b/src/PhpSpreadsheet/Writer/Xls/Font.php index ba5c51bd..127bd331 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Font.php +++ b/src/PhpSpreadsheet/Writer/Xls/Font.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -72,9 +74,9 @@ class Font $font_shadow = 0; $icv = $this->colorIndex; // Index to color palette - if ($this->font->getSuperScript()) { + if ($this->font->getSuperscript()) { $sss = 1; - } elseif ($this->font->getSubScript()) { + } elseif ($this->font->getSubscript()) { $sss = 2; } else { $sss = 0; @@ -82,9 +84,9 @@ class Font $bFamily = 0; // Font family $bCharSet = \PhpOffice\PhpSpreadsheet\Shared\Font::getCharsetFromFontName($this->font->getName()); // Character set - $record = 0x31; // Record identifier - $reserved = 0x00; // Reserved - $grbit = 0x00; // Font attributes + $record = 0x31; // Record identifier + $reserved = 0x00; // Reserved + $grbit = 0x00; // Font attributes if ($this->font->getItalic()) { $grbit |= 0x02; } @@ -114,7 +116,7 @@ class Font $bCharSet, $reserved ); - $data .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort($this->font->getName()); + $data .= StringHelper::UTF8toBIFF8UnicodeShort($this->font->getName()); $length = strlen($data); $header = pack('vv', $record, $length); @@ -132,10 +134,10 @@ class Font private static function mapBold($bold) { if ($bold) { - return 0x2BC; // 700 = Bold font weight + return 0x2BC; // 700 = Bold font weight } - return 0x190; // 400 = Normal font weight + return 0x190; // 400 = Normal font weight } /** diff --git a/src/PhpSpreadsheet/Writer/Xls/Parser.php b/src/PhpSpreadsheet/Writer/Xls/Parser.php index dfa8bec5..f8243991 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Parser.php +++ b/src/PhpSpreadsheet/Writer/Xls/Parser.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -548,7 +551,7 @@ class Parser } // TODO: use real error codes - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown token $token"); + throw new WriterException("Unknown token $token"); } /** @@ -583,10 +586,10 @@ class Parser // chop away beggining and ending quotes $string = substr($string, 1, strlen($string) - 2); if (strlen($string) > 255) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('String is too long'); + throw new WriterException('String is too long'); } - return pack('C', $this->ptg['ptgStr']) . \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort($string); + return pack('C', $this->ptg['ptgStr']) . StringHelper::UTF8toBIFF8UnicodeShort($string); } /** @@ -626,7 +629,7 @@ class Parser list($cell1, $cell2) = explode(':', $range); } else { // TODO: use real error codes - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Unknown range separator'); + throw new WriterException('Unknown range separator'); } // Convert the cell references @@ -642,7 +645,7 @@ class Parser $ptgArea = pack('C', $this->ptg['ptgAreaA']); } else { // TODO: use real error codes - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown class $class"); + throw new WriterException("Unknown class $class"); } return $ptgArea . $row1 . $row2 . $col1 . $col2; @@ -773,11 +776,11 @@ class Parser $sheet1 = $this->getSheetIndex($sheet_name1); if ($sheet1 == -1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown sheet name $sheet_name1 in formula"); + throw new WriterException("Unknown sheet name $sheet_name1 in formula"); } $sheet2 = $this->getSheetIndex($sheet_name2); if ($sheet2 == -1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown sheet name $sheet_name2 in formula"); + throw new WriterException("Unknown sheet name $sheet_name2 in formula"); } // Reverse max and min sheet numbers if necessary @@ -787,7 +790,7 @@ class Parser } else { // Single sheet name only. $sheet1 = $this->getSheetIndex($ext_ref); if ($sheet1 == -1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown sheet name $ext_ref in formula"); + throw new WriterException("Unknown sheet name $ext_ref in formula"); } $sheet2 = $sheet1; } @@ -819,11 +822,11 @@ class Parser $sheet1 = $this->getSheetIndex($sheet_name1); if ($sheet1 == -1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown sheet name $sheet_name1 in formula"); + throw new WriterException("Unknown sheet name $sheet_name1 in formula"); } $sheet2 = $this->getSheetIndex($sheet_name2); if ($sheet2 == -1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown sheet name $sheet_name2 in formula"); + throw new WriterException("Unknown sheet name $sheet_name2 in formula"); } // Reverse max and min sheet numbers if necessary @@ -833,7 +836,7 @@ class Parser } else { // Single sheet name only. $sheet1 = $this->getSheetIndex($ext_ref); if ($sheet1 == -1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Unknown sheet name $ext_ref in formula"); + throw new WriterException("Unknown sheet name $ext_ref in formula"); } $sheet2 = $sheet1; } @@ -903,10 +906,10 @@ class Parser $cell = strtoupper($cell); list($row, $col, $row_rel, $col_rel) = $this->cellToRowcol($cell); if ($col >= 256) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Column in: $cell greater than 255"); + throw new WriterException("Column in: $cell greater than 255"); } if ($row >= 65536) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Row in: $cell greater than 65536 "); + throw new WriterException("Row in: $cell greater than 65536 "); } // Set the high bits to indicate if row or col are relative. @@ -944,7 +947,7 @@ class Parser // FIXME: this changes for BIFF8 if (($row1 >= 65536) or ($row2 >= 65536)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Row in: $range greater than 65536 "); + throw new WriterException("Row in: $range greater than 65536 "); } // Set the high bits to indicate if rows are relative. @@ -1307,7 +1310,7 @@ class Parser $this->advance(); // eat the "(" $result = $this->parenthesizedExpression(); if ($this->currentToken != ')') { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("')' token expected."); + throw new WriterException("')' token expected."); } $this->advance(); // eat the ")" return $result; @@ -1369,7 +1372,7 @@ class Parser return $result; } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Syntax error: ' . $this->currentToken . ', lookahead: ' . $this->lookAhead . ', current char: ' . $this->currentCharacter); + throw new WriterException('Syntax error: ' . $this->currentToken . ', lookahead: ' . $this->lookAhead . ', current char: ' . $this->currentCharacter); } /** @@ -1390,7 +1393,7 @@ class Parser if ($this->currentToken == ',' || $this->currentToken == ';') { $this->advance(); // eat the "," or ";" } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Syntax error: comma expected in function $function, arg #{$num_args}"); + throw new WriterException("Syntax error: comma expected in function $function, arg #{$num_args}"); } $result2 = $this->condition(); $result = $this->createTree('arg', $result, $result2); @@ -1401,12 +1404,12 @@ class Parser ++$num_args; } if (!isset($this->functions[$function])) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Function $function() doesn't exist"); + throw new WriterException("Function $function() doesn't exist"); } $args = $this->functions[$function][1]; // If fixed number of args eg. TIME($i, $j, $k). Check that the number of args is valid. if (($args >= 0) and ($args != $num_args)) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Incorrect number of arguments in function $function() "); + throw new WriterException("Incorrect number of arguments in function $function() "); } $result = $this->createTree($function, $result, $num_args); diff --git a/src/PhpSpreadsheet/Writer/Xls/Workbook.php b/src/PhpSpreadsheet/Writer/Xls/Workbook.php index 2f2056e1..a493a8bf 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Workbook.php +++ b/src/PhpSpreadsheet/Writer/Xls/Workbook.php @@ -2,6 +2,12 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -108,14 +114,14 @@ class Workbook extends BIFFwriter /** * Workbook. * - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $spreadsheet; /** * Fonts writers. * - * @var \PhpOffice\PhpSpreadsheet\Writer\Xls\Font[] + * @var Font[] */ private $fontWriters = []; @@ -190,14 +196,14 @@ class Workbook extends BIFFwriter /** * Class constructor. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet The Workbook + * @param Spreadsheet $spreadsheet The Workbook * @param int $str_total Total number of strings * @param int $str_unique Total number of unique strings * @param array $str_table String Table * @param array $colors Colour Table * @param Parser $parser The formula parser created for the Workbook */ - public function __construct(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet, &$str_total, &$str_unique, &$str_table, &$colors, Parser $parser) + public function __construct(Spreadsheet $spreadsheet, &$str_total, &$str_unique, &$str_table, &$colors, Parser $parser) { // It needs to call its parent's constructor explicitly parent::__construct(); @@ -306,7 +312,7 @@ class Workbook extends BIFFwriter $countFonts = count($this->fontWriters); $fontIndex = ($countFonts < 4) ? $countFonts : $countFonts + 1; - $fontWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xls\Font($font); + $fontWriter = new Font($font); $fontWriter->setColorIndex($this->addColor($font->getColor()->getRGB())); $this->fontWriters[] = $fontWriter; @@ -484,7 +490,7 @@ class Workbook extends BIFFwriter // add size of Workbook globals part 2, the length of the SHEET records $total_worksheets = count($this->spreadsheet->getAllSheets()); foreach ($this->spreadsheet->getWorksheetIterator() as $sheet) { - $offset += $boundsheet_length + strlen(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort($sheet->getTitle())); + $offset += $boundsheet_length + strlen(StringHelper::UTF8toBIFF8UnicodeShort($sheet->getTitle())); } // add the sizes of each of the Sheet substreams, respectively @@ -563,15 +569,15 @@ class Workbook extends BIFFwriter // Write a Name record if the print area has been defined if ($sheetSetup->isPrintAreaSet()) { // Print area - $printArea = \PhpOffice\PhpSpreadsheet\Cell::splitRange($sheetSetup->getPrintArea()); + $printArea = Cell::splitRange($sheetSetup->getPrintArea()); $printArea = $printArea[0]; - $printArea[0] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($printArea[0]); - $printArea[1] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($printArea[1]); + $printArea[0] = Cell::coordinateFromString($printArea[0]); + $printArea[1] = Cell::coordinateFromString($printArea[1]); $print_rowmin = $printArea[0][1] - 1; $print_rowmax = $printArea[1][1] - 1; - $print_colmin = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($printArea[0][0]) - 1; - $print_colmax = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($printArea[1][0]) - 1; + $print_colmin = Cell::columnIndexFromString($printArea[0][0]) - 1; + $print_colmax = Cell::columnIndexFromString($printArea[1][0]) - 1; $this->writeNameShort( $i, // sheet index @@ -591,8 +597,8 @@ class Workbook extends BIFFwriter // simultaneous repeatColumns repeatRows if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) { $repeat = $sheetSetup->getColumnsToRepeatAtLeft(); - $colmin = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[0]) - 1; - $colmax = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[1]) - 1; + $colmin = Cell::columnIndexFromString($repeat[0]) - 1; + $colmax = Cell::columnIndexFromString($repeat[1]) - 1; $repeat = $sheetSetup->getRowsToRepeatAtTop(); $rowmin = $repeat[0] - 1; @@ -612,8 +618,8 @@ class Workbook extends BIFFwriter // Columns to repeat if ($sheetSetup->isColumnsToRepeatAtLeftSet()) { $repeat = $sheetSetup->getColumnsToRepeatAtLeft(); - $colmin = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[0]) - 1; - $colmax = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[1]) - 1; + $colmin = Cell::columnIndexFromString($repeat[0]) - 1; + $colmax = Cell::columnIndexFromString($repeat[1]) - 1; } else { $colmin = 0; $colmax = 255; @@ -655,14 +661,14 @@ class Workbook extends BIFFwriter $namedRanges = $this->spreadsheet->getNamedRanges(); foreach ($namedRanges as $namedRange) { // Create absolute coordinate - $range = \PhpOffice\PhpSpreadsheet\Cell::splitRange($namedRange->getRange()); + $range = Cell::splitRange($namedRange->getRange()); for ($i = 0; $i < count($range); ++$i) { - $range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . \PhpOffice\PhpSpreadsheet\Cell::absoluteCoordinate($range[$i][0]); + $range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . Cell::absoluteCoordinate($range[$i][0]); if (isset($range[$i][1])) { - $range[$i][1] = \PhpOffice\PhpSpreadsheet\Cell::absoluteCoordinate($range[$i][1]); + $range[$i][1] = Cell::absoluteCoordinate($range[$i][1]); } } - $range = \PhpOffice\PhpSpreadsheet\Cell::buildRange($range); // e.g. Sheet1!$A$1:$B$2 + $range = Cell::buildRange($range); // e.g. Sheet1!$A$1:$B$2 // parse formula try { @@ -682,7 +688,7 @@ class Workbook extends BIFFwriter $scope = 0; } $chunk .= $this->writeData($this->writeDefinedNameBiff8($namedRange->getName(), $formulaData, $scope, false)); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { // do nothing } } @@ -697,8 +703,8 @@ class Workbook extends BIFFwriter // simultaneous repeatColumns repeatRows if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) { $repeat = $sheetSetup->getColumnsToRepeatAtLeft(); - $colmin = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[0]) - 1; - $colmax = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[1]) - 1; + $colmin = Cell::columnIndexFromString($repeat[0]) - 1; + $colmax = Cell::columnIndexFromString($repeat[1]) - 1; $repeat = $sheetSetup->getRowsToRepeatAtTop(); $rowmin = $repeat[0] - 1; @@ -718,8 +724,8 @@ class Workbook extends BIFFwriter // Columns to repeat if ($sheetSetup->isColumnsToRepeatAtLeftSet()) { $repeat = $sheetSetup->getColumnsToRepeatAtLeft(); - $colmin = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[0]) - 1; - $colmax = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($repeat[1]) - 1; + $colmin = Cell::columnIndexFromString($repeat[0]) - 1; + $colmax = Cell::columnIndexFromString($repeat[1]) - 1; } else { $colmin = 0; $colmax = 255; @@ -747,19 +753,19 @@ class Workbook extends BIFFwriter $sheetSetup = $this->spreadsheet->getSheet($i)->getPageSetup(); if ($sheetSetup->isPrintAreaSet()) { // Print area, e.g. A3:J6,H1:X20 - $printArea = \PhpOffice\PhpSpreadsheet\Cell::splitRange($sheetSetup->getPrintArea()); + $printArea = Cell::splitRange($sheetSetup->getPrintArea()); $countPrintArea = count($printArea); $formulaData = ''; for ($j = 0; $j < $countPrintArea; ++$j) { $printAreaRect = $printArea[$j]; // e.g. A3:J6 - $printAreaRect[0] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($printAreaRect[0]); - $printAreaRect[1] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($printAreaRect[1]); + $printAreaRect[0] = Cell::coordinateFromString($printAreaRect[0]); + $printAreaRect[1] = Cell::coordinateFromString($printAreaRect[1]); $print_rowmin = $printAreaRect[0][1] - 1; $print_rowmax = $printAreaRect[1][1] - 1; - $print_colmin = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($printAreaRect[0][0]) - 1; - $print_colmax = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($printAreaRect[1][0]) - 1; + $print_colmin = Cell::columnIndexFromString($printAreaRect[0][0]) - 1; + $print_colmax = Cell::columnIndexFromString($printAreaRect[1][0]) - 1; // construct formula data manually because parser does not recognize absolute 3d cell references $formulaData .= pack('Cvvvvv', 0x3B, $i, $print_rowmin, $print_rowmax, $print_colmin, $print_colmax); @@ -779,7 +785,7 @@ class Workbook extends BIFFwriter $sheetAutoFilter = $this->spreadsheet->getSheet($i)->getAutoFilter(); $autoFilterRange = $sheetAutoFilter->getRange(); if (!empty($autoFilterRange)) { - $rangeBounds = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($autoFilterRange); + $rangeBounds = Cell::rangeBoundaries($autoFilterRange); //Autofilter built in name $name = pack('C', 0x0D); @@ -809,10 +815,10 @@ class Workbook extends BIFFwriter $options = $isBuiltIn ? 0x20 : 0x00; // length of the name, character count - $nlen = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($name); + $nlen = StringHelper::countCharacters($name); // name with stripped length field - $name = substr(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($name), 2); + $name = substr(StringHelper::UTF8toBIFF8UnicodeLong($name), 2); // size of the formula (in bytes) $sz = strlen($formulaData); @@ -944,7 +950,7 @@ class Workbook extends BIFFwriter $grbit = 0x0000; // Visibility and sheet type $data = pack('VCC', $offset, $ss, $st); - $data .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort($sheetname); + $data .= StringHelper::UTF8toBIFF8UnicodeShort($sheetname); $length = strlen($data); $header = pack('vv', $record, $length); @@ -1012,7 +1018,7 @@ class Workbook extends BIFFwriter { $record = 0x041E; // Record identifier - $numberFormatString = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($format); + $numberFormatString = StringHelper::UTF8toBIFF8UnicodeLong($format); $length = 2 + strlen($numberFormatString); // Number of bytes to follow $header = pack('vv', $record, $length); @@ -1028,7 +1034,7 @@ class Workbook extends BIFFwriter $record = 0x0022; // Record identifier $length = 0x0002; // Bytes to follow - $f1904 = (\PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar() == \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904) + $f1904 = (Date::getExcelCalendar() == Date::CALENDAR_MAC_1904) ? 1 : 0; // Flag for 1904 date system @@ -1416,7 +1422,7 @@ class Workbook extends BIFFwriter { // write the Escher stream if necessary if (isset($this->escher)) { - $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls\Escher($this->escher); + $writer = new Escher($this->escher); $data = $writer->close(); $record = 0x00EB; diff --git a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php index 464df8c3..419d1121 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php @@ -2,6 +2,22 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Cell\DataValidation; +use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Shared\Xls; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Color; +use PhpOffice\PhpSpreadsheet\Style\Conditional; +use PhpOffice\PhpSpreadsheet\Style\Fill; +use PhpOffice\PhpSpreadsheet\Style\Protection; +use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; +use PhpOffice\PhpSpreadsheet\Worksheet\SheetView; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -266,8 +282,8 @@ class Worksheet extends BIFFwriter // Determine lowest and highest column and row $this->lastRowIndex = ($maxR > 65535) ? 65535 : $maxR; - $this->firstColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($minC); - $this->lastColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($maxC); + $this->firstColumnIndex = Cell::columnIndexFromString($minC); + $this->lastColumnIndex = Cell::columnIndexFromString($maxC); // if ($this->firstColumnIndex > 255) $this->firstColumnIndex = 255; if ($this->lastColumnIndex > 255) { @@ -316,7 +332,7 @@ class Worksheet extends BIFFwriter $width = $defaultWidth; - $columnLetter = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($i); + $columnLetter = Cell::stringFromColumnIndex($i); if (isset($columnDimensions[$columnLetter])) { $columnDimension = $columnDimensions[$columnLetter]; if ($columnDimension->getWidth() >= 0) { @@ -401,56 +417,56 @@ class Worksheet extends BIFFwriter foreach ($phpSheet->getCoordinates() as $coordinate) { $cell = $phpSheet->getCell($coordinate); $row = $cell->getRow() - 1; - $column = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($cell->getColumn()) - 1; + $column = Cell::columnIndexFromString($cell->getColumn()) - 1; // Don't break Excel break the code! if ($row > 65535 || $column > 255) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Rows or columns overflow! Excel5 has limit to 65535 rows and 255 columns. Use XLSX instead.'); + throw new WriterException('Rows or columns overflow! Excel5 has limit to 65535 rows and 255 columns. Use XLSX instead.'); } // Write cell value $xfIndex = $cell->getXfIndex() + 15; // there are 15 cell style Xfs $cVal = $cell->getValue(); - if ($cVal instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if ($cVal instanceof RichText) { $arrcRun = []; - $str_len = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($cVal->getPlainText(), 'UTF-8'); + $str_len = StringHelper::countCharacters($cVal->getPlainText(), 'UTF-8'); $str_pos = 0; $elements = $cVal->getRichTextElements(); foreach ($elements as $element) { // FONT Index - if ($element instanceof \PhpOffice\PhpSpreadsheet\RichText\Run) { + if ($element instanceof RichText\Run) { $str_fontidx = $this->fontHashIndex[$element->getFont()->getHashCode()]; } else { $str_fontidx = 0; } $arrcRun[] = ['strlen' => $str_pos, 'fontidx' => $str_fontidx]; // Position FROM - $str_pos += \PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($element->getText(), 'UTF-8'); + $str_pos += StringHelper::countCharacters($element->getText(), 'UTF-8'); } $this->writeRichTextString($row, $column, $cVal->getPlainText(), $xfIndex, $arrcRun); } else { switch ($cell->getDatatype()) { - case \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING: - case \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL: + case Cell\DataType::TYPE_STRING: + case Cell\DataType::TYPE_NULL: if ($cVal === '' || $cVal === null) { $this->writeBlank($row, $column, $xfIndex); } else { $this->writeString($row, $column, $cVal, $xfIndex); } break; - case \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC: + case Cell\DataType::TYPE_NUMERIC: $this->writeNumber($row, $column, $cVal, $xfIndex); break; - case \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA: + case Cell\DataType::TYPE_FORMULA: $calculatedValue = $this->preCalculateFormulas ? $cell->getCalculatedValue() : null; $this->writeFormula($row, $column, $cVal, $xfIndex, $calculatedValue); break; - case \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL: + case Cell\DataType::TYPE_BOOL: $this->writeBoolErr($row, $column, $cVal, 0, $xfIndex); break; - case \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR: + case Cell\DataType::TYPE_ERROR: $this->writeBoolErr($row, $column, self::mapErrorCode($cVal), 1, $xfIndex); break; } @@ -480,7 +496,7 @@ class Worksheet extends BIFFwriter // Hyperlinks foreach ($phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) { - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($coordinate); + list($column, $row) = Cell::coordinateFromString($coordinate); $url = $hyperlink->getUrl(); @@ -494,7 +510,7 @@ class Worksheet extends BIFFwriter $url = 'external:' . $url; } - $this->writeUrl($row - 1, \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1, $url); + $this->writeUrl($row - 1, Cell::columnIndexFromString($column) - 1, $url); } $this->writeDataValidity(); @@ -513,8 +529,8 @@ class Worksheet extends BIFFwriter // Write ConditionalFormattingTable records foreach ($arrConditionalStyles as $cellCoordinate => $conditionalStyles) { foreach ($conditionalStyles as $conditional) { - if ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION - || $conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) { + if ($conditional->getConditionType() == Conditional::CONDITION_EXPRESSION + || $conditional->getConditionType() == Conditional::CONDITION_CELLIS) { if (!isset($arrConditional[$conditional->getHashCode()])) { // This hash code has been handled $arrConditional[$conditional->getHashCode()] = true; @@ -553,10 +569,10 @@ class Worksheet extends BIFFwriter $lastCell = $explodes[1]; } - $firstCellCoordinates = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($firstCell); // e.g. array(0, 1) - $lastCellCoordinates = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($lastCell); // e.g. array(1, 6) + $firstCellCoordinates = Cell::coordinateFromString($firstCell); // e.g. array(0, 1) + $lastCellCoordinates = Cell::coordinateFromString($lastCell); // e.g. array(1, 6) - return pack('vvvv', $firstCellCoordinates[1] - 1, $lastCellCoordinates[1] - 1, \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($firstCellCoordinates[0]) - 1, \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($lastCellCoordinates[0]) - 1); + return pack('vvvv', $firstCellCoordinates[1] - 1, $lastCellCoordinates[1] - 1, Cell::columnIndexFromString($firstCellCoordinates[0]) - 1, Cell::columnIndexFromString($lastCellCoordinates[0]) - 1); } /** @@ -671,7 +687,7 @@ class Worksheet extends BIFFwriter { $record = 0x00FD; // Record identifier $length = 0x000A; // Bytes to follow - $str = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort($str, $arrcRun); + $str = StringHelper::UTF8toBIFF8UnicodeShort($str, $arrcRun); /* check if string is already present */ if (!isset($this->stringTable[$str])) { @@ -741,7 +757,7 @@ class Worksheet extends BIFFwriter $record = 0x00FD; // Record identifier $length = 0x000A; // Bytes to follow - $str = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($str); + $str = StringHelper::UTF8toBIFF8UnicodeLong($str); /* check if string is already present */ if (!isset($this->stringTable[$str])) { @@ -869,7 +885,7 @@ class Worksheet extends BIFFwriter // Numeric value $num = pack('d', $calculatedValue); } elseif (is_string($calculatedValue)) { - $errorCodes = \PhpOffice\PhpSpreadsheet\Cell\DataType::getErrorCodes(); + $errorCodes = Cell\DataType::getErrorCodes(); if (isset($errorCodes[$calculatedValue])) { // Error value $num = pack('CCCvCv', 0x02, 0x00, self::mapErrorCode($calculatedValue), 0x00, 0x00, 0xFFFF); @@ -923,7 +939,7 @@ class Worksheet extends BIFFwriter } return 0; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { // do nothing } } @@ -936,7 +952,7 @@ class Worksheet extends BIFFwriter private function writeStringRecord($stringValue) { $record = 0x0207; // Record identifier - $data = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($stringValue); + $data = StringHelper::UTF8toBIFF8UnicodeLong($stringValue); $length = strlen($data); $header = pack('vv', $record, $length); @@ -1078,10 +1094,10 @@ class Worksheet extends BIFFwriter $url .= "\0"; // character count - $url_len = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters($url); + $url_len = StringHelper::countCharacters($url); $url_len = pack('V', $url_len); - $url = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding($url, 'UTF-16LE', 'UTF-8'); + $url = StringHelper::convertEncoding($url, 'UTF-16LE', 'UTF-8'); // Calculate the data length $length = 0x24 + strlen($url); @@ -1174,14 +1190,14 @@ class Worksheet extends BIFFwriter // Pack the main data stream $data = pack('vvvv', $row1, $row2, $col1, $col2) . - $unknown1 . - $link_type . - $unknown2 . - $up_count . - $dir_short_len . - $dir_short . - $unknown3 . - $stream_len; /*. + $unknown1 . + $link_type . + $unknown2 . + $up_count . + $dir_short_len . + $dir_short . + $unknown3 . + $stream_len; /*. $dir_long_len . $unknown4 . $dir_long . @@ -1293,7 +1309,7 @@ class Worksheet extends BIFFwriter // no support in PhpSpreadsheet for selected sheet, therefore sheet is only selected if it is the active sheet $fSelected = ($this->phpSheet === $this->phpSheet->getParent()->getActiveSheet()) ? 1 : 0; $fPaged = 1; // 2 - $fPageBreakPreview = $this->phpSheet->getSheetView()->getView() === \PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW; + $fPageBreakPreview = $this->phpSheet->getSheetView()->getView() === SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW; $grbit = $fDspFmla; $grbit |= $fDspGrid << 1; @@ -1422,8 +1438,7 @@ class Worksheet extends BIFFwriter private function writeSelection() { // look up the selected cell range - $selectedCells = $this->phpSheet->getSelectedCells(); - $selectedCells = \PhpOffice\PhpSpreadsheet\Cell::splitRange($this->phpSheet->getSelectedCells()); + $selectedCells = Cell::splitRange($this->phpSheet->getSelectedCells()); $selectedCells = $selectedCells[0]; if (count($selectedCells) == 2) { list($first, $last) = $selectedCells; @@ -1432,12 +1447,12 @@ class Worksheet extends BIFFwriter $last = $selectedCells[0]; } - list($colFirst, $rwFirst) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($first); - $colFirst = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($colFirst) - 1; // base 0 column index + list($colFirst, $rwFirst) = Cell::coordinateFromString($first); + $colFirst = Cell::columnIndexFromString($colFirst) - 1; // base 0 column index --$rwFirst; // base 0 row index - list($colLast, $rwLast) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($last); - $colLast = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($colLast) - 1; // base 0 column index + list($colLast, $rwLast) = Cell::coordinateFromString($last); + $colLast = Cell::columnIndexFromString($colLast) - 1; // base 0 column index --$rwLast; // base 0 row index // make sure we are not out of bounds @@ -1510,12 +1525,12 @@ class Worksheet extends BIFFwriter ++$j; // extract the row and column indexes - $range = \PhpOffice\PhpSpreadsheet\Cell::splitRange($mergeCell); + $range = Cell::splitRange($mergeCell); list($first, $last) = $range[0]; - list($firstColumn, $firstRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($first); - list($lastColumn, $lastRow) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($last); + list($firstColumn, $firstRow) = Cell::coordinateFromString($first); + list($lastColumn, $lastRow) = Cell::coordinateFromString($last); - $recordData .= pack('vvvv', $firstRow - 1, $lastRow - 1, \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($firstColumn) - 1, \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($lastColumn) - 1); + $recordData .= pack('vvvv', $firstRow - 1, $lastRow - 1, Cell::columnIndexFromString($firstColumn) - 1, Cell::columnIndexFromString($lastColumn) - 1); // flush record if we have reached limit for number of merged cells, or reached final merged cell if ($j == $maxCountMergeCellsPerRecord or $i == $countMergeCells) { @@ -1640,7 +1655,7 @@ class Worksheet extends BIFFwriter hexdec($password) ); - $recordData .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong('p' . md5($recordData)); + $recordData .= StringHelper::UTF8toBIFF8UnicodeLong('p' . md5($recordData)); $length = strlen($recordData); @@ -1713,9 +1728,9 @@ class Worksheet extends BIFFwriter { $panes = []; if ($freezePane = $this->phpSheet->getFreezePane()) { - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($freezePane); + list($column, $row) = Cell::coordinateFromString($freezePane); $panes[0] = $row - 1; - $panes[1] = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column) - 1; + $panes[1] = Cell::columnIndexFromString($column) - 1; } else { // thaw panes return; @@ -1813,7 +1828,7 @@ class Worksheet extends BIFFwriter $fLeftToRight = 0x0; // Print over then down // Page orientation - $fLandscape = ($this->phpSheet->getPageSetup()->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? + $fLandscape = ($this->phpSheet->getPageSetup()->getOrientation() == PageSetup::ORIENTATION_LANDSCAPE) ? 0x0 : 0x1; $fNoPls = 0x0; // Setup not read from printer @@ -1862,7 +1877,7 @@ class Worksheet extends BIFFwriter } */ - $recordData = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($this->phpSheet->getHeaderFooter()->getOddHeader()); + $recordData = StringHelper::UTF8toBIFF8UnicodeLong($this->phpSheet->getHeaderFooter()->getOddHeader()); $length = strlen($recordData); $header = pack('vv', $record, $length); @@ -1886,7 +1901,7 @@ class Worksheet extends BIFFwriter } */ - $recordData = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($this->phpSheet->getHeaderFooter()->getOddFooter()); + $recordData = StringHelper::UTF8toBIFF8UnicodeLong($this->phpSheet->getHeaderFooter()->getOddFooter()); $length = strlen($recordData); $header = pack('vv', $record, $length); @@ -2056,7 +2071,7 @@ class Worksheet extends BIFFwriter $record = 0x009D; // Record identifier $length = 0x0002; // Bytes to follow - $rangeBounds = \PhpOffice\PhpSpreadsheet\Cell::rangeBoundaries($this->phpSheet->getAutoFilter()->getRange()); + $rangeBounds = Cell::rangeBoundaries($this->phpSheet->getAutoFilter()->getRange()); $iNumFilters = 1 + $rangeBounds[1][0] - $rangeBounds[0][0]; $header = pack('vv', $record, $length); @@ -2158,13 +2173,13 @@ class Worksheet extends BIFFwriter foreach ($this->phpSheet->getBreaks() as $cell => $breakType) { // Fetch coordinates - $coordinates = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($cell); + $coordinates = Cell::coordinateFromString($cell); // Decide what to do by the type of break switch ($breakType) { case \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_COLUMN: // Add to list of vertical breaks - $vbreaks[] = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($coordinates[0]) - 1; + $vbreaks[] = Cell::columnIndexFromString($coordinates[0]) - 1; break; case \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_ROW: // Add to list of horizontal breaks @@ -2409,10 +2424,10 @@ class Worksheet extends BIFFwriter $row_end = $row_start; // Row containing bottom right corner of object // Zero the specified offset if greater than the cell dimensions - if ($x1 >= \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start))) { + if ($x1 >= Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_start))) { $x1 = 0; } - if ($y1 >= \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_start + 1)) { + if ($y1 >= Xls::sizeRow($this->phpSheet, $row_start + 1)) { $y1 = 0; } @@ -2420,38 +2435,38 @@ class Worksheet extends BIFFwriter $height = $height + $y1 - 1; // Subtract the underlying cell widths to find the end cell of the image - while ($width >= \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end))) { - $width -= \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end)); + while ($width >= Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end))) { + $width -= Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end)); ++$col_end; } // Subtract the underlying cell heights to find the end cell of the image - while ($height >= \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_end + 1)) { - $height -= \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_end + 1); + while ($height >= Xls::sizeRow($this->phpSheet, $row_end + 1)) { + $height -= Xls::sizeRow($this->phpSheet, $row_end + 1); ++$row_end; } // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell // with zero eight or width. // - if (\PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start)) == 0) { + if (Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_start)) == 0) { return; } - if (\PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end)) == 0) { + if (Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end)) == 0) { return; } - if (\PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_start + 1) == 0) { + if (Xls::sizeRow($this->phpSheet, $row_start + 1) == 0) { return; } - if (\PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_end + 1) == 0) { + if (Xls::sizeRow($this->phpSheet, $row_end + 1) == 0) { return; } // Convert the pixel values to the percentage value expected by Excel - $x1 = $x1 / \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_start)) * 1024; - $y1 = $y1 / \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_start + 1) * 256; - $x2 = $width / \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object - $y2 = $height / \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $row_end + 1) * 256; // Distance to bottom of object + $x1 = $x1 / Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_start)) * 1024; + $y1 = $y1 / Xls::sizeRow($this->phpSheet, $row_start + 1) * 256; + $x2 = $width / Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object + $y2 = $height / Xls::sizeRow($this->phpSheet, $row_end + 1) * 256; // Distance to bottom of object $this->writeObjPicture($col_start, $x1, $row_start, $y1, $col_end, $x2, $row_end, $y2); } @@ -2577,7 +2592,7 @@ class Worksheet extends BIFFwriter // Open file. $bmp_fd = @fopen($bitmap, 'rb'); if (!$bmp_fd) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Couldn't import $bitmap"); + throw new WriterException("Couldn't import $bitmap"); } // Slurp the file into a string. @@ -2585,13 +2600,13 @@ class Worksheet extends BIFFwriter // Check that the file is big enough to be a bitmap. if (strlen($data) <= 0x36) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap doesn't contain enough data.\n"); + throw new WriterException("$bitmap doesn't contain enough data.\n"); } // The first 2 bytes are used to identify the bitmap. $identity = unpack('A2ident', $data); if ($identity['ident'] != 'BM') { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap doesn't appear to be a valid bitmap image.\n"); + throw new WriterException("$bitmap doesn't appear to be a valid bitmap image.\n"); } // Remove bitmap data: ID. @@ -2615,20 +2630,20 @@ class Worksheet extends BIFFwriter $height = $width_and_height[2]; $data = substr($data, 8); if ($width > 0xFFFF) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap: largest image width supported is 65k.\n"); + throw new WriterException("$bitmap: largest image width supported is 65k.\n"); } if ($height > 0xFFFF) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap: largest image height supported is 65k.\n"); + throw new WriterException("$bitmap: largest image height supported is 65k.\n"); } // Read and remove the bitmap planes and bpp data. Verify them. $planes_and_bitcount = unpack('v2', substr($data, 0, 4)); $data = substr($data, 4); if ($planes_and_bitcount[2] != 24) { // Bitcount - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap isn't a 24bit true color bitmap.\n"); + throw new WriterException("$bitmap isn't a 24bit true color bitmap.\n"); } if ($planes_and_bitcount[1] != 1) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap: only 1 plane supported in bitmap image.\n"); + throw new WriterException("$bitmap: only 1 plane supported in bitmap image.\n"); } // Read and remove the bitmap compression. Verify compression. @@ -2636,7 +2651,7 @@ class Worksheet extends BIFFwriter $data = substr($data, 4); if ($compression['comp'] != 0) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("$bitmap: compression not supported in bitmap image.\n"); + throw new WriterException("$bitmap: compression not supported in bitmap image.\n"); } // Remove bitmap data: data size, hres, vres, colours, imp. colours. @@ -2695,7 +2710,7 @@ class Worksheet extends BIFFwriter { // write the Escher stream if necessary if (isset($this->escher)) { - $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls\Escher($this->escher); + $writer = new Escher($this->escher); $data = $writer->close(); $spOffsets = $writer->getSpOffsets(); $spTypes = $writer->getSpTypes(); @@ -2775,6 +2790,8 @@ class Worksheet extends BIFFwriter /** * Store the DATAVALIDATIONS and DATAVALIDATION records. + * + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ private function writeDataValidity() { @@ -2807,30 +2824,30 @@ class Worksheet extends BIFFwriter $options = 0x00000000; // data type - $type = $dataValidation->getType(); - switch ($type) { - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_NONE: + $type = 0x00; + switch ($dataValidation->getType()) { + case DataValidation::TYPE_NONE: $type = 0x00; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE: + case DataValidation::TYPE_WHOLE: $type = 0x01; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_DECIMAL: + case DataValidation::TYPE_DECIMAL: $type = 0x02; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST: + case DataValidation::TYPE_LIST: $type = 0x03; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_DATE: + case DataValidation::TYPE_DATE: $type = 0x04; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_TIME: + case DataValidation::TYPE_TIME: $type = 0x05; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_TEXTLENGTH: + case DataValidation::TYPE_TEXTLENGTH: $type = 0x06; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_CUSTOM: + case DataValidation::TYPE_CUSTOM: $type = 0x07; break; } @@ -2838,15 +2855,15 @@ class Worksheet extends BIFFwriter $options |= $type << 0; // error style - $errorStyle = $dataValidation->getErrorStyle(); - switch ($errorStyle) { - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP: + $errorStyle = 0x00; + switch ($dataValidation->getErrorStyle()) { + case DataValidation::STYLE_STOP: $errorStyle = 0x00; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_WARNING: + case DataValidation::STYLE_WARNING: $errorStyle = 0x01; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION: + case DataValidation::STYLE_INFORMATION: $errorStyle = 0x02; break; } @@ -2871,30 +2888,30 @@ class Worksheet extends BIFFwriter $options |= $dataValidation->getShowErrorMessage() << 19; // condition operator - $operator = $dataValidation->getOperator(); - switch ($operator) { - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_BETWEEN: + $operator = 0x00; + switch ($dataValidation->getOperator()) { + case DataValidation::OPERATOR_BETWEEN: $operator = 0x00; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_NOTBETWEEN: + case DataValidation::OPERATOR_NOTBETWEEN: $operator = 0x01; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_EQUAL: + case DataValidation::OPERATOR_EQUAL: $operator = 0x02; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_NOTEQUAL: + case DataValidation::OPERATOR_NOTEQUAL: $operator = 0x03; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_GREATERTHAN: + case DataValidation::OPERATOR_GREATERTHAN: $operator = 0x04; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_LESSTHAN: + case DataValidation::OPERATOR_LESSTHAN: $operator = 0x05; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_GREATERTHANOREQUAL: + case DataValidation::OPERATOR_GREATERTHANOREQUAL: $operator = 0x06; break; - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_LESSTHANOREQUAL: + case DataValidation::OPERATOR_LESSTHANOREQUAL: $operator = 0x07; break; } @@ -2906,22 +2923,22 @@ class Worksheet extends BIFFwriter // prompt title $promptTitle = $dataValidation->getPromptTitle() !== '' ? $dataValidation->getPromptTitle() : chr(0); - $data .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($promptTitle); + $data .= StringHelper::UTF8toBIFF8UnicodeLong($promptTitle); // error title $errorTitle = $dataValidation->getErrorTitle() !== '' ? $dataValidation->getErrorTitle() : chr(0); - $data .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($errorTitle); + $data .= StringHelper::UTF8toBIFF8UnicodeLong($errorTitle); // prompt text $prompt = $dataValidation->getPrompt() !== '' ? $dataValidation->getPrompt() : chr(0); - $data .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($prompt); + $data .= StringHelper::UTF8toBIFF8UnicodeLong($prompt); // error text $error = $dataValidation->getError() !== '' ? $dataValidation->getError() : chr(0); - $data .= \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($error); + $data .= StringHelper::UTF8toBIFF8UnicodeLong($error); // formula 1 try { @@ -2932,7 +2949,7 @@ class Worksheet extends BIFFwriter $this->parser->parse($formula1); $formula1 = $this->parser->toReversePolish(); $sz1 = strlen($formula1); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { $sz1 = 0; $formula1 = ''; } @@ -2943,12 +2960,12 @@ class Worksheet extends BIFFwriter try { $formula2 = $dataValidation->getFormula2(); if ($formula2 === '') { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('No formula2'); + throw new WriterException('No formula2'); } $this->parser->parse($formula2); $formula2 = $this->parser->toReversePolish(); $sz2 = strlen($formula2); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { $sz2 = 0; $formula2 = ''; } @@ -3010,7 +3027,7 @@ class Worksheet extends BIFFwriter $wScalvePLV = $this->phpSheet->getSheetView()->getZoomScale(); // 2 // The options flags that comprise $grbit - if ($this->phpSheet->getSheetView()->getView() == \PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_PAGE_LAYOUT) { + if ($this->phpSheet->getSheetView()->getView() == SheetView::SHEETVIEW_PAGE_LAYOUT) { $fPageLayoutView = 1; } else { $fPageLayoutView = 0; @@ -3030,43 +3047,43 @@ class Worksheet extends BIFFwriter /** * Write CFRule Record. * - * @param \PhpOffice\PhpSpreadsheet\Style\Conditional $conditional + * @param Conditional $conditional */ - private function writeCFRule(\PhpOffice\PhpSpreadsheet\Style\Conditional $conditional) + private function writeCFRule(Conditional $conditional) { $record = 0x01B1; // Record identifier // $type : Type of the CF // $operatorType : Comparison operator - if ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION) { + if ($conditional->getConditionType() == Conditional::CONDITION_EXPRESSION) { $type = 0x02; $operatorType = 0x00; - } elseif ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) { + } elseif ($conditional->getConditionType() == Conditional::CONDITION_CELLIS) { $type = 0x01; switch ($conditional->getOperatorType()) { - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_NONE: + case Conditional::OPERATOR_NONE: $operatorType = 0x00; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_EQUAL: + case Conditional::OPERATOR_EQUAL: $operatorType = 0x03; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHAN: + case Conditional::OPERATOR_GREATERTHAN: $operatorType = 0x05; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL: + case Conditional::OPERATOR_GREATERTHANOREQUAL: $operatorType = 0x07; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN: + case Conditional::OPERATOR_LESSTHAN: $operatorType = 0x06; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHANOREQUAL: + case Conditional::OPERATOR_LESSTHANOREQUAL: $operatorType = 0x08; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_NOTEQUAL: + case Conditional::OPERATOR_NOTEQUAL: $operatorType = 0x04; break; - case \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BETWEEN: + case Conditional::OPERATOR_BETWEEN: $operatorType = 0x01; break; // not OPERATOR_NOTBETWEEN 0x02 @@ -3082,7 +3099,7 @@ class Worksheet extends BIFFwriter $szValue2 = 0x0000; $operand1 = pack('Cv', 0x1E, $arrConditions[0]); $operand2 = null; - } elseif ($numConditions == 2 && ($conditional->getOperatorType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BETWEEN)) { + } elseif ($numConditions == 2 && ($conditional->getOperatorType() == Conditional::OPERATOR_BETWEEN)) { $szValue1 = ($arrConditions[0] <= 65535 ? 3 : 0x0000); $szValue2 = ($arrConditions[1] <= 65535 ? 3 : 0x0000); $operand1 = pack('Cv', 0x1E, $arrConditions[0]); @@ -3116,14 +3133,14 @@ class Worksheet extends BIFFwriter $bFormatProt = 0; } // Border - $bBorderLeft = ($conditional->getStyle()->getBorders()->getLeft()->getColor()->getARGB() == \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK - && $conditional->getStyle()->getBorders()->getLeft()->getBorderStyle() == \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE ? 1 : 0); - $bBorderRight = ($conditional->getStyle()->getBorders()->getRight()->getColor()->getARGB() == \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK - && $conditional->getStyle()->getBorders()->getRight()->getBorderStyle() == \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE ? 1 : 0); - $bBorderTop = ($conditional->getStyle()->getBorders()->getTop()->getColor()->getARGB() == \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK - && $conditional->getStyle()->getBorders()->getTop()->getBorderStyle() == \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE ? 1 : 0); - $bBorderBottom = ($conditional->getStyle()->getBorders()->getBottom()->getColor()->getARGB() == \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_BLACK - && $conditional->getStyle()->getBorders()->getBottom()->getBorderStyle() == \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE ? 1 : 0); + $bBorderLeft = ($conditional->getStyle()->getBorders()->getLeft()->getColor()->getARGB() == Color::COLOR_BLACK + && $conditional->getStyle()->getBorders()->getLeft()->getBorderStyle() == Border::BORDER_NONE ? 1 : 0); + $bBorderRight = ($conditional->getStyle()->getBorders()->getRight()->getColor()->getARGB() == Color::COLOR_BLACK + && $conditional->getStyle()->getBorders()->getRight()->getBorderStyle() == Border::BORDER_NONE ? 1 : 0); + $bBorderTop = ($conditional->getStyle()->getBorders()->getTop()->getColor()->getARGB() == Color::COLOR_BLACK + && $conditional->getStyle()->getBorders()->getTop()->getBorderStyle() == Border::BORDER_NONE ? 1 : 0); + $bBorderBottom = ($conditional->getStyle()->getBorders()->getBottom()->getColor()->getARGB() == Color::COLOR_BLACK + && $conditional->getStyle()->getBorders()->getBottom()->getBorderStyle() == Border::BORDER_NONE ? 1 : 0); if ($bBorderLeft == 0 || $bBorderRight == 0 || $bBorderTop == 0 || $bBorderBottom == 0) { $bFormatBorder = 1; } else { @@ -3143,8 +3160,8 @@ class Worksheet extends BIFFwriter || $conditional->getStyle()->getFont()->getSize() != null || $conditional->getStyle()->getFont()->getBold() != null || $conditional->getStyle()->getFont()->getItalic() != null - || $conditional->getStyle()->getFont()->getSuperScript() != null - || $conditional->getStyle()->getFont()->getSubScript() != null + || $conditional->getStyle()->getFont()->getSuperscript() != null + || $conditional->getStyle()->getFont()->getSubscript() != null || $conditional->getStyle()->getFont()->getUnderline() != null || $conditional->getStyle()->getFont()->getStrikethrough() != null || $conditional->getStyle()->getFont()->getColor()->getARGB() != null) { @@ -3199,7 +3216,7 @@ class Worksheet extends BIFFwriter $dataBlockFont = pack('VVVVVVVV', 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000); $dataBlockFont .= pack('VVVVVVVV', 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000); } else { - $dataBlockFont = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong($conditional->getStyle()->getFont()->getName()); + $dataBlockFont = StringHelper::UTF8toBIFF8UnicodeLong($conditional->getStyle()->getFont()->getName()); } // Font Size if ($conditional->getStyle()->getFont()->getSize() == null) { @@ -3216,10 +3233,10 @@ class Worksheet extends BIFFwriter $dataBlockFont .= pack('v', 0x0190); } // Escapement type - if ($conditional->getStyle()->getFont()->getSubScript() == true) { + if ($conditional->getStyle()->getFont()->getSubscript() == true) { $dataBlockFont .= pack('v', 0x02); $fontEscapement = 0; - } elseif ($conditional->getStyle()->getFont()->getSuperScript() == true) { + } elseif ($conditional->getStyle()->getFont()->getSuperscript() == true) { $dataBlockFont .= pack('v', 0x01); $fontEscapement = 0; } else { @@ -3458,22 +3475,22 @@ class Worksheet extends BIFFwriter $blockAlign = 0; // Alignment and text break switch ($conditional->getStyle()->getAlignment()->getHorizontal()) { - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL: + case Alignment::HORIZONTAL_GENERAL: $blockAlign = 0; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT: + case Alignment::HORIZONTAL_LEFT: $blockAlign = 1; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT: + case Alignment::HORIZONTAL_RIGHT: $blockAlign = 3; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER: + case Alignment::HORIZONTAL_CENTER: $blockAlign = 2; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS: + case Alignment::HORIZONTAL_CENTER_CONTINUOUS: $blockAlign = 6; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY: + case Alignment::HORIZONTAL_JUSTIFY: $blockAlign = 5; break; } @@ -3483,16 +3500,16 @@ class Worksheet extends BIFFwriter $blockAlign |= 0 << 3; } switch ($conditional->getStyle()->getAlignment()->getVertical()) { - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM: + case Alignment::VERTICAL_BOTTOM: $blockAlign = 2 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP: + case Alignment::VERTICAL_TOP: $blockAlign = 0 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER: + case Alignment::VERTICAL_CENTER: $blockAlign = 1 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY: + case Alignment::VERTICAL_JUSTIFY: $blockAlign = 3 << 4; break; } @@ -3518,178 +3535,178 @@ class Worksheet extends BIFFwriter if ($bFormatBorder == 1) { $blockLineStyle = 0; switch ($conditional->getStyle()->getBorders()->getLeft()->getBorderStyle()) { - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE: + case Border::BORDER_NONE: $blockLineStyle |= 0x00; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN: + case Border::BORDER_THIN: $blockLineStyle |= 0x01; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM: + case Border::BORDER_MEDIUM: $blockLineStyle |= 0x02; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED: + case Border::BORDER_DASHED: $blockLineStyle |= 0x03; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED: + case Border::BORDER_DOTTED: $blockLineStyle |= 0x04; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK: + case Border::BORDER_THICK: $blockLineStyle |= 0x05; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE: + case Border::BORDER_DOUBLE: $blockLineStyle |= 0x06; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR: + case Border::BORDER_HAIR: $blockLineStyle |= 0x07; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED: + case Border::BORDER_MEDIUMDASHED: $blockLineStyle |= 0x08; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT: + case Border::BORDER_DASHDOT: $blockLineStyle |= 0x09; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT: + case Border::BORDER_MEDIUMDASHDOT: $blockLineStyle |= 0x0A; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT: + case Border::BORDER_DASHDOTDOT: $blockLineStyle |= 0x0B; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT: + case Border::BORDER_MEDIUMDASHDOTDOT: $blockLineStyle |= 0x0C; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT: + case Border::BORDER_SLANTDASHDOT: $blockLineStyle |= 0x0D; break; } switch ($conditional->getStyle()->getBorders()->getRight()->getBorderStyle()) { - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE: + case Border::BORDER_NONE: $blockLineStyle |= 0x00 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN: + case Border::BORDER_THIN: $blockLineStyle |= 0x01 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM: + case Border::BORDER_MEDIUM: $blockLineStyle |= 0x02 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED: + case Border::BORDER_DASHED: $blockLineStyle |= 0x03 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED: + case Border::BORDER_DOTTED: $blockLineStyle |= 0x04 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK: + case Border::BORDER_THICK: $blockLineStyle |= 0x05 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE: + case Border::BORDER_DOUBLE: $blockLineStyle |= 0x06 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR: + case Border::BORDER_HAIR: $blockLineStyle |= 0x07 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED: + case Border::BORDER_MEDIUMDASHED: $blockLineStyle |= 0x08 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT: + case Border::BORDER_DASHDOT: $blockLineStyle |= 0x09 << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT: + case Border::BORDER_MEDIUMDASHDOT: $blockLineStyle |= 0x0A << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT: + case Border::BORDER_DASHDOTDOT: $blockLineStyle |= 0x0B << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT: + case Border::BORDER_MEDIUMDASHDOTDOT: $blockLineStyle |= 0x0C << 4; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT: + case Border::BORDER_SLANTDASHDOT: $blockLineStyle |= 0x0D << 4; break; } switch ($conditional->getStyle()->getBorders()->getTop()->getBorderStyle()) { - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE: + case Border::BORDER_NONE: $blockLineStyle |= 0x00 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN: + case Border::BORDER_THIN: $blockLineStyle |= 0x01 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM: + case Border::BORDER_MEDIUM: $blockLineStyle |= 0x02 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED: + case Border::BORDER_DASHED: $blockLineStyle |= 0x03 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED: + case Border::BORDER_DOTTED: $blockLineStyle |= 0x04 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK: + case Border::BORDER_THICK: $blockLineStyle |= 0x05 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE: + case Border::BORDER_DOUBLE: $blockLineStyle |= 0x06 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR: + case Border::BORDER_HAIR: $blockLineStyle |= 0x07 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED: + case Border::BORDER_MEDIUMDASHED: $blockLineStyle |= 0x08 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT: + case Border::BORDER_DASHDOT: $blockLineStyle |= 0x09 << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT: + case Border::BORDER_MEDIUMDASHDOT: $blockLineStyle |= 0x0A << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT: + case Border::BORDER_DASHDOTDOT: $blockLineStyle |= 0x0B << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT: + case Border::BORDER_MEDIUMDASHDOTDOT: $blockLineStyle |= 0x0C << 8; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT: + case Border::BORDER_SLANTDASHDOT: $blockLineStyle |= 0x0D << 8; break; } switch ($conditional->getStyle()->getBorders()->getBottom()->getBorderStyle()) { - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE: + case Border::BORDER_NONE: $blockLineStyle |= 0x00 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN: + case Border::BORDER_THIN: $blockLineStyle |= 0x01 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM: + case Border::BORDER_MEDIUM: $blockLineStyle |= 0x02 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED: + case Border::BORDER_DASHED: $blockLineStyle |= 0x03 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED: + case Border::BORDER_DOTTED: $blockLineStyle |= 0x04 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK: + case Border::BORDER_THICK: $blockLineStyle |= 0x05 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE: + case Border::BORDER_DOUBLE: $blockLineStyle |= 0x06 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR: + case Border::BORDER_HAIR: $blockLineStyle |= 0x07 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED: + case Border::BORDER_MEDIUMDASHED: $blockLineStyle |= 0x08 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT: + case Border::BORDER_DASHDOT: $blockLineStyle |= 0x09 << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT: + case Border::BORDER_MEDIUMDASHDOT: $blockLineStyle |= 0x0A << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT: + case Border::BORDER_DASHDOTDOT: $blockLineStyle |= 0x0B << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT: + case Border::BORDER_MEDIUMDASHDOTDOT: $blockLineStyle |= 0x0C << 12; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT: + case Border::BORDER_SLANTDASHDOT: $blockLineStyle |= 0x0D << 12; break; } @@ -3702,46 +3719,46 @@ class Worksheet extends BIFFwriter //@todo writeCFRule() => $blockColor => Index Color for bottom line //@todo writeCFRule() => $blockColor => Index Color for diagonal line switch ($conditional->getStyle()->getBorders()->getDiagonal()->getBorderStyle()) { - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE: + case Border::BORDER_NONE: $blockColor |= 0x00 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN: + case Border::BORDER_THIN: $blockColor |= 0x01 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM: + case Border::BORDER_MEDIUM: $blockColor |= 0x02 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED: + case Border::BORDER_DASHED: $blockColor |= 0x03 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED: + case Border::BORDER_DOTTED: $blockColor |= 0x04 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK: + case Border::BORDER_THICK: $blockColor |= 0x05 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE: + case Border::BORDER_DOUBLE: $blockColor |= 0x06 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR: + case Border::BORDER_HAIR: $blockColor |= 0x07 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED: + case Border::BORDER_MEDIUMDASHED: $blockColor |= 0x08 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT: + case Border::BORDER_DASHDOT: $blockColor |= 0x09 << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT: + case Border::BORDER_MEDIUMDASHDOT: $blockColor |= 0x0A << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT: + case Border::BORDER_DASHDOTDOT: $blockColor |= 0x0B << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT: + case Border::BORDER_MEDIUMDASHDOTDOT: $blockColor |= 0x0C << 21; break; - case \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT: + case Border::BORDER_SLANTDASHDOT: $blockColor |= 0x0D << 21; break; } @@ -3751,67 +3768,67 @@ class Worksheet extends BIFFwriter // Fill Patern Style $blockFillPatternStyle = 0; switch ($conditional->getStyle()->getFill()->getFillType()) { - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE: + case Fill::FILL_NONE: $blockFillPatternStyle = 0x00; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID: + case Fill::FILL_SOLID: $blockFillPatternStyle = 0x01; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_MEDIUMGRAY: + case Fill::FILL_PATTERN_MEDIUMGRAY: $blockFillPatternStyle = 0x02; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRAY: + case Fill::FILL_PATTERN_DARKGRAY: $blockFillPatternStyle = 0x03; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRAY: + case Fill::FILL_PATTERN_LIGHTGRAY: $blockFillPatternStyle = 0x04; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKHORIZONTAL: + case Fill::FILL_PATTERN_DARKHORIZONTAL: $blockFillPatternStyle = 0x05; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKVERTICAL: + case Fill::FILL_PATTERN_DARKVERTICAL: $blockFillPatternStyle = 0x06; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKDOWN: + case Fill::FILL_PATTERN_DARKDOWN: $blockFillPatternStyle = 0x07; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKUP: + case Fill::FILL_PATTERN_DARKUP: $blockFillPatternStyle = 0x08; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRID: + case Fill::FILL_PATTERN_DARKGRID: $blockFillPatternStyle = 0x09; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKTRELLIS: + case Fill::FILL_PATTERN_DARKTRELLIS: $blockFillPatternStyle = 0x0A; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTHORIZONTAL: + case Fill::FILL_PATTERN_LIGHTHORIZONTAL: $blockFillPatternStyle = 0x0B; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTVERTICAL: + case Fill::FILL_PATTERN_LIGHTVERTICAL: $blockFillPatternStyle = 0x0C; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTDOWN: + case Fill::FILL_PATTERN_LIGHTDOWN: $blockFillPatternStyle = 0x0D; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTUP: + case Fill::FILL_PATTERN_LIGHTUP: $blockFillPatternStyle = 0x0E; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRID: + case Fill::FILL_PATTERN_LIGHTGRID: $blockFillPatternStyle = 0x0F; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTTRELLIS: + case Fill::FILL_PATTERN_LIGHTTRELLIS: $blockFillPatternStyle = 0x10; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125: + case Fill::FILL_PATTERN_GRAY125: $blockFillPatternStyle = 0x11; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY0625: + case Fill::FILL_PATTERN_GRAY0625: $blockFillPatternStyle = 0x12; break; - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR: + case Fill::FILL_GRADIENT_LINEAR: $blockFillPatternStyle = 0x00; break; // does not exist in BIFF8 - case \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH: + case Fill::FILL_GRADIENT_PATH: $blockFillPatternStyle = 0x00; break; // does not exist in BIFF8 default: @@ -4171,10 +4188,10 @@ class Worksheet extends BIFFwriter } if ($bFormatProt == 1) { $dataBlockProtection = 0; - if ($conditional->getStyle()->getProtection()->getLocked() == \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED) { + if ($conditional->getStyle()->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED) { $dataBlockProtection = 1; } - if ($conditional->getStyle()->getProtection()->getHidden() == \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED) { + if ($conditional->getStyle()->getProtection()->getHidden() == Protection::PROTECTION_PROTECTED) { $dataBlockProtection = 1 << 1; } } @@ -4220,15 +4237,15 @@ class Worksheet extends BIFFwriter $arrConditional = []; foreach ($this->phpSheet->getConditionalStylesCollection() as $cellCoordinate => $conditionalStyles) { foreach ($conditionalStyles as $conditional) { - if ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION - || $conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) { + if ($conditional->getConditionType() == Conditional::CONDITION_EXPRESSION + || $conditional->getConditionType() == Conditional::CONDITION_CELLIS) { if (!in_array($conditional->getHashCode(), $arrConditional)) { $arrConditional[] = $conditional->getHashCode(); } // Cells - $arrCoord = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($cellCoordinate); + $arrCoord = Cell::coordinateFromString($cellCoordinate); if (!is_numeric($arrCoord[0])) { - $arrCoord[0] = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($arrCoord[0]); + $arrCoord[0] = Cell::columnIndexFromString($arrCoord[0]); } if (is_null($numColumnMin) || ($numColumnMin > $arrCoord[0])) { $numColumnMin = $arrCoord[0]; diff --git a/src/PhpSpreadsheet/Writer/Xls/Xf.php b/src/PhpSpreadsheet/Writer/Xls/Xf.php index 23f76f6a..8b911cb7 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Xf.php +++ b/src/PhpSpreadsheet/Writer/Xls/Xf.php @@ -2,6 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls; +use PhpOffice\PhpSpreadsheet\Style; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Borders; +use PhpOffice\PhpSpreadsheet\Style\Fill; +use PhpOffice\PhpSpreadsheet\Style\Protection; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -134,9 +141,9 @@ class Xf /** * Constructor. * - * @param \PhpOffice\PhpSpreadsheet\Style The XF format + * @param Style The XF format */ - public function __construct(\PhpOffice\PhpSpreadsheet\Style $style) + public function __construct(Style $style) { $this->isStyleXf = false; $this->fontIndex = 0; @@ -233,10 +240,10 @@ class Xf $border1 |= $this->rightBorderColor << 23; $diagonalDirection = $this->_style->getBorders()->getDiagonalDirection(); - $diag_tl_to_rb = $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH - || $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_DOWN; - $diag_tr_to_lb = $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH - || $diagonalDirection == \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_UP; + $diag_tl_to_rb = $diagonalDirection == Borders::DIAGONAL_BOTH + || $diagonalDirection == Borders::DIAGONAL_DOWN; + $diag_tr_to_lb = $diagonalDirection == Borders::DIAGONAL_BOTH + || $diagonalDirection == Borders::DIAGONAL_UP; $border1 |= $diag_tl_to_rb << 30; $border1 |= $diag_tr_to_lb << 31; @@ -366,20 +373,20 @@ class Xf * @static array of int */ private static $mapBorderStyles = [ - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE => 0x00, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN => 0x01, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM => 0x02, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED => 0x03, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED => 0x04, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK => 0x05, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE => 0x06, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_HAIR => 0x07, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED => 0x08, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT => 0x09, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT => 0x0A, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT => 0x0B, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT => 0x0C, - \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT => 0x0D, + Border::BORDER_NONE => 0x00, + Border::BORDER_THIN => 0x01, + Border::BORDER_MEDIUM => 0x02, + Border::BORDER_DASHED => 0x03, + Border::BORDER_DOTTED => 0x04, + Border::BORDER_THICK => 0x05, + Border::BORDER_DOUBLE => 0x06, + Border::BORDER_HAIR => 0x07, + Border::BORDER_MEDIUMDASHED => 0x08, + Border::BORDER_DASHDOT => 0x09, + Border::BORDER_MEDIUMDASHDOT => 0x0A, + Border::BORDER_DASHDOTDOT => 0x0B, + Border::BORDER_MEDIUMDASHDOTDOT => 0x0C, + Border::BORDER_SLANTDASHDOT => 0x0D, ]; /** @@ -404,27 +411,27 @@ class Xf * @static array of int */ private static $mapFillTypes = [ - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE => 0x00, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID => 0x01, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_MEDIUMGRAY => 0x02, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRAY => 0x03, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRAY => 0x04, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKVERTICAL => 0x06, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKDOWN => 0x07, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKUP => 0x08, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRID => 0x09, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKTRELLIS => 0x0A, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTDOWN => 0x0D, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTUP => 0x0E, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRID => 0x0F, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125 => 0x11, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY0625 => 0x12, - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8 - \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8 + Fill::FILL_NONE => 0x00, + Fill::FILL_SOLID => 0x01, + Fill::FILL_PATTERN_MEDIUMGRAY => 0x02, + Fill::FILL_PATTERN_DARKGRAY => 0x03, + Fill::FILL_PATTERN_LIGHTGRAY => 0x04, + Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05, + Fill::FILL_PATTERN_DARKVERTICAL => 0x06, + Fill::FILL_PATTERN_DARKDOWN => 0x07, + Fill::FILL_PATTERN_DARKUP => 0x08, + Fill::FILL_PATTERN_DARKGRID => 0x09, + Fill::FILL_PATTERN_DARKTRELLIS => 0x0A, + Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B, + Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C, + Fill::FILL_PATTERN_LIGHTDOWN => 0x0D, + Fill::FILL_PATTERN_LIGHTUP => 0x0E, + Fill::FILL_PATTERN_LIGHTGRID => 0x0F, + Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10, + Fill::FILL_PATTERN_GRAY125 => 0x11, + Fill::FILL_PATTERN_GRAY0625 => 0x12, + Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8 + Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8 ]; /** @@ -449,13 +456,13 @@ class Xf * @static array of int */ private static $mapHAlignments = [ - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_GENERAL => 0, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT => 1, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER => 2, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT => 3, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_FILL => 4, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY => 5, - \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6, + Alignment::HORIZONTAL_GENERAL => 0, + Alignment::HORIZONTAL_LEFT => 1, + Alignment::HORIZONTAL_CENTER => 2, + Alignment::HORIZONTAL_RIGHT => 3, + Alignment::HORIZONTAL_FILL => 4, + Alignment::HORIZONTAL_JUSTIFY => 5, + Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6, ]; /** @@ -480,10 +487,10 @@ class Xf * @static array of int */ private static $mapVAlignments = [ - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP => 0, - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER => 1, - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM => 2, - \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY => 3, + Alignment::VERTICAL_TOP => 0, + Alignment::VERTICAL_CENTER => 1, + Alignment::VERTICAL_BOTTOM => 2, + Alignment::VERTICAL_JUSTIFY => 3, ]; /** @@ -531,11 +538,11 @@ class Xf private static function mapLocked($locked) { switch ($locked) { - case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT: + case Protection::PROTECTION_INHERIT: return 1; - case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED: + case Protection::PROTECTION_PROTECTED: return 1; - case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED: + case Protection::PROTECTION_UNPROTECTED: return 0; default: return 1; @@ -553,11 +560,11 @@ class Xf private static function mapHidden($hidden) { switch ($hidden) { - case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT: + case Protection::PROTECTION_INHERIT: return 0; - case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED: + case Protection::PROTECTION_PROTECTED: return 1; - case \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED: + case Protection::PROTECTION_UNPROTECTED: return 0; default: return 0; diff --git a/src/PhpSpreadsheet/Writer/Xlsx.php b/src/PhpSpreadsheet/Writer/Xlsx.php index 56f1c508..7bcb0b33 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx.php +++ b/src/PhpSpreadsheet/Writer/Xlsx.php @@ -2,7 +2,27 @@ namespace PhpOffice\PhpSpreadsheet\Writer; +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\HashTable; +use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet\Drawing as WorksheetDrawing; +use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\ContentTypes; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsRibbon; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsVBA; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Theme; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet; use ZipArchive; /** @@ -46,7 +66,7 @@ class Xlsx extends BaseWriter implements IWriter /** * Private Spreadsheet. * - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $spreadSheet; @@ -58,78 +78,78 @@ class Xlsx extends BaseWriter implements IWriter private $stringTable = []; /** - * Private unique \PhpOffice\PhpSpreadsheet\Style\Conditional HashTable. + * Private unique Conditional HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $stylesConditionalHashTable; /** - * Private unique \PhpOffice\PhpSpreadsheet\Style HashTable. + * Private unique Style HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $styleHashTable; /** - * Private unique \PhpOffice\PhpSpreadsheet\Style\Fill HashTable. + * Private unique Fill HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $fillHashTable; /** * Private unique \PhpOffice\PhpSpreadsheet\Style\Font HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $fontHashTable; /** - * Private unique \PhpOffice\PhpSpreadsheet\Style\Borders HashTable. + * Private unique Borders HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $bordersHashTable; /** - * Private unique \PhpOffice\PhpSpreadsheet\Style\NumberFormat HashTable. + * Private unique NumberFormat HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $numFmtHashTable; /** * Private unique \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing HashTable. * - * @var \PhpOffice\PhpSpreadsheet\HashTable + * @var HashTable */ private $drawingHashTable; /** * Create a new Xlsx Writer. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet */ - public function __construct(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet) + public function __construct(Spreadsheet $spreadsheet) { // Assign PhpSpreadsheet $this->setSpreadsheet($spreadsheet); $writerPartsArray = [ - 'stringtable' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable::class, - 'contenttypes' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\ContentTypes::class, - 'docprops' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps::class, - 'rels' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels::class, - 'theme' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Theme::class, - 'style' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style::class, - 'workbook' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook::class, - 'worksheet' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet::class, - 'drawing' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing::class, - 'comments' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments::class, - 'chart' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart::class, - 'relsvba' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsVBA::class, - 'relsribbonobjects' => \PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsRibbon::class, + 'stringtable' => StringTable::class, + 'contenttypes' => ContentTypes::class, + 'docprops' => DocProps::class, + 'rels' => Rels::class, + 'theme' => Theme::class, + 'style' => Style::class, + 'workbook' => Workbook::class, + 'worksheet' => Worksheet::class, + 'drawing' => Drawing::class, + 'comments' => Comments::class, + 'chart' => Chart::class, + 'relsvba' => RelsVBA::class, + 'relsribbonobjects' => RelsRibbon::class, ]; // Initialise writer parts @@ -139,13 +159,13 @@ class Xlsx extends BaseWriter implements IWriter } $hashTablesArray = ['stylesConditionalHashTable', 'fillHashTable', 'fontHashTable', - 'bordersHashTable', 'numFmtHashTable', 'drawingHashTable', - 'styleHashTable', + 'bordersHashTable', 'numFmtHashTable', 'drawingHashTable', + 'styleHashTable', ]; // Set HashTable variables foreach ($hashTablesArray as $tableName) { - $this->$tableName = new \PhpOffice\PhpSpreadsheet\HashTable(); + $this->$tableName = new HashTable(); } } @@ -170,7 +190,7 @@ class Xlsx extends BaseWriter implements IWriter * * @param string $pFilename * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ public function save($pFilename) { @@ -181,16 +201,16 @@ class Xlsx extends BaseWriter implements IWriter // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { - $pFilename = @tempnam(\PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir(), 'phpxltmp'); + $pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp'); if ($pFilename == '') { $pFilename = $originalFilename; } } - $saveDebugLog = \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog(); - \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog(false); - $saveDateReturnType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType(); - \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType(\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL); + $saveDebugLog = Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog(); + Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog(false); + $saveDateReturnType = Functions::getReturnDateType(); + Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); // Create string lookup table $this->stringTable = []; @@ -217,7 +237,7 @@ class Xlsx extends BaseWriter implements IWriter // Try opening the ZIP file if ($zip->open($pFilename, ZipArchive::OVERWRITE) !== true) { if ($zip->open($pFilename, ZipArchive::CREATE) !== true) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Could not open ' . $pFilename . ' for writing.'); + throw new WriterException('Could not open ' . $pFilename . ' for writing.'); } } @@ -339,7 +359,7 @@ class Xlsx extends BaseWriter implements IWriter // Add media for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { - if ($this->getDrawingHashTable()->getByIndex($i) instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing) { + if ($this->getDrawingHashTable()->getByIndex($i) instanceof WorksheetDrawing) { $imageContents = null; $imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath(); if (strpos($imagePath, 'zip://') !== false) { @@ -356,7 +376,7 @@ class Xlsx extends BaseWriter implements IWriter } $zip->addFromString('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); - } elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing) { + } elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof MemoryDrawing) { ob_start(); call_user_func( $this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), @@ -369,30 +389,30 @@ class Xlsx extends BaseWriter implements IWriter } } - \PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($saveDateReturnType); - \PhpOffice\PhpSpreadsheet\Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); + Functions::setReturnDateType($saveDateReturnType); + Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); // Close file if ($zip->close() === false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not close zip file $pFilename."); + throw new WriterException("Could not close zip file $pFilename."); } // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { if (copy($pFilename, $originalFilename) === false) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Could not copy temporary zip file $pFilename to $originalFilename."); + throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename."); } @unlink($pFilename); } } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('PhpSpreadsheet object unassigned.'); + throw new WriterException('PhpSpreadsheet object unassigned.'); } } /** * Get Spreadsheet object. * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return Spreadsheet */ @@ -401,13 +421,13 @@ class Xlsx extends BaseWriter implements IWriter if ($this->spreadSheet !== null) { return $this->spreadSheet; } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('No Spreadsheet object assigned.'); + throw new WriterException('No Spreadsheet object assigned.'); } /** * Set Spreadsheet object. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet PhpSpreadsheet object + * @param Spreadsheet $spreadsheet PhpSpreadsheet object * * @return Xlsx */ @@ -429,9 +449,9 @@ class Xlsx extends BaseWriter implements IWriter } /** - * Get \PhpOffice\PhpSpreadsheet\Style HashTable. + * Get Style HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getStyleHashTable() { @@ -439,9 +459,9 @@ class Xlsx extends BaseWriter implements IWriter } /** - * Get \PhpOffice\PhpSpreadsheet\Style\Conditional HashTable. + * Get Conditional HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getStylesConditionalHashTable() { @@ -449,9 +469,9 @@ class Xlsx extends BaseWriter implements IWriter } /** - * Get \PhpOffice\PhpSpreadsheet\Style\Fill HashTable. + * Get Fill HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getFillHashTable() { @@ -461,7 +481,7 @@ class Xlsx extends BaseWriter implements IWriter /** * Get \PhpOffice\PhpSpreadsheet\Style\Font HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getFontHashTable() { @@ -469,9 +489,9 @@ class Xlsx extends BaseWriter implements IWriter } /** - * Get \PhpOffice\PhpSpreadsheet\Style\Borders HashTable. + * Get Borders HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getBordersHashTable() { @@ -479,9 +499,9 @@ class Xlsx extends BaseWriter implements IWriter } /** - * Get \PhpOffice\PhpSpreadsheet\Style\NumberFormat HashTable. + * Get NumberFormat HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getNumFmtHashTable() { @@ -491,7 +511,7 @@ class Xlsx extends BaseWriter implements IWriter /** * Get \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing HashTable. * - * @return \PhpOffice\PhpSpreadsheet\HashTable + * @return HashTable */ public function getDrawingHashTable() { diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index 418688f7..6f7f58d5 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -10,6 +10,9 @@ use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\Legend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. @@ -43,7 +46,7 @@ class Chart extends WriterPart * @param \PhpOffice\PhpSpreadsheet\Chart $pChart * @param mixed $calculateCellValues * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -54,9 +57,9 @@ class Chart extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // Ensure that data series values are up-to-date before we save if ($this->calculateCellValues) { @@ -121,12 +124,12 @@ class Chart extends WriterPart /** * Write Chart Title. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param Title $title * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeTitle(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Title $title = null) + private function writeTitle(XMLWriter $objWriter, Title $title = null) { if (is_null($title)) { return; @@ -166,12 +169,12 @@ class Chart extends WriterPart /** * Write Chart Legend. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param Legend $legend * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeLegend(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Legend $legend = null) + private function writeLegend(XMLWriter $objWriter, Legend $legend = null) { if (is_null($legend)) { return; @@ -217,7 +220,7 @@ class Chart extends WriterPart /** * Write Chart Plot Area. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet * @param PlotArea $plotArea * @param Title $xAxisLabel @@ -225,9 +228,9 @@ class Chart extends WriterPart * @param Axis $xAxis * @param Axis $yAxis * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writePlotArea(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, PlotArea $plotArea, Title $xAxisLabel = null, Title $yAxisLabel = null, Axis $xAxis = null, Axis $yAxis = null, GridLines $majorGridlines = null, GridLines $minorGridlines = null) + private function writePlotArea(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, PlotArea $plotArea, Title $xAxisLabel = null, Title $yAxisLabel = null, Axis $xAxis = null, Axis $yAxis = null, GridLines $majorGridlines = null, GridLines $minorGridlines = null) { if (is_null($plotArea)) { return; @@ -353,12 +356,12 @@ class Chart extends WriterPart /** * Write Data Labels. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpSpreadsheet\Chart\Layout $chartLayout Chart layout * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDataLabels(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Layout $chartLayout = null) + private function writeDataLabels(XMLWriter $objWriter, Layout $chartLayout = null) { $objWriter->startElement('c:dLbls'); @@ -403,7 +406,7 @@ class Chart extends WriterPart /** * Write Category Axis. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param PlotArea $plotArea * @param Title $xAxisLabel * @param string $groupType Chart type @@ -413,7 +416,7 @@ class Chart extends WriterPart * @param mixed $xAxis * @param mixed $yAxis * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writeCategoryAxis($objWriter, PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis) { @@ -458,7 +461,7 @@ class Chart extends WriterPart $caption = $caption[0]; } $objWriter->startElement('a:t'); - $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($caption)); + $objWriter->writeRawData(StringHelper::controlCharacterPHP2OOXML($caption)); $objWriter->endElement(); $objWriter->endElement(); @@ -526,7 +529,7 @@ class Chart extends WriterPart /** * Write Value Axis. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param PlotArea $plotArea * @param Title $yAxisLabel * @param string $groupType Chart type @@ -538,7 +541,7 @@ class Chart extends WriterPart * @param mixed $majorGridlines * @param mixed $minorGridlines * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writeValueAxis($objWriter, PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines) { @@ -811,7 +814,7 @@ class Chart extends WriterPart } $objWriter->startElement('a:t'); - $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($caption)); + $objWriter->writeRawData(StringHelper::controlCharacterPHP2OOXML($caption)); $objWriter->endElement(); $objWriter->endElement(); @@ -1018,7 +1021,7 @@ class Chart extends WriterPart * * @param PlotArea $plotArea * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string|array */ @@ -1035,7 +1038,7 @@ class Chart extends WriterPart } $chartType = array_unique($chartTypes); if (count($chartTypes) == 0) { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Chart is not yet implemented'); + throw new WriterException('Chart is not yet implemented'); } } @@ -1047,13 +1050,13 @@ class Chart extends WriterPart * * @param DataSeries $plotGroup * @param string $groupType Type of plot for dataseries - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param bool &$catIsMultiLevelSeries Is category a multi-series category * @param bool &$valIsMultiLevelSeries Is value set a multi-series set * @param string &$plotGroupingType Type of grouping for multi-series values * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMultiLevelSeries, &$valIsMultiLevelSeries, &$plotGroupingType, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) { @@ -1095,6 +1098,20 @@ class Chart extends WriterPart foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) { $objWriter->startElement('c:ser'); + $plotLabel = $plotGroup->getPlotLabelByIndex($plotSeriesIdx); + if ($plotLabel) { + $fillColor = $plotLabel->getFillColor(); + if ($fillColor !== null) { + $objWriter->startElement('c:spPr'); + $objWriter->startElement('a:solidFill'); + $objWriter->startElement('a:srgbClr'); + $objWriter->writeAttribute('val', $fillColor); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + } + } + $objWriter->startElement('c:idx'); $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx); $objWriter->endElement(); @@ -1225,9 +1242,9 @@ class Chart extends WriterPart * Write Plot Series Label. * * @param DataSeriesValues $plotSeriesLabel - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writePlotSeriesLabel($plotSeriesLabel, $objWriter) { @@ -1260,13 +1277,13 @@ class Chart extends WriterPart * Write Plot Series Values. * * @param DataSeriesValues $plotSeriesValues - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $groupType Type of plot for dataseries * @param string $dataType Datatype of series values * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writePlotSeriesValues($plotSeriesValues, \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $groupType, $dataType = 'str') + private function writePlotSeriesValues($plotSeriesValues, XMLWriter $objWriter, $groupType, $dataType = 'str') { if (is_null($plotSeriesValues)) { return; @@ -1354,9 +1371,9 @@ class Chart extends WriterPart * Write Bubble Chart Details. * * @param DataSeriesValues $plotSeriesValues - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writeBubbles($plotSeriesValues, $objWriter) { @@ -1400,12 +1417,12 @@ class Chart extends WriterPart /** * Write Layout. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param Layout $layout * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeLayout(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Layout $layout = null) + private function writeLayout(XMLWriter $objWriter, Layout $layout = null) { $objWriter->startElement('c:layout'); @@ -1470,9 +1487,9 @@ class Chart extends WriterPart /** * Write Alternate Content block. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writeAlternateContent($objWriter) { @@ -1500,9 +1517,9 @@ class Chart extends WriterPart /** * Write Printer Settings. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function writePrintSettings($objWriter) { diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Comments.php b/src/PhpSpreadsheet/Writer/Xlsx/Comments.php index e630b797..d08f3aec 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Comments.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Comments.php @@ -2,6 +2,10 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Comment; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -40,9 +44,9 @@ class Comments extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -87,14 +91,14 @@ class Comments extends WriterPart /** * Write comment to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pCellReference Cell reference - * @param \PhpOffice\PhpSpreadsheet\Comment $pComment Comment + * @param Comment $pComment Comment * @param array $pAuthors Array of authors * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeComment(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pCellReference, \PhpOffice\PhpSpreadsheet\Comment $pComment, array $pAuthors) + private function writeComment(XMLWriter $objWriter, $pCellReference, Comment $pComment, array $pAuthors) { // comment $objWriter->startElement('comment'); @@ -123,9 +127,9 @@ class Comments extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -186,17 +190,17 @@ class Comments extends WriterPart /** * Write VML comment to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pCellReference Cell reference, eg: 'A1' - * @param \PhpOffice\PhpSpreadsheet\Comment $pComment Comment + * @param Comment $pComment Comment * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeVMLComment(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pCellReference, \PhpOffice\PhpSpreadsheet\Comment $pComment) + private function writeVMLComment(XMLWriter $objWriter, $pCellReference, Comment $pComment) { // Metadata - list($column, $row) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($pCellReference); - $column = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($column); + list($column, $row) = Cell::coordinateFromString($pCellReference); + $column = Cell::columnIndexFromString($column); $id = 1024 + $column + $row; $id = substr($id, 0, 4); diff --git a/src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php b/src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php index bf01e978..64a14602 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/ContentTypes.php @@ -2,6 +2,12 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Shared\File; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,21 +35,21 @@ class ContentTypes extends WriterPart /** * Write content types to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * @param bool $includeCharts Flag indicating if we should include drawing details for charts * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ - public function writeContentTypes(\PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet, $includeCharts = false) + public function writeContentTypes(Spreadsheet $spreadsheet, $includeCharts = false) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -140,7 +146,7 @@ class ContentTypes extends WriterPart if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing) { $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension()); $mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath()); - } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing) { + } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof MemoryDrawing) { $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType()); $extension = explode('/', $extension); $extension = $extension[1]; @@ -187,30 +193,30 @@ class ContentTypes extends WriterPart * * @param string $pFile Filename * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string Mime Type */ private function getImageMimeType($pFile) { - if (\PhpOffice\PhpSpreadsheet\Shared\File::fileExists($pFile)) { + if (File::fileExists($pFile)) { $image = getimagesize($pFile); return image_type_to_mime_type($image[2]); } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("File $pFile does not exist"); + throw new WriterException("File $pFile does not exist"); } /** * Write Default content type. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pPartname Part name * @param string $pContentType Content type * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDefaultContentType(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pPartname, $pContentType) + private function writeDefaultContentType(XMLWriter $objWriter, $pPartname, $pContentType) { if ($pPartname != '' && $pContentType != '') { // Write content type @@ -219,20 +225,20 @@ class ContentTypes extends WriterPart $objWriter->writeAttribute('ContentType', $pContentType); $objWriter->endElement(); } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.'); + throw new WriterException('Invalid parameters passed.'); } } /** * Write Override content type. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pPartname Part name * @param string $pContentType Content type * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeOverrideContentType(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pPartname, $pContentType) + private function writeOverrideContentType(XMLWriter $objWriter, $pPartname, $pContentType) { if ($pPartname != '' && $pContentType != '') { // Write content type @@ -241,7 +247,7 @@ class ContentTypes extends WriterPart $objWriter->writeAttribute('ContentType', $pContentType); $objWriter->endElement(); } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.'); + throw new WriterException('Invalid parameters passed.'); } } } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/DocProps.php b/src/PhpSpreadsheet/Writer/Xlsx/DocProps.php index 7eb9a06e..3de9b5a8 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/DocProps.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/DocProps.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,20 +32,20 @@ class DocProps extends WriterPart /** * Write docProps/app.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeDocPropsApp(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeDocPropsApp(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -128,20 +131,20 @@ class DocProps extends WriterPart /** * Write docProps/core.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeDocPropsCore(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeDocPropsCore(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -197,13 +200,13 @@ class DocProps extends WriterPart /** * Write docProps/custom.xml to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeDocPropsCustom(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeDocPropsCustom(Spreadsheet $spreadsheet) { $customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); if (empty($customPropertyList)) { @@ -213,9 +216,9 @@ class DocProps extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php b/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php index afd27f30..ca1272ae 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Drawing.php @@ -2,6 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing; +use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -33,7 +40,7 @@ class Drawing extends WriterPart * @param int &$chartRef Chart ID * @param bool $includeCharts Flag indicating if we should include drawing details for charts * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -42,9 +49,9 @@ class Drawing extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -84,29 +91,29 @@ class Drawing extends WriterPart /** * Write drawings to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpSpreadsheet\Chart $pChart * @param int $pRelationId * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - public function writeChart(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart $pChart, $pRelationId = -1) + public function writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart $pChart, $pRelationId = -1) { $tl = $pChart->getTopLeftPosition(); - $tl['colRow'] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($tl['cell']); + $tl['colRow'] = Cell::coordinateFromString($tl['cell']); $br = $pChart->getBottomRightPosition(); - $br['colRow'] = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($br['cell']); + $br['colRow'] = Cell::coordinateFromString($br['cell']); $objWriter->startElement('xdr:twoCellAnchor'); $objWriter->startElement('xdr:from'); - $objWriter->writeElement('xdr:col', \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($tl['colRow'][0]) - 1); + $objWriter->writeElement('xdr:col', Cell::columnIndexFromString($tl['colRow'][0]) - 1); $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['xOffset'])); $objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1); $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['yOffset'])); $objWriter->endElement(); $objWriter->startElement('xdr:to'); - $objWriter->writeElement('xdr:col', \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($br['colRow'][0]) - 1); + $objWriter->writeElement('xdr:col', Cell::columnIndexFromString($br['colRow'][0]) - 1); $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['xOffset'])); $objWriter->writeElement('xdr:row', $br['colRow'][1] - 1); $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['yOffset'])); @@ -157,20 +164,20 @@ class Drawing extends WriterPart /** * Write drawings to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing $pDrawing + * @param XMLWriter $objWriter XML Writer + * @param BaseDrawing $pDrawing * @param int $pRelationId * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - public function writeDrawing(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing $pDrawing, $pRelationId = -1) + public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId = -1) { if ($pRelationId >= 0) { // xdr:oneCellAnchor $objWriter->startElement('xdr:oneCellAnchor'); // Image location - $aCoordinates = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($pDrawing->getCoordinates()); - $aCoordinates[0] = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($aCoordinates[0]); + $aCoordinates = Cell::coordinateFromString($pDrawing->getCoordinates()); + $aCoordinates[0] = Cell::columnIndexFromString($aCoordinates[0]); // xdr:from $objWriter->startElement('xdr:from'); @@ -280,7 +287,7 @@ class Drawing extends WriterPart $objWriter->endElement(); } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.'); + throw new WriterException('Invalid parameters passed.'); } } @@ -289,7 +296,7 @@ class Drawing extends WriterPart * * @param \PhpOffice\PhpSpreadsheet\Worksheet $pWorksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -298,9 +305,9 @@ class Drawing extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -436,13 +443,13 @@ class Drawing extends WriterPart /** * Write VML comment to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pReference Reference - * @param \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing $pImage Image + * @param HeaderFooterDrawing $pImage Image * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeVMLHeaderFooterImage(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pReference, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing $pImage) + private function writeVMLHeaderFooterImage(XMLWriter $objWriter, $pReference, HeaderFooterDrawing $pImage) { // Calculate object id preg_match('{(\d+)}', md5($pReference), $m); @@ -470,7 +477,7 @@ class Drawing extends WriterPart // o:lock $objWriter->startElement('o:lock'); $objWriter->writeAttribute('v:ext', 'edit'); - $objWriter->writeAttribute('rotation', 't'); + $objWriter->writeAttribute('textRotation', 't'); $objWriter->endElement(); $objWriter->endElement(); @@ -479,13 +486,13 @@ class Drawing extends WriterPart /** * Get an array of all drawings. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return \PhpOffice\PhpSpreadsheet\Worksheet\Drawing[] All drawings in PhpSpreadsheet */ - public function allDrawings(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allDrawings(Spreadsheet $spreadsheet) { // Get an array of all drawings $aDrawings = []; diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Rels.php b/src/PhpSpreadsheet/Writer/Xlsx/Rels.php index 2d4ceef5..eec3cefa 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Rels.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Rels.php @@ -2,6 +2,11 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,20 +34,20 @@ class Rels extends WriterPart /** * Write relationships to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ - public function writeRelationships(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeRelationships(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -104,20 +109,20 @@ class Rels extends WriterPart /** * Write workbook relationships to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ - public function writeWorkbookRelationships(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeWorkbookRelationships(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -189,7 +194,7 @@ class Rels extends WriterPart * @param int $pWorksheetId * @param bool $includeCharts Flag indicating if we should write charts * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -198,9 +203,9 @@ class Rels extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -284,7 +289,7 @@ class Rels extends WriterPart * @param int &$chartRef Chart ID * @param bool $includeCharts Flag indicating if we should write charts * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -293,9 +298,9 @@ class Rels extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -310,7 +315,7 @@ class Rels extends WriterPart $iterator = $pWorksheet->getDrawingCollection()->getIterator(); while ($iterator->valid()) { if ($iterator->current() instanceof \PhpOffice\PhpSpreadsheet\Worksheet\Drawing - || $iterator->current() instanceof \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing) { + || $iterator->current() instanceof MemoryDrawing) { // Write relationship for image drawing $this->writeRelationship( $objWriter, @@ -349,7 +354,7 @@ class Rels extends WriterPart * * @param \PhpOffice\PhpSpreadsheet\Worksheet $pWorksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -358,9 +363,9 @@ class Rels extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -389,15 +394,15 @@ class Rels extends WriterPart /** * Write Override content type. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param int $pId Relationship ID. rId will be prepended! * @param string $pType Relationship type * @param string $pTarget Relationship target * @param string $pTargetMode Relationship target mode * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeRelationship(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pId, $pType, $pTarget, $pTargetMode = '') + private function writeRelationship(XMLWriter $objWriter, $pId, $pType, $pTarget, $pTargetMode = '') { if ($pType != '' && $pTarget != '') { // Write relationship @@ -412,7 +417,7 @@ class Rels extends WriterPart $objWriter->endElement(); } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.'); + throw new WriterException('Invalid parameters passed.'); } } } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/RelsRibbon.php b/src/PhpSpreadsheet/Writer/Xlsx/RelsRibbon.php index da414a2f..e827d182 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/RelsRibbon.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/RelsRibbon.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,20 +32,20 @@ class RelsRibbon extends WriterPart /** * Write relationships for additional objects of custom UI (ribbon). * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeRibbonRelationships(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeRibbonRelationships(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Xlsx/RelsVBA.php b/src/PhpSpreadsheet/Writer/Xlsx/RelsVBA.php index dbf4dfed..8bd7de13 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/RelsVBA.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/RelsVBA.php @@ -2,6 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,20 +32,20 @@ class RelsVBA extends WriterPart /** * Write relationships for a signed VBA Project. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeVBARelationships(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeVBARelationships(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header diff --git a/src/PhpSpreadsheet/Writer/Xlsx/StringTable.php b/src/PhpSpreadsheet/Writer/Xlsx/StringTable.php index 4232445a..aaa07e82 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/StringTable.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/StringTable.php @@ -2,6 +2,12 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,10 +35,10 @@ class StringTable extends WriterPart /** * Create worksheet stringtable. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param Worksheet $pSheet Worksheet * @param string[] $pExistingTable Existing table to eventually merge with * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string[] String table for worksheet */ @@ -60,10 +66,10 @@ class StringTable extends WriterPart ($cellValue !== null) && $cellValue !== '' && !isset($aFlippedStringTable[$cellValue]) && - ($cell->getDataType() == \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING || $cell->getDataType() == \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING2 || $cell->getDataType() == \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL)) { + ($cell->getDataType() == Cell\DataType::TYPE_STRING || $cell->getDataType() == Cell\DataType::TYPE_STRING2 || $cell->getDataType() == Cell\DataType::TYPE_NULL)) { $aStringTable[] = $cellValue; $aFlippedStringTable[$cellValue] = true; - } elseif ($cellValue instanceof \PhpOffice\PhpSpreadsheet\RichText && + } elseif ($cellValue instanceof RichText && ($cellValue !== null) && !isset($aFlippedStringTable[$cellValue->getHashCode()])) { $aStringTable[] = $cellValue; @@ -73,7 +79,7 @@ class StringTable extends WriterPart return $aStringTable; } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception("Invalid \PhpOffice\PhpSpreadsheet\Worksheet object passed."); + throw new WriterException('Invalid Worksheet object passed.'); } /** @@ -81,7 +87,7 @@ class StringTable extends WriterPart * * @param string[] $pStringTable * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -90,9 +96,9 @@ class StringTable extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -107,15 +113,15 @@ class StringTable extends WriterPart foreach ($pStringTable as $textElement) { $objWriter->startElement('si'); - if (!$textElement instanceof \PhpOffice\PhpSpreadsheet\RichText) { - $textToWrite = \PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($textElement); + if (!$textElement instanceof RichText) { + $textToWrite = StringHelper::controlCharacterPHP2OOXML($textElement); $objWriter->startElement('t'); if ($textToWrite !== trim($textToWrite)) { $objWriter->writeAttribute('xml:space', 'preserve'); } $objWriter->writeRawData($textToWrite); $objWriter->endElement(); - } elseif ($textElement instanceof \PhpOffice\PhpSpreadsheet\RichText) { + } elseif ($textElement instanceof RichText) { $this->writeRichText($objWriter, $textElement); } @@ -130,13 +136,13 @@ class StringTable extends WriterPart /** * Write Rich Text. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\RichText $pRichText Rich text + * @param XMLWriter $objWriter XML Writer + * @param RichText $pRichText Rich text * @param string $prefix Optional Namespace prefix * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - public function writeRichText(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\RichText $pRichText, $prefix = null) + public function writeRichText(XMLWriter $objWriter, RichText $pRichText, $prefix = null) { if ($prefix !== null) { $prefix .= ':'; @@ -149,7 +155,7 @@ class StringTable extends WriterPart $objWriter->startElement($prefix . 'r'); // rPr - if ($element instanceof \PhpOffice\PhpSpreadsheet\RichText\Run) { + if ($element instanceof RichText\Run) { // rPr $objWriter->startElement($prefix . 'rPr'); @@ -169,11 +175,11 @@ class StringTable extends WriterPart $objWriter->endElement(); // Superscript / subscript - if ($element->getFont()->getSuperScript() || $element->getFont()->getSubScript()) { + if ($element->getFont()->getSuperscript() || $element->getFont()->getSubscript()) { $objWriter->startElement($prefix . 'vertAlign'); - if ($element->getFont()->getSuperScript()) { + if ($element->getFont()->getSuperscript()) { $objWriter->writeAttribute('val', 'superscript'); - } elseif ($element->getFont()->getSubScript()) { + } elseif ($element->getFont()->getSubscript()) { $objWriter->writeAttribute('val', 'subscript'); } $objWriter->endElement(); @@ -205,7 +211,7 @@ class StringTable extends WriterPart // t $objWriter->startElement($prefix . 't'); $objWriter->writeAttribute('xml:space', 'preserve'); - $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($element->getText())); + $objWriter->writeRawData(StringHelper::controlCharacterPHP2OOXML($element->getText())); $objWriter->endElement(); $objWriter->endElement(); @@ -215,17 +221,17 @@ class StringTable extends WriterPart /** * Write Rich Text. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param string|\PhpOffice\PhpSpreadsheet\RichText $pRichText text string or Rich text + * @param XMLWriter $objWriter XML Writer + * @param string|RichText $pRichText text string or Rich text * @param string $prefix Optional Namespace prefix * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - public function writeRichTextForCharts(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pRichText = null, $prefix = null) + public function writeRichTextForCharts(XMLWriter $objWriter, $pRichText = null, $prefix = null) { - if (!$pRichText instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if (!$pRichText instanceof RichText) { $textRun = $pRichText; - $pRichText = new \PhpOffice\PhpSpreadsheet\RichText(); + $pRichText = new RichText(); $pRichText->createTextRun($textRun); } @@ -269,7 +275,7 @@ class StringTable extends WriterPart // t $objWriter->startElement($prefix . 't'); - $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($element->getText())); + $objWriter->writeRawData(StringHelper::controlCharacterPHP2OOXML($element->getText())); $objWriter->endElement(); $objWriter->endElement(); @@ -290,9 +296,9 @@ class StringTable extends WriterPart // Loop through stringtable and add flipped items to $returnValue foreach ($stringTable as $key => $value) { - if (!$value instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if (!$value instanceof RichText) { $returnValue[$value] = $key; - } elseif ($value instanceof \PhpOffice\PhpSpreadsheet\RichText) { + } elseif ($value instanceof RichText) { $returnValue[$value->getHashCode()] = $key; } } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Style.php b/src/PhpSpreadsheet/Writer/Xlsx/Style.php index 96457aa1..96779f3b 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Style.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Style.php @@ -2,6 +2,16 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Borders; +use PhpOffice\PhpSpreadsheet\Style\Fill; +use PhpOffice\PhpSpreadsheet\Style\Font; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; +use PhpOffice\PhpSpreadsheet\Style\Protection; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,20 +39,20 @@ class Style extends WriterPart /** * Write styles to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeStyles(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeStyles(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -161,16 +171,16 @@ class Style extends WriterPart /** * Write Fill. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Style\Fill $pFill Fill style + * @param XMLWriter $objWriter XML Writer + * @param Fill $pFill Fill style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeFill(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Fill $pFill) + private function writeFill(XMLWriter $objWriter, Fill $pFill) { // Check if this is a pattern type or gradient type - if ($pFill->getFillType() === \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR || - $pFill->getFillType() === \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH) { + if ($pFill->getFillType() === Fill::FILL_GRADIENT_LINEAR || + $pFill->getFillType() === Fill::FILL_GRADIENT_PATH) { // Gradient fill $this->writeGradientFill($objWriter, $pFill); } elseif ($pFill->getFillType() !== null) { @@ -182,12 +192,12 @@ class Style extends WriterPart /** * Write Gradient Fill. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Style\Fill $pFill Fill style + * @param XMLWriter $objWriter XML Writer + * @param Fill $pFill Fill style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeGradientFill(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Fill $pFill) + private function writeGradientFill(XMLWriter $objWriter, Fill $pFill) { // fill $objWriter->startElement('fill'); @@ -227,12 +237,12 @@ class Style extends WriterPart /** * Write Pattern Fill. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Style\Fill $pFill Fill style + * @param XMLWriter $objWriter XML Writer + * @param Fill $pFill Fill style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writePatternFill(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Fill $pFill) + private function writePatternFill(XMLWriter $objWriter, Fill $pFill) { // fill $objWriter->startElement('fill'); @@ -241,7 +251,7 @@ class Style extends WriterPart $objWriter->startElement('patternFill'); $objWriter->writeAttribute('patternType', $pFill->getFillType()); - if ($pFill->getFillType() !== \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE) { + if ($pFill->getFillType() !== Fill::FILL_NONE) { // fgColor if ($pFill->getStartColor()->getARGB()) { $objWriter->startElement('fgColor'); @@ -249,7 +259,7 @@ class Style extends WriterPart $objWriter->endElement(); } } - if ($pFill->getFillType() !== \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE) { + if ($pFill->getFillType() !== Fill::FILL_NONE) { // bgColor if ($pFill->getEndColor()->getARGB()) { $objWriter->startElement('bgColor'); @@ -266,12 +276,12 @@ class Style extends WriterPart /** * Write Font. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Style\Font $pFont Font style + * @param XMLWriter $objWriter XML Writer + * @param Font $pFont Font style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeFont(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Font $pFont) + private function writeFont(XMLWriter $objWriter, Font $pFont) { // font $objWriter->startElement('font'); @@ -310,11 +320,11 @@ class Style extends WriterPart } // Superscript / subscript - if ($pFont->getSuperScript() === true || $pFont->getSubScript() === true) { + if ($pFont->getSuperscript() === true || $pFont->getSubscript() === true) { $objWriter->startElement('vertAlign'); - if ($pFont->getSuperScript() === true) { + if ($pFont->getSuperscript() === true) { $objWriter->writeAttribute('val', 'superscript'); - } elseif ($pFont->getSubScript() === true) { + } elseif ($pFont->getSubscript() === true) { $objWriter->writeAttribute('val', 'subscript'); } $objWriter->endElement(); @@ -323,7 +333,7 @@ class Style extends WriterPart // Size if ($pFont->getSize() !== null) { $objWriter->startElement('sz'); - $objWriter->writeAttribute('val', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pFont->getSize())); + $objWriter->writeAttribute('val', StringHelper::formatNumber($pFont->getSize())); $objWriter->endElement(); } @@ -347,26 +357,26 @@ class Style extends WriterPart /** * Write Border. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Style\Borders $pBorders Borders style + * @param XMLWriter $objWriter XML Writer + * @param Borders $pBorders Borders style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeBorder(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\Borders $pBorders) + private function writeBorder(XMLWriter $objWriter, Borders $pBorders) { // Write border $objWriter->startElement('border'); // Diagonal? switch ($pBorders->getDiagonalDirection()) { - case \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_UP: + case Borders::DIAGONAL_UP: $objWriter->writeAttribute('diagonalUp', 'true'); $objWriter->writeAttribute('diagonalDown', 'false'); break; - case \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_DOWN: + case Borders::DIAGONAL_DOWN: $objWriter->writeAttribute('diagonalUp', 'false'); $objWriter->writeAttribute('diagonalDown', 'true'); break; - case \PhpOffice\PhpSpreadsheet\Style\Borders::DIAGONAL_BOTH: + case Borders::DIAGONAL_BOTH: $objWriter->writeAttribute('diagonalUp', 'true'); $objWriter->writeAttribute('diagonalDown', 'true'); break; @@ -384,13 +394,13 @@ class Style extends WriterPart /** * Write Cell Style Xf. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpSpreadsheet\Style $pStyle Style - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet Workbook + * @param Spreadsheet $spreadsheet Workbook * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeCellStyleXf(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style $pStyle, \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + private function writeCellStyleXf(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style $pStyle, Spreadsheet $spreadsheet) { // xf $objWriter->startElement('xf'); @@ -415,7 +425,7 @@ class Style extends WriterPart $objWriter->writeAttribute('applyFill', ($spreadsheet->getDefaultStyle()->getFill()->getHashCode() != $pStyle->getFill()->getHashCode()) ? '1' : '0'); $objWriter->writeAttribute('applyBorder', ($spreadsheet->getDefaultStyle()->getBorders()->getHashCode() != $pStyle->getBorders()->getHashCode()) ? '1' : '0'); $objWriter->writeAttribute('applyAlignment', ($spreadsheet->getDefaultStyle()->getAlignment()->getHashCode() != $pStyle->getAlignment()->getHashCode()) ? '1' : '0'); - if ($pStyle->getProtection()->getLocked() != \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT) { + if ($pStyle->getProtection()->getLocked() != Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != Protection::PROTECTION_INHERIT) { $objWriter->writeAttribute('applyProtection', 'true'); } @@ -438,19 +448,19 @@ class Style extends WriterPart if ($pStyle->getAlignment()->getIndent() > 0) { $objWriter->writeAttribute('indent', $pStyle->getAlignment()->getIndent()); } - if ($pStyle->getAlignment()->getReadorder() > 0) { - $objWriter->writeAttribute('readingOrder', $pStyle->getAlignment()->getReadorder()); + if ($pStyle->getAlignment()->getReadOrder() > 0) { + $objWriter->writeAttribute('readingOrder', $pStyle->getAlignment()->getReadOrder()); } $objWriter->endElement(); // protection - if ($pStyle->getProtection()->getLocked() != \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT) { + if ($pStyle->getProtection()->getLocked() != Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != Protection::PROTECTION_INHERIT) { $objWriter->startElement('protection'); - if ($pStyle->getProtection()->getLocked() != \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT) { - $objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED ? 'true' : 'false')); + if ($pStyle->getProtection()->getLocked() != Protection::PROTECTION_INHERIT) { + $objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED ? 'true' : 'false')); } - if ($pStyle->getProtection()->getHidden() != \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT) { - $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED ? 'true' : 'false')); + if ($pStyle->getProtection()->getHidden() != Protection::PROTECTION_INHERIT) { + $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == Protection::PROTECTION_PROTECTED ? 'true' : 'false')); } $objWriter->endElement(); } @@ -461,12 +471,12 @@ class Style extends WriterPart /** * Write Cell Style Dxf. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param \PhpOffice\PhpSpreadsheet\Style $pStyle Style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeCellStyleDxf(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style $pStyle) + private function writeCellStyleDxf(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style $pStyle) { // dxf $objWriter->startElement('dxf'); @@ -505,16 +515,16 @@ class Style extends WriterPart // protection if (($pStyle->getProtection()->getLocked() !== null) || ($pStyle->getProtection()->getHidden() !== null)) { - if ($pStyle->getProtection()->getLocked() !== \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT || - $pStyle->getProtection()->getHidden() !== \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT) { + if ($pStyle->getProtection()->getLocked() !== Protection::PROTECTION_INHERIT || + $pStyle->getProtection()->getHidden() !== Protection::PROTECTION_INHERIT) { $objWriter->startElement('protection'); if (($pStyle->getProtection()->getLocked() !== null) && - ($pStyle->getProtection()->getLocked() !== \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT)) { - $objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED ? 'true' : 'false')); + ($pStyle->getProtection()->getLocked() !== Protection::PROTECTION_INHERIT)) { + $objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == Protection::PROTECTION_PROTECTED ? 'true' : 'false')); } if (($pStyle->getProtection()->getHidden() !== null) && - ($pStyle->getProtection()->getHidden() !== \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_INHERIT)) { - $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == \PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED ? 'true' : 'false')); + ($pStyle->getProtection()->getHidden() !== Protection::PROTECTION_INHERIT)) { + $objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == Protection::PROTECTION_PROTECTED ? 'true' : 'false')); } $objWriter->endElement(); } @@ -526,16 +536,16 @@ class Style extends WriterPart /** * Write BorderPr. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pName Element name - * @param \PhpOffice\PhpSpreadsheet\Style\Border $pBorder Border style + * @param Border $pBorder Border style * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeBorderPr(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pName, \PhpOffice\PhpSpreadsheet\Style\Border $pBorder) + private function writeBorderPr(XMLWriter $objWriter, $pName, Border $pBorder) { // Write BorderPr - if ($pBorder->getBorderStyle() != \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_NONE) { + if ($pBorder->getBorderStyle() != Border::BORDER_NONE) { $objWriter->startElement($pName); $objWriter->writeAttribute('style', $pBorder->getBorderStyle()); @@ -551,13 +561,13 @@ class Style extends WriterPart /** * Write NumberFormat. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Style\NumberFormat $pNumberFormat Number Format + * @param XMLWriter $objWriter XML Writer + * @param NumberFormat $pNumberFormat Number Format * @param int $pId Number Format identifier * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - private function writeNumFmt(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Style\NumberFormat $pNumberFormat, $pId = 0) + private function writeNumFmt(XMLWriter $objWriter, NumberFormat $pNumberFormat, $pId = 0) { // Translate formatcode $formatCode = $pNumberFormat->getFormatCode(); @@ -574,13 +584,13 @@ class Style extends WriterPart /** * Get an array of all styles. * - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return \PhpOffice\PhpSpreadsheet\Style[] All styles in PhpSpreadsheet */ - public function allStyles(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allStyles(Spreadsheet $spreadsheet) { return $spreadsheet->getCellXfCollection(); } @@ -588,13 +598,13 @@ class Style extends WriterPart /** * Get an array of all conditional styles. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Style\Conditional[] All conditional styles in PhpSpreadsheet + * @return Conditional[] All conditional styles in PhpSpreadsheet */ - public function allConditionalStyles(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allConditionalStyles(Spreadsheet $spreadsheet) { // Get an array of all styles $aStyles = []; @@ -614,24 +624,24 @@ class Style extends WriterPart /** * Get an array of all fills. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Style\Fill[] All fills in PhpSpreadsheet + * @return Fill[] All fills in PhpSpreadsheet */ - public function allFills(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allFills(Spreadsheet $spreadsheet) { // Get an array of unique fills $aFills = []; // Two first fills are predefined - $fill0 = new \PhpOffice\PhpSpreadsheet\Style\Fill(); - $fill0->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_NONE); + $fill0 = new Fill(); + $fill0->setFillType(Fill::FILL_NONE); $aFills[] = $fill0; - $fill1 = new \PhpOffice\PhpSpreadsheet\Style\Fill(); - $fill1->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125); + $fill1 = new Fill(); + $fill1->setFillType(Fill::FILL_PATTERN_GRAY125); $aFills[] = $fill1; // The remaining fills $aStyles = $this->allStyles($spreadsheet); @@ -648,13 +658,13 @@ class Style extends WriterPart /** * Get an array of all fonts. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Style\Font[] All fonts in PhpSpreadsheet + * @return Font[] All fonts in PhpSpreadsheet */ - public function allFonts(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allFonts(Spreadsheet $spreadsheet) { // Get an array of unique fonts $aFonts = []; @@ -673,13 +683,13 @@ class Style extends WriterPart /** * Get an array of all borders. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Style\Borders[] All borders in PhpSpreadsheet + * @return Borders[] All borders in PhpSpreadsheet */ - public function allBorders(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allBorders(Spreadsheet $spreadsheet) { // Get an array of unique borders $aBorders = []; @@ -698,13 +708,13 @@ class Style extends WriterPart /** * Get an array of all number formats. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Style\NumberFormat[] All number formats in PhpSpreadsheet + * @return NumberFormat[] All number formats in PhpSpreadsheet */ - public function allNumberFormats(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function allNumberFormats(Spreadsheet $spreadsheet) { // Get an array of unique number formats $aNumFmts = []; diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Theme.php b/src/PhpSpreadsheet/Writer/Xlsx/Theme.php index 4dde8153..da3f206f 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Theme.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Theme.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; -/** +/* * PhpSpreadsheet. * * Copyright (c) 2006 - 2016 PhpSpreadsheet @@ -26,6 +26,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; /** * @category PhpSpreadsheet @@ -131,20 +133,20 @@ class Theme extends WriterPart /** * Write theme to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * * @return string XML Output */ - public function writeTheme(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + public function writeTheme(Spreadsheet $spreadsheet) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -815,7 +817,7 @@ class Theme extends WriterPart /** * Write fonts to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter + * @param XMLWriter $objWriter * @param string $latinFont * @param array of string $fontSet * @@ -851,7 +853,7 @@ class Theme extends WriterPart /** * Write colour scheme to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter + * @param XMLWriter $objWriter * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php b/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php index 16f9f73b..d21db57d 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php @@ -2,6 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\NamedRange; +use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; + /** * Copyright (c) 2006 - 2016 PhpSpreadsheet. * @@ -29,20 +37,20 @@ class Workbook extends WriterPart /** * Write workbook to XML format. * - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param Spreadsheet $spreadsheet * @param bool $recalcRequired Indicate whether formulas should be recalculated before writing * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ - public function writeWorkbook(\PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet, $recalcRequired = false) + public function writeWorkbook(Spreadsheet $spreadsheet, $recalcRequired = false) { // Create XML writer if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -86,11 +94,11 @@ class Workbook extends WriterPart /** * Write file version. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeFileVersion(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter) + private function writeFileVersion(XMLWriter $objWriter) { $objWriter->startElement('fileVersion'); $objWriter->writeAttribute('appName', 'xl'); @@ -103,15 +111,15 @@ class Workbook extends WriterPart /** * Write WorkbookPr. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeWorkbookPr(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter) + private function writeWorkbookPr(XMLWriter $objWriter) { $objWriter->startElement('workbookPr'); - if (\PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar() == \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904) { + if (Date::getExcelCalendar() == Date::CALENDAR_MAC_1904) { $objWriter->writeAttribute('date1904', '1'); } @@ -123,12 +131,12 @@ class Workbook extends WriterPart /** * Write BookViews. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param XMLWriter $objWriter XML Writer + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeBookViews(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + private function writeBookViews(XMLWriter $objWriter, Spreadsheet $spreadsheet) { // bookViews $objWriter->startElement('bookViews'); @@ -154,12 +162,12 @@ class Workbook extends WriterPart /** * Write WorkbookProtection. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param XMLWriter $objWriter XML Writer + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeWorkbookProtection(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + private function writeWorkbookProtection(XMLWriter $objWriter, Spreadsheet $spreadsheet) { if ($spreadsheet->getSecurity()->isSecurityEnabled()) { $objWriter->startElement('workbookProtection'); @@ -182,12 +190,12 @@ class Workbook extends WriterPart /** * Write calcPr. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param bool $recalcRequired Indicate whether formulas should be recalculated before writing * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeCalcPr(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $recalcRequired = true) + private function writeCalcPr(XMLWriter $objWriter, $recalcRequired = true) { $objWriter->startElement('calcPr'); @@ -206,12 +214,12 @@ class Workbook extends WriterPart /** * Write sheets. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param XMLWriter $objWriter XML Writer + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheets(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + private function writeSheets(XMLWriter $objWriter, Spreadsheet $spreadsheet) { // Write sheets $objWriter->startElement('sheets'); @@ -233,15 +241,15 @@ class Workbook extends WriterPart /** * Write sheet. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer + * @param XMLWriter $objWriter XML Writer * @param string $pSheetname Sheet name * @param int $pSheetId Sheet id * @param int $pRelId Relationship ID * @param string $sheetState Sheet state (visible, hidden, veryHidden) * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheet(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pSheetname, $pSheetId = 1, $pRelId = 1, $sheetState = 'visible') + private function writeSheet(XMLWriter $objWriter, $pSheetname, $pSheetId = 1, $pRelId = 1, $sheetState = 'visible') { if ($pSheetname != '') { // Write sheet @@ -254,19 +262,19 @@ class Workbook extends WriterPart $objWriter->writeAttribute('r:id', 'rId' . $pRelId); $objWriter->endElement(); } else { - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.'); + throw new WriterException('Invalid parameters passed.'); } } /** * Write Defined Names. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet + * @param XMLWriter $objWriter XML Writer + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDefinedNames(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + private function writeDefinedNames(XMLWriter $objWriter, Spreadsheet $spreadsheet) { // Write defined names $objWriter->startElement('definedNames'); @@ -296,12 +304,12 @@ class Workbook extends WriterPart /** * Write named ranges. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet + * @param XMLWriter $objWriter XML Writer + * @param Spreadsheet $spreadsheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeNamedRanges(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\SpreadSheet $spreadsheet) + private function writeNamedRanges(XMLWriter $objWriter, Spreadsheet $spreadsheet) { // Loop named ranges $namedRanges = $spreadsheet->getNamedRanges(); @@ -313,12 +321,12 @@ class Workbook extends WriterPart /** * Write Defined Name for named range. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\NamedRange $pNamedRange + * @param XMLWriter $objWriter XML Writer + * @param NamedRange $pNamedRange * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDefinedNameForNamedRange(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\NamedRange $pNamedRange) + private function writeDefinedNameForNamedRange(XMLWriter $objWriter, NamedRange $pNamedRange) { // definedName for named range $objWriter->startElement('definedName'); @@ -328,14 +336,14 @@ class Workbook extends WriterPart } // Create absolute coordinate and write as raw text - $range = \PhpOffice\PhpSpreadsheet\Cell::splitRange($pNamedRange->getRange()); + $range = Cell::splitRange($pNamedRange->getRange()); for ($i = 0; $i < count($range); ++$i) { - $range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . \PhpOffice\PhpSpreadsheet\Cell::absoluteReference($range[$i][0]); + $range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . Cell::absoluteReference($range[$i][0]); if (isset($range[$i][1])) { - $range[$i][1] = \PhpOffice\PhpSpreadsheet\Cell::absoluteReference($range[$i][1]); + $range[$i][1] = Cell::absoluteReference($range[$i][1]); } } - $range = \PhpOffice\PhpSpreadsheet\Cell::buildRange($range); + $range = Cell::buildRange($range); $objWriter->writeRawData($range); @@ -345,13 +353,13 @@ class Workbook extends WriterPart /** * Write Defined Name for autoFilter. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet + * @param XMLWriter $objWriter XML Writer + * @param Worksheet $pSheet * @param int $pSheetId * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDefinedNameForAutofilter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $pSheetId = 0) + private function writeDefinedNameForAutofilter(XMLWriter $objWriter, Worksheet $pSheet, $pSheetId = 0) { // definedName for autoFilter $autoFilterRange = $pSheet->getAutoFilter()->getRange(); @@ -362,15 +370,15 @@ class Workbook extends WriterPart $objWriter->writeAttribute('hidden', '1'); // Create absolute coordinate and write as raw text - $range = \PhpOffice\PhpSpreadsheet\Cell::splitRange($autoFilterRange); + $range = Cell::splitRange($autoFilterRange); $range = $range[0]; // Strip any worksheet ref so we can make the cell ref absolute if (strpos($range[0], '!') !== false) { list($ws, $range[0]) = explode('!', $range[0]); } - $range[0] = \PhpOffice\PhpSpreadsheet\Cell::absoluteCoordinate($range[0]); - $range[1] = \PhpOffice\PhpSpreadsheet\Cell::absoluteCoordinate($range[1]); + $range[0] = Cell::absoluteCoordinate($range[0]); + $range[1] = Cell::absoluteCoordinate($range[1]); $range = implode(':', $range); $objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range); @@ -382,13 +390,13 @@ class Workbook extends WriterPart /** * Write Defined Name for PrintTitles. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet + * @param XMLWriter $objWriter XML Writer + * @param Worksheet $pSheet * @param int $pSheetId * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDefinedNameForPrintTitles(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $pSheetId = 0) + private function writeDefinedNameForPrintTitles(XMLWriter $objWriter, Worksheet $pSheet, $pSheetId = 0) { // definedName for PrintTitles if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet() || $pSheet->getPageSetup()->isRowsToRepeatAtTopSet()) { @@ -426,13 +434,13 @@ class Workbook extends WriterPart /** * Write Defined Name for PrintTitles. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet + * @param XMLWriter $objWriter XML Writer + * @param Worksheet $pSheet * @param int $pSheetId * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDefinedNameForPrintArea(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $pSheetId = 0) + private function writeDefinedNameForPrintArea(XMLWriter $objWriter, Worksheet $pSheet, $pSheetId = 0) { // definedName for PrintArea if ($pSheet->getPageSetup()->isPrintAreaSet()) { @@ -444,12 +452,12 @@ class Workbook extends WriterPart $settingString = ''; // Print area - $printArea = \PhpOffice\PhpSpreadsheet\Cell::splitRange($pSheet->getPageSetup()->getPrintArea()); + $printArea = Cell::splitRange($pSheet->getPageSetup()->getPrintArea()); $chunks = []; foreach ($printArea as $printAreaRect) { - $printAreaRect[0] = \PhpOffice\PhpSpreadsheet\Cell::absoluteReference($printAreaRect[0]); - $printAreaRect[1] = \PhpOffice\PhpSpreadsheet\Cell::absoluteReference($printAreaRect[1]); + $printAreaRect[0] = Cell::absoluteReference($printAreaRect[0]); + $printAreaRect[1] = Cell::absoluteReference($printAreaRect[1]); $chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect); } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index e8d3b715..dfaea5a0 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; -/** +/* * PhpSpreadsheet. * * Copyright (c) 2006 - 2015 PhpSpreadsheet @@ -26,6 +26,16 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ +use PhpOffice\PhpSpreadsheet\Cell; +use PhpOffice\PhpSpreadsheet\RichText; +use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; +use PhpOffice\PhpSpreadsheet\Style\Conditional; +use PhpOffice\PhpSpreadsheet\Worksheet as PhpspreadsheetWorksheet; +use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; +use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; +use PhpOffice\PhpSpreadsheet\Worksheet\SheetView; +use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; /** * @category PhpSpreadsheet @@ -37,11 +47,11 @@ class Worksheet extends WriterPart /** * Write worksheet to XML format. * - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet + * @param PhpspreadsheetWorksheet $pSheet * @param string[] $pStringTable * @param bool $includeCharts Flag indicating if we should write charts * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException * * @return string XML Output */ @@ -51,9 +61,9 @@ class Worksheet extends WriterPart // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY); + $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header @@ -133,18 +143,18 @@ class Worksheet extends WriterPart // Return return $objWriter->getData(); } - throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid \\PhpOffice\\PhpSpreadsheet\\Worksheet object passed.'); + throw new WriterException('Invalid \\PhpOffice\\PhpSpreadsheet\\Worksheet object passed.'); } /** * Write SheetPr. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheetPr(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeSheetPr(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // sheetPr $objWriter->startElement('sheetPr'); @@ -187,12 +197,12 @@ class Worksheet extends WriterPart /** * Write Dimension. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDimension(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeDimension(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // dimension $objWriter->startElement('dimension'); @@ -203,12 +213,12 @@ class Worksheet extends WriterPart /** * Write SheetViews. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheetViews(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeSheetViews(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // sheetViews $objWriter->startElement('sheetViews'); @@ -233,7 +243,7 @@ class Worksheet extends WriterPart } // View Layout Type - if ($pSheet->getSheetView()->getView() !== \PhpOffice\PhpSpreadsheet\Worksheet\SheetView::SHEETVIEW_NORMAL) { + if ($pSheet->getSheetView()->getView() !== SheetView::SHEETVIEW_NORMAL) { $objWriter->writeAttribute('view', $pSheet->getSheetView()->getView()); } @@ -266,8 +276,8 @@ class Worksheet extends WriterPart // Calculate freeze coordinates $xSplit = $ySplit = 0; - list($xSplit, $ySplit) = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($topLeftCell); - $xSplit = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($xSplit); + list($xSplit, $ySplit) = Cell::coordinateFromString($topLeftCell); + $xSplit = Cell::columnIndexFromString($xSplit); // pane $pane = 'topRight'; @@ -296,7 +306,6 @@ class Worksheet extends WriterPart } // Selection -// if ($pane != '') { // Only need to write selection element if we have a split pane // We cheat a little by over-riding the active cell selection, setting it to the split cell $objWriter->startElement('selection'); @@ -306,7 +315,6 @@ class Worksheet extends WriterPart $objWriter->writeAttribute('activeCell', $activeCell); $objWriter->writeAttribute('sqref', $activeCell); $objWriter->endElement(); -// } $objWriter->endElement(); @@ -316,12 +324,12 @@ class Worksheet extends WriterPart /** * Write SheetFormatPr. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheetFormatPr(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeSheetFormatPr(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // sheetFormatPr $objWriter->startElement('sheetFormatPr'); @@ -329,7 +337,7 @@ class Worksheet extends WriterPart // Default row height if ($pSheet->getDefaultRowDimension()->getRowHeight() >= 0) { $objWriter->writeAttribute('customHeight', 'true'); - $objWriter->writeAttribute('defaultRowHeight', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getDefaultRowDimension()->getRowHeight())); + $objWriter->writeAttribute('defaultRowHeight', StringHelper::formatNumber($pSheet->getDefaultRowDimension()->getRowHeight())); } else { $objWriter->writeAttribute('defaultRowHeight', '14.4'); } @@ -342,7 +350,7 @@ class Worksheet extends WriterPart // Default column width if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) { - $objWriter->writeAttribute('defaultColWidth', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getDefaultColumnDimension()->getWidth())); + $objWriter->writeAttribute('defaultColWidth', StringHelper::formatNumber($pSheet->getDefaultColumnDimension()->getWidth())); } // Outline level - row @@ -369,12 +377,12 @@ class Worksheet extends WriterPart /** * Write Cols. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeCols(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeCols(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // cols if (count($pSheet->getColumnDimensions()) > 0) { @@ -386,15 +394,15 @@ class Worksheet extends WriterPart foreach ($pSheet->getColumnDimensions() as $colDimension) { // col $objWriter->startElement('col'); - $objWriter->writeAttribute('min', \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($colDimension->getColumnIndex())); - $objWriter->writeAttribute('max', \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($colDimension->getColumnIndex())); + $objWriter->writeAttribute('min', Cell::columnIndexFromString($colDimension->getColumnIndex())); + $objWriter->writeAttribute('max', Cell::columnIndexFromString($colDimension->getColumnIndex())); if ($colDimension->getWidth() < 0) { // No width set, apply default of 10 $objWriter->writeAttribute('width', '9.10'); } else { // Width set - $objWriter->writeAttribute('width', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($colDimension->getWidth())); + $objWriter->writeAttribute('width', StringHelper::formatNumber($colDimension->getWidth())); } // Column visibility @@ -435,12 +443,12 @@ class Worksheet extends WriterPart /** * Write SheetProtection. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheetProtection(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeSheetProtection(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // sheetProtection $objWriter->startElement('sheetProtection'); @@ -471,12 +479,12 @@ class Worksheet extends WriterPart /** * Write ConditionalFormatting. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeConditionalFormatting(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeConditionalFormatting(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // Conditional id $id = 1; @@ -488,7 +496,7 @@ class Worksheet extends WriterPart // if ($this->getParentWriter()->getStylesConditionalHashTable()->getIndexForHashCode($conditional->getHashCode()) == '') { // continue; // } - if ($conditional->getConditionType() != \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_NONE) { + if ($conditional->getConditionType() != Conditional::CONDITION_NONE) { // conditionalFormatting $objWriter->startElement('conditionalFormatting'); $objWriter->writeAttribute('sqref', $cellCoordinate); @@ -499,35 +507,35 @@ class Worksheet extends WriterPart $objWriter->writeAttribute('dxfId', $this->getParentWriter()->getStylesConditionalHashTable()->getIndexForHashCode($conditional->getHashCode())); $objWriter->writeAttribute('priority', $id++); - if (($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS || $conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT) - && $conditional->getOperatorType() != \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_NONE) { + if (($conditional->getConditionType() == Conditional::CONDITION_CELLIS || $conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT) + && $conditional->getOperatorType() != Conditional::OPERATOR_NONE) { $objWriter->writeAttribute('operator', $conditional->getOperatorType()); } - if ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT + if ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT && !is_null($conditional->getText())) { $objWriter->writeAttribute('text', $conditional->getText()); } - if ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_CONTAINSTEXT + if ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == Conditional::OPERATOR_CONTAINSTEXT && !is_null($conditional->getText())) { $objWriter->writeElement('formula', 'NOT(ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . ')))'); - } elseif ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BEGINSWITH + } elseif ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == Conditional::OPERATOR_BEGINSWITH && !is_null($conditional->getText())) { $objWriter->writeElement('formula', 'LEFT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"'); - } elseif ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_ENDSWITH + } elseif ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == Conditional::OPERATOR_ENDSWITH && !is_null($conditional->getText())) { $objWriter->writeElement('formula', 'RIGHT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"'); - } elseif ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_NOTCONTAINS + } elseif ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == Conditional::OPERATOR_NOTCONTAINS && !is_null($conditional->getText())) { $objWriter->writeElement('formula', 'ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . '))'); - } elseif ($conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS - || $conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CONTAINSTEXT - || $conditional->getConditionType() == \PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_EXPRESSION) { + } elseif ($conditional->getConditionType() == Conditional::CONDITION_CELLIS + || $conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT + || $conditional->getConditionType() == Conditional::CONDITION_EXPRESSION) { foreach ($conditional->getConditions() as $formula) { // Formula $objWriter->writeElement('formula', $formula); @@ -545,18 +553,19 @@ class Worksheet extends WriterPart /** * Write DataValidations. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDataValidations(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeDataValidations(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // Datavalidation collection $dataValidationCollection = $pSheet->getDataValidationCollection(); // Write data validations? if (!empty($dataValidationCollection)) { + $dataValidationCollection = Cell::mergeRangesInCollection($dataValidationCollection); $objWriter->startElement('dataValidations'); $objWriter->writeAttribute('count', count($dataValidationCollection)); @@ -612,12 +621,12 @@ class Worksheet extends WriterPart /** * Write Hyperlinks. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeHyperlinks(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeHyperlinks(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // Hyperlink collection $hyperlinkCollection = $pSheet->getHyperlinkCollection(); @@ -654,12 +663,12 @@ class Worksheet extends WriterPart /** * Write ProtectedRanges. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeProtectedRanges(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeProtectedRanges(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { if (count($pSheet->getProtectedCells()) > 0) { // protectedRanges @@ -684,12 +693,12 @@ class Worksheet extends WriterPart /** * Write MergeCells. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeMergeCells(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeMergeCells(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { if (count($pSheet->getMergeCells()) > 0) { // mergeCells @@ -710,12 +719,12 @@ class Worksheet extends WriterPart /** * Write PrintOptions. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writePrintOptions(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writePrintOptions(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // printOptions $objWriter->startElement('printOptions'); @@ -737,33 +746,33 @@ class Worksheet extends WriterPart /** * Write PageMargins. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writePageMargins(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writePageMargins(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // pageMargins $objWriter->startElement('pageMargins'); - $objWriter->writeAttribute('left', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getPageMargins()->getLeft())); - $objWriter->writeAttribute('right', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getPageMargins()->getRight())); - $objWriter->writeAttribute('top', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getPageMargins()->getTop())); - $objWriter->writeAttribute('bottom', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getPageMargins()->getBottom())); - $objWriter->writeAttribute('header', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getPageMargins()->getHeader())); - $objWriter->writeAttribute('footer', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($pSheet->getPageMargins()->getFooter())); + $objWriter->writeAttribute('left', StringHelper::formatNumber($pSheet->getPageMargins()->getLeft())); + $objWriter->writeAttribute('right', StringHelper::formatNumber($pSheet->getPageMargins()->getRight())); + $objWriter->writeAttribute('top', StringHelper::formatNumber($pSheet->getPageMargins()->getTop())); + $objWriter->writeAttribute('bottom', StringHelper::formatNumber($pSheet->getPageMargins()->getBottom())); + $objWriter->writeAttribute('header', StringHelper::formatNumber($pSheet->getPageMargins()->getHeader())); + $objWriter->writeAttribute('footer', StringHelper::formatNumber($pSheet->getPageMargins()->getFooter())); $objWriter->endElement(); } /** * Write AutoFilter. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeAutoFilter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeAutoFilter(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { $autoFilterRange = $pSheet->getAutoFilter()->getRange(); if (!empty($autoFilterRange)) { @@ -771,7 +780,7 @@ class Worksheet extends WriterPart $objWriter->startElement('autoFilter'); // Strip any worksheet reference from the filter coordinates - $range = \PhpOffice\PhpSpreadsheet\Cell::splitRange($autoFilterRange); + $range = Cell::splitRange($autoFilterRange); $range = $range[0]; // Strip any worksheet ref if (strpos($range[0], '!') !== false) { @@ -782,7 +791,7 @@ class Worksheet extends WriterPart $objWriter->writeAttribute('ref', str_replace('$', '', $range)); $columns = $pSheet->getAutoFilter()->getColumns(); - if (count($columns > 0)) { + if (count($columns) > 0) { foreach ($columns as $columnID => $column) { $rules = $column->getRules(); if (count($rules) > 0) { @@ -790,17 +799,17 @@ class Worksheet extends WriterPart $objWriter->writeAttribute('colId', $pSheet->getAutoFilter()->getColumnOffset($columnID)); $objWriter->startElement($column->getFilterType()); - if ($column->getJoin() == \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND) { + if ($column->getJoin() == Column::AUTOFILTER_COLUMN_JOIN_AND) { $objWriter->writeAttribute('and', 1); } foreach ($rules as $rule) { - if (($column->getFilterType() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) && - ($rule->getOperator() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL) && + if (($column->getFilterType() === Column::AUTOFILTER_FILTERTYPE_FILTER) && + ($rule->getOperator() === Rule::AUTOFILTER_COLUMN_RULE_EQUAL) && ($rule->getValue() === '')) { // Filter rule for Blanks $objWriter->writeAttribute('blank', 1); - } elseif ($rule->getRuleType() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER) { + } elseif ($rule->getRuleType() === Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER) { // Dynamic Filter Rule $objWriter->writeAttribute('type', $rule->getGrouping()); $val = $column->getAttribute('val'); @@ -811,19 +820,19 @@ class Worksheet extends WriterPart if ($maxVal !== null) { $objWriter->writeAttribute('maxVal', $maxVal); } - } elseif ($rule->getRuleType() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_TOPTENFILTER) { + } elseif ($rule->getRuleType() === Rule::AUTOFILTER_RULETYPE_TOPTENFILTER) { // Top 10 Filter Rule $objWriter->writeAttribute('val', $rule->getValue()); - $objWriter->writeAttribute('percent', (($rule->getOperator() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT) ? '1' : '0')); - $objWriter->writeAttribute('top', (($rule->getGrouping() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) ? '1' : '0')); + $objWriter->writeAttribute('percent', (($rule->getOperator() === Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT) ? '1' : '0')); + $objWriter->writeAttribute('top', (($rule->getGrouping() === Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) ? '1' : '0')); } else { // Filter, DateGroupItem or CustomFilter $objWriter->startElement($rule->getRuleType()); - if ($rule->getOperator() !== \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL) { + if ($rule->getOperator() !== Rule::AUTOFILTER_COLUMN_RULE_EQUAL) { $objWriter->writeAttribute('operator', $rule->getOperator()); } - if ($rule->getRuleType() === \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP) { + if ($rule->getRuleType() === Rule::AUTOFILTER_RULETYPE_DATEGROUP) { // Date Group filters foreach ($rule->getValue() as $key => $value) { if ($value > '') { @@ -852,12 +861,12 @@ class Worksheet extends WriterPart /** * Write PageSetup. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writePageSetup(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writePageSetup(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // pageSetup $objWriter->startElement('pageSetup'); @@ -888,12 +897,12 @@ class Worksheet extends WriterPart /** * Write Header / Footer. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeHeaderFooter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeHeaderFooter(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // headerFooter $objWriter->startElement('headerFooter'); @@ -914,20 +923,20 @@ class Worksheet extends WriterPart /** * Write Breaks. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeBreaks(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeBreaks(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // Get row and column breaks $aRowBreaks = []; $aColumnBreaks = []; foreach ($pSheet->getBreaks() as $cell => $breakType) { - if ($breakType == \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_ROW) { + if ($breakType == PhpspreadsheetWorksheet::BREAK_ROW) { $aRowBreaks[] = $cell; - } elseif ($breakType == \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_COLUMN) { + } elseif ($breakType == PhpspreadsheetWorksheet::BREAK_COLUMN) { $aColumnBreaks[] = $cell; } } @@ -939,7 +948,7 @@ class Worksheet extends WriterPart $objWriter->writeAttribute('manualBreakCount', count($aRowBreaks)); foreach ($aRowBreaks as $cell) { - $coords = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($cell); + $coords = Cell::coordinateFromString($cell); $objWriter->startElement('brk'); $objWriter->writeAttribute('id', $coords[1]); @@ -957,10 +966,10 @@ class Worksheet extends WriterPart $objWriter->writeAttribute('manualBreakCount', count($aColumnBreaks)); foreach ($aColumnBreaks as $cell) { - $coords = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($cell); + $coords = Cell::coordinateFromString($cell); $objWriter->startElement('brk'); - $objWriter->writeAttribute('id', \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($coords[0]) - 1); + $objWriter->writeAttribute('id', Cell::columnIndexFromString($coords[0]) - 1); $objWriter->writeAttribute('man', '1'); $objWriter->endElement(); } @@ -972,13 +981,13 @@ class Worksheet extends WriterPart /** * Write SheetData. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * @param string[] $pStringTable String table * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeSheetData(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, array $pStringTable) + private function writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, array $pStringTable) { // Flipped stringtable, for faster index searching $aFlippedStringTable = $this->getParentWriter()->getWriterPart('stringtable')->flipStringTable($pStringTable); @@ -987,7 +996,7 @@ class Worksheet extends WriterPart $objWriter->startElement('sheetData'); // Get column count - $colCount = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($pSheet->getHighestColumn()); + $colCount = Cell::columnIndexFromString($pSheet->getHighestColumn()); // Highest row number $highestRow = $pSheet->getHighestRow(); @@ -995,7 +1004,7 @@ class Worksheet extends WriterPart // Loop through cells $cellsByRow = []; foreach ($pSheet->getCoordinates() as $coordinate) { - $cellAddress = \PhpOffice\PhpSpreadsheet\Cell::coordinateFromString($coordinate); + $cellAddress = Cell::coordinateFromString($coordinate); $cellsByRow[$cellAddress[1]][] = $coordinate; } @@ -1016,7 +1025,7 @@ class Worksheet extends WriterPart // Row dimensions if ($rowDimension->getRowHeight() >= 0) { $objWriter->writeAttribute('customHeight', '1'); - $objWriter->writeAttribute('ht', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($rowDimension->getRowHeight())); + $objWriter->writeAttribute('ht', StringHelper::formatNumber($rowDimension->getRowHeight())); } // Row visibility @@ -1059,15 +1068,15 @@ class Worksheet extends WriterPart /** * Write Cell. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet - * @param \PhpOffice\PhpSpreadsheet\Cell $pCellAddress Cell Address + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet + * @param Cell $pCellAddress Cell Address * @param string[] $pStringTable String table * @param string[] $pFlippedStringTable String table (flipped), for faster index searching * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeCell(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $pCellAddress, array $pFlippedStringTable) + private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, $pCellAddress, array $pFlippedStringTable) { // Cell $pCell = $pSheet->getCell($pCellAddress); @@ -1106,9 +1115,9 @@ class Worksheet extends WriterPart // Write data depending on its type switch (strtolower($mappedType)) { case 'inlinestr': // Inline string - if (!$cellValue instanceof \PhpOffice\PhpSpreadsheet\RichText) { - $objWriter->writeElement('t', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML(htmlspecialchars($cellValue))); - } elseif ($cellValue instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if (!$cellValue instanceof RichText) { + $objWriter->writeElement('t', StringHelper::controlCharacterPHP2OOXML(htmlspecialchars($cellValue))); + } elseif ($cellValue instanceof RichText) { $objWriter->startElement('is'); $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $cellValue); $objWriter->endElement(); @@ -1116,11 +1125,11 @@ class Worksheet extends WriterPart break; case 's': // String - if (!$cellValue instanceof \PhpOffice\PhpSpreadsheet\RichText) { + if (!$cellValue instanceof RichText) { if (isset($pFlippedStringTable[$cellValue])) { $objWriter->writeElement('v', $pFlippedStringTable[$cellValue]); } - } elseif ($cellValue instanceof \PhpOffice\PhpSpreadsheet\RichText) { + } elseif ($cellValue instanceof RichText) { $objWriter->writeElement('v', $pFlippedStringTable[$cellValue->getHashCode()]); } @@ -1141,7 +1150,7 @@ class Worksheet extends WriterPart if ($this->getParentWriter()->getOffice2003Compatibility() === false) { if ($this->getParentWriter()->getPreCalculateFormulas()) { if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) != '#') { - $objWriter->writeElement('v', \PhpOffice\PhpSpreadsheet\Shared\StringHelper::formatNumber($calculatedValue)); + $objWriter->writeElement('v', StringHelper::formatNumber($calculatedValue)); } else { $objWriter->writeElement('v', '0'); } @@ -1175,13 +1184,13 @@ class Worksheet extends WriterPart /** * Write Drawings. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * @param bool $includeCharts Flag indicating if we should include drawing details for charts * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeDrawings(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet = null, $includeCharts = false) + private function writeDrawings(XMLWriter $objWriter = null, PhpspreadsheetWorksheet $pSheet = null, $includeCharts = false) { $chartCount = ($includeCharts) ? $pSheet->getChartCollection()->count() : 0; // If sheet contains drawings, add the relationships @@ -1196,12 +1205,12 @@ class Worksheet extends WriterPart /** * Write LegacyDrawing. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeLegacyDrawing(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeLegacyDrawing(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // If sheet contains comments, add the relationships if (count($pSheet->getComments()) > 0) { @@ -1214,12 +1223,12 @@ class Worksheet extends WriterPart /** * Write LegacyDrawingHF. * - * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer - * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet Worksheet + * @param XMLWriter $objWriter XML Writer + * @param PhpspreadsheetWorksheet $pSheet Worksheet * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ - private function writeLegacyDrawingHF(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet) + private function writeLegacyDrawingHF(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet) { // If sheet contains images, add the relationships if (count($pSheet->getHeaderFooter()->getImages()) > 0) { diff --git a/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php b/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php index a743ab12..e6a16fda 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/WriterPart.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; + /** * Copyright (c) 2006 - 2015 PhpSpreadsheet. * @@ -29,7 +31,7 @@ abstract class WriterPart /** * Parent Xlsx object. * - * @var \PhpOffice\PhpSpreadsheet\Writer\Xlsx + * @var Xlsx */ private $parentWriter; @@ -38,7 +40,7 @@ abstract class WriterPart * * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * - * @return \PhpOffice\PhpSpreadsheet\Writer\Xlsx + * @return Xlsx */ public function getParentWriter() { @@ -48,9 +50,9 @@ abstract class WriterPart /** * Set parent Xlsx object. * - * @param \PhpOffice\PhpSpreadsheet\Writer\Xlsx $pWriter + * @param Xlsx $pWriter */ - public function __construct(\PhpOffice\PhpSpreadsheet\Writer\Xlsx $pWriter) + public function __construct(Xlsx $pWriter) { $this->parentWriter = $pWriter; } diff --git a/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php b/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php index d8458045..6b05d454 100644 --- a/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php @@ -5,11 +5,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\DateTime; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Shared\Date; +use PHPUnit_Framework_TestCase; /** * Class DateTimeTest. */ -class DateTimeTest extends \PHPUnit_Framework_TestCase +class DateTimeTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Calculation/EngineeringTest.php b/tests/PhpSpreadsheetTests/Calculation/EngineeringTest.php index 89d1e5f1..2e19eff7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/EngineeringTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/EngineeringTest.php @@ -4,17 +4,19 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; +use PHPUnit_Framework_TestCase; -class EngineeringTest extends \PHPUnit_Framework_TestCase +class EngineeringTest extends PHPUnit_Framework_TestCase { /** - * @var \PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert + * @var ComplexAssert */ protected $complexAssert; public function setUp() { - $this->complexAssert = new \PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert(); + $this->complexAssert = new ComplexAssert(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } diff --git a/tests/PhpSpreadsheetTests/Calculation/FinancialTest.php b/tests/PhpSpreadsheetTests/Calculation/FinancialTest.php index b61ef6ae..04f6b4e8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/FinancialTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/FinancialTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Financial; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PHPUnit_Framework_TestCase; -class FinancialTest extends \PHPUnit_Framework_TestCase +class FinancialTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php index 2f6aaa06..371f2826 100644 --- a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PHPUnit_Framework_TestCase; -class FunctionsTest extends \PHPUnit_Framework_TestCase +class FunctionsTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php b/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php index ab9cf4fd..d1aac26a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Logical; +use PHPUnit_Framework_TestCase; -class LogicalTest extends \PHPUnit_Framework_TestCase +class LogicalTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php b/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php index 39dfa17d..94696e4c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php @@ -4,11 +4,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\LookupRef; +use PHPUnit_Framework_TestCase; /** * Class LookupRefTest. */ -class LookupRefTest extends \PHPUnit_Framework_TestCase +class LookupRefTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php b/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php index 518250fa..d765931c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PHPUnit_Framework_TestCase; -class MathTrigTest extends \PHPUnit_Framework_TestCase +class MathTrigTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php b/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php index e4c06b2d..8a6cd0c5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PHPUnit_Framework_TestCase; -class TextDataTest extends \PHPUnit_Framework_TestCase +class TextDataTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/CalculationTest.php b/tests/PhpSpreadsheetTests/CalculationTest.php index 8711e6ac..d8979979 100644 --- a/tests/PhpSpreadsheetTests/CalculationTest.php +++ b/tests/PhpSpreadsheetTests/CalculationTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests; use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PHPUnit_Framework_TestCase; -class CalculationTest extends \PHPUnit_Framework_TestCase +class CalculationTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php b/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php index 2f8b29a3..637ced24 100644 --- a/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php +++ b/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php @@ -9,8 +9,9 @@ use PhpOffice\PhpSpreadsheet\Collection\Cells; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Worksheet; +use PHPUnit_Framework_TestCase; -class AdvancedValueBinderTest extends \PHPUnit_Framework_TestCase +class AdvancedValueBinderTest extends PHPUnit_Framework_TestCase { public function provider() { diff --git a/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php b/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php index f98f4fb5..92ab1f29 100644 --- a/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Cell; use PhpOffice\PhpSpreadsheet\Cell\DataType; +use PHPUnit_Framework_TestCase; -class DataTypeTest extends \PHPUnit_Framework_TestCase +class DataTypeTest extends PHPUnit_Framework_TestCase { public function testGetErrorCodes() { diff --git a/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php b/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php index ca892d66..4d09a56a 100644 --- a/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php @@ -2,12 +2,14 @@ namespace PhpOffice\PhpSpreadsheetTests\Cell; +use DateTime; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder; use PhpOffice\PhpSpreadsheet\RichText; +use PHPUnit_Framework_TestCase; -class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase +class DefaultValueBinderTest extends PHPUnit_Framework_TestCase { protected $cellStub; @@ -50,7 +52,7 @@ class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase ['123'], ['-123.456'], ['#REF!'], - [new \DateTime()], + [new DateTime()], ]; } diff --git a/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php b/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php index b4c68f62..3d86cb62 100644 --- a/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php +++ b/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Cell; use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; +use PHPUnit_Framework_TestCase; -class HyperlinkTest extends \PHPUnit_Framework_TestCase +class HyperlinkTest extends PHPUnit_Framework_TestCase { public function testGetUrl() { diff --git a/tests/PhpSpreadsheetTests/CellTest.php b/tests/PhpSpreadsheetTests/CellTest.php index 6e60efe5..3a7d429e 100644 --- a/tests/PhpSpreadsheetTests/CellTest.php +++ b/tests/PhpSpreadsheetTests/CellTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Exception; +use PHPUnit_Framework_TestCase; -class CellTest extends \PHPUnit_Framework_TestCase +class CellTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerColumnString @@ -299,4 +300,20 @@ class CellTest extends \PHPUnit_Framework_TestCase { return require 'data/CellExtractAllCellReferencesInRange.php'; } + + /** + * @dataProvider providerMergeRangesInCollection + * + * @param mixed $expectedResult + */ + public function testMergeRangesInCollection($expectedResult, ...$args) + { + $result = Cell::mergeRangesInCollection(...$args); + $this->assertEquals($expectedResult, $result); + } + + public function providerMergeRangesInCollection() + { + return require 'data/CellMergeRangesInCollection.php'; + } } diff --git a/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php b/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php index 7e87bfab..a7746b16 100644 --- a/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php +++ b/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Exception; +use PHPUnit_Framework_TestCase; -class DataSeriesValuesTest extends \PHPUnit_Framework_TestCase +class DataSeriesValuesTest extends PHPUnit_Framework_TestCase { public function testSetDataType() { diff --git a/tests/PhpSpreadsheetTests/Chart/LayoutTest.php b/tests/PhpSpreadsheetTests/Chart/LayoutTest.php index de8d3c9f..22daa18d 100644 --- a/tests/PhpSpreadsheetTests/Chart/LayoutTest.php +++ b/tests/PhpSpreadsheetTests/Chart/LayoutTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Layout; +use PHPUnit_Framework_TestCase; -class LayoutTest extends \PHPUnit_Framework_TestCase +class LayoutTest extends PHPUnit_Framework_TestCase { public function testSetLayoutTarget() { diff --git a/tests/PhpSpreadsheetTests/Chart/LegendTest.php b/tests/PhpSpreadsheetTests/Chart/LegendTest.php index e472fbfe..1df0ab70 100644 --- a/tests/PhpSpreadsheetTests/Chart/LegendTest.php +++ b/tests/PhpSpreadsheetTests/Chart/LegendTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Legend; +use PHPUnit_Framework_TestCase; -class LegendTest extends \PHPUnit_Framework_TestCase +class LegendTest extends PHPUnit_Framework_TestCase { public function testSetPosition() { diff --git a/tests/PhpSpreadsheetTests/Collection/CellsTest.php b/tests/PhpSpreadsheetTests/Collection/CellsTest.php index 6b91ec6f..33899be7 100644 --- a/tests/PhpSpreadsheetTests/Collection/CellsTest.php +++ b/tests/PhpSpreadsheetTests/Collection/CellsTest.php @@ -7,8 +7,9 @@ use PhpOffice\PhpSpreadsheet\Collection\Cells; use PhpOffice\PhpSpreadsheet\Collection\Memory; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet; +use PHPUnit_Framework_TestCase; -class CellsTest extends \PHPUnit_Framework_TestCase +class CellsTest extends PHPUnit_Framework_TestCase { public function testCollectionCell() { diff --git a/tests/PhpSpreadsheetTests/Helper/MigratorTest.php b/tests/PhpSpreadsheetTests/Helper/MigratorTest.php index 39a922ab..cb91f65a 100644 --- a/tests/PhpSpreadsheetTests/Helper/MigratorTest.php +++ b/tests/PhpSpreadsheetTests/Helper/MigratorTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Helper; use PhpOffice\PhpSpreadsheet\Helper\Migrator; +use PHPUnit_Framework_TestCase; -class MigratorTest extends \PHPUnit_Framework_TestCase +class MigratorTest extends PHPUnit_Framework_TestCase { public function testMappingOnlyContainExistingClasses() { diff --git a/tests/PhpSpreadsheetTests/IOFactoryTest.php b/tests/PhpSpreadsheetTests/IOFactoryTest.php index 51787521..071e4bb6 100644 --- a/tests/PhpSpreadsheetTests/IOFactoryTest.php +++ b/tests/PhpSpreadsheetTests/IOFactoryTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests; use PhpOffice\PhpSpreadsheet\IOFactory; +use PHPUnit_Framework_TestCase; -class IOFactoryTest extends \PHPUnit_Framework_TestCase +class IOFactoryTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerIdentify diff --git a/tests/PhpSpreadsheetTests/Reader/CsvTest.php b/tests/PhpSpreadsheetTests/Reader/CsvTest.php index 6727b10b..90e94a52 100644 --- a/tests/PhpSpreadsheetTests/Reader/CsvTest.php +++ b/tests/PhpSpreadsheetTests/Reader/CsvTest.php @@ -2,10 +2,13 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader; +use PhpOffice\PhpSpreadsheet\Reader\Csv as ReaderCsv; use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Csv as WriterCsv; +use PHPUnit_Framework_TestCase; -class CsvTest extends \PHPUnit_Framework_TestCase +class CsvTest extends PHPUnit_Framework_TestCase { public function testEnclosure() { @@ -15,11 +18,11 @@ class CsvTest extends \PHPUnit_Framework_TestCase // Write temp file with value $spreadsheet = new Spreadsheet(); $spreadsheet->getActiveSheet()->getCell('A1')->setValue($value); - $writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet); + $writer = new WriterCsv($spreadsheet); $writer->save($filename); // Read written file - $reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv(); + $reader = new ReaderCsv(); $reloadedSpreadsheet = $reader->load($filename); $actual = $reloadedSpreadsheet->getActiveSheet()->getCell('A1')->getCalculatedValue(); $this->assertSame($value, $actual, 'should be able to write and read strings with multiples quotes'); @@ -27,7 +30,7 @@ class CsvTest extends \PHPUnit_Framework_TestCase public function testDelimiterDetection() { - $reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv(); + $reader = new ReaderCsv(); $this->assertNull($reader->getDelimiter()); $filename = __DIR__ . '/../../data/Reader/CSV/semicolon_separated.csv'; diff --git a/tests/PhpSpreadsheetTests/Reader/HTMLTest.php b/tests/PhpSpreadsheetTests/Reader/HTMLTest.php index 03ad95f9..ca85be9c 100644 --- a/tests/PhpSpreadsheetTests/Reader/HTMLTest.php +++ b/tests/PhpSpreadsheetTests/Reader/HTMLTest.php @@ -3,17 +3,14 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader; use PhpOffice\PhpSpreadsheet\Reader\Html; +use PHPUnit_Framework_TestCase; -class HTMLTest extends \PHPUnit_Framework_TestCase +class HTMLTest extends PHPUnit_Framework_TestCase { public function testCsvWithAngleBracket() { $filename = __DIR__ . '/../../data/Reader/HTML/csv_with_angle_bracket.csv'; - $this->assertFalse($this->getInstance()->canRead($filename)); - } - - private function getInstance() - { - return new HTML(); + $reader = new Html(); + $this->assertFalse($reader->canRead($filename)); } } diff --git a/tests/PhpSpreadsheetTests/Reader/OdsTest.php b/tests/PhpSpreadsheetTests/Reader/OdsTest.php index ccda9958..658869b0 100644 --- a/tests/PhpSpreadsheetTests/Reader/OdsTest.php +++ b/tests/PhpSpreadsheetTests/Reader/OdsTest.php @@ -4,25 +4,27 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Reader\Ods; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Font; +use PHPUnit_Framework_TestCase; /** * @todo The class doesn't read the bold/italic/underline properties (rich text) */ -class OdsTest extends \PHPUnit_Framework_TestCase +class OdsTest extends PHPUnit_Framework_TestCase { /** - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $spreadsheetOOCalcTest; /** - * @var \PhpOffice\PhpSpreadsheet\Spreadsheet + * @var Spreadsheet */ private $spreadsheetData; /** - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ protected function loadOOCalcTestFile() { @@ -31,14 +33,14 @@ class OdsTest extends \PHPUnit_Framework_TestCase // Load into this instance $reader = new Ods(); - $this->spreadsheetOOCalcTest = $reader->loadIntoExisting($filename, new \PhpOffice\PhpSpreadsheet\Spreadsheet()); + $this->spreadsheetOOCalcTest = $reader->loadIntoExisting($filename, new Spreadsheet()); } return $this->spreadsheetOOCalcTest; } /** - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ protected function loadDataFile() { @@ -47,7 +49,7 @@ class OdsTest extends \PHPUnit_Framework_TestCase // Load into this instance $reader = new Ods(); - $this->spreadsheetData = $reader->loadIntoExisting($filename, new \PhpOffice\PhpSpreadsheet\Spreadsheet()); + $this->spreadsheetData = $reader->loadIntoExisting($filename, new Spreadsheet()); } return $this->spreadsheetData; diff --git a/tests/PhpSpreadsheetTests/Reader/XEEValidatorTest.php b/tests/PhpSpreadsheetTests/Reader/XEEValidatorTest.php index a9a97314..372e51bb 100644 --- a/tests/PhpSpreadsheetTests/Reader/XEEValidatorTest.php +++ b/tests/PhpSpreadsheetTests/Reader/XEEValidatorTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader; use PhpOffice\PhpSpreadsheet\Reader\BaseReader; +use PHPUnit_Framework_TestCase; -class XEEValidatorTest extends \PHPUnit_Framework_TestCase +class XEEValidatorTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerInvalidXML diff --git a/tests/PhpSpreadsheetTests/ReferenceHelperTest.php b/tests/PhpSpreadsheetTests/ReferenceHelperTest.php index ecbcd081..1f7e0d56 100644 --- a/tests/PhpSpreadsheetTests/ReferenceHelperTest.php +++ b/tests/PhpSpreadsheetTests/ReferenceHelperTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests; use PhpOffice\PhpSpreadsheet\ReferenceHelper; +use PHPUnit_Framework_TestCase; -class ReferenceHelperTest extends \PHPUnit_Framework_TestCase +class ReferenceHelperTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/SampleTest.php b/tests/PhpSpreadsheetTests/SampleTest.php index a7e1e075..ecbedfbd 100644 --- a/tests/PhpSpreadsheetTests/SampleTest.php +++ b/tests/PhpSpreadsheetTests/SampleTest.php @@ -2,7 +2,10 @@ namespace PhpOffice\PhpSpreadsheetTests; -class SampleTest extends \PHPUnit_Framework_TestCase +use PhpOffice\PhpSpreadsheet\Helper\Sample; +use PHPUnit_Framework_TestCase; + +class SampleTest extends PHPUnit_Framework_TestCase { /** * @runInSeparateProcess @@ -35,7 +38,7 @@ class SampleTest extends \PHPUnit_Framework_TestCase $skipped = array_merge($skipped, $tooLongToBeCovered); } - $helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); + $helper = new Sample(); $samples = []; foreach ($helper->getSamples() as $name => $sample) { if (!in_array($name, $skipped)) { diff --git a/tests/PhpSpreadsheetTests/SettingsTest.php b/tests/PhpSpreadsheetTests/SettingsTest.php index 02a8c36b..ec0e12ea 100644 --- a/tests/PhpSpreadsheetTests/SettingsTest.php +++ b/tests/PhpSpreadsheetTests/SettingsTest.php @@ -2,7 +2,10 @@ namespace PhpOffice\PhpSpreadsheetTests; -class SettingsTest extends \PHPUnit_Framework_TestCase +use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit_Framework_TestCase; + +class SettingsTest extends PHPUnit_Framework_TestCase { /** * @var string @@ -22,15 +25,15 @@ class SettingsTest extends \PHPUnit_Framework_TestCase public function testGetXMLSettings() { - $result = \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions(); + $result = Settings::getLibXmlLoaderOptions(); $this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result)); $this->assertFalse(libxml_disable_entity_loader()); } public function testSetXMLSettings() { - \PhpOffice\PhpSpreadsheet\Settings::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID); - $result = \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions(); + Settings::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID); + $result = Settings::getLibXmlLoaderOptions(); $this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result)); $this->assertFalse(libxml_disable_entity_loader()); } diff --git a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php index 337b8ed4..7841fe98 100644 --- a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php +++ b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Shared\CodePage; +use PHPUnit_Framework_TestCase; -class CodePageTest extends \PHPUnit_Framework_TestCase +class CodePageTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerCodePage diff --git a/tests/PhpSpreadsheetTests/Shared/DateTest.php b/tests/PhpSpreadsheetTests/Shared/DateTest.php index 0439cf60..2e6d028d 100644 --- a/tests/PhpSpreadsheetTests/Shared/DateTest.php +++ b/tests/PhpSpreadsheetTests/Shared/DateTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Date; +use PHPUnit_Framework_TestCase; -class DateTest extends \PHPUnit_Framework_TestCase +class DateTest extends PHPUnit_Framework_TestCase { public function testSetExcelCalendar() { diff --git a/tests/PhpSpreadsheetTests/Shared/FileTest.php b/tests/PhpSpreadsheetTests/Shared/FileTest.php index eb802a0f..5f148a2a 100644 --- a/tests/PhpSpreadsheetTests/Shared/FileTest.php +++ b/tests/PhpSpreadsheetTests/Shared/FileTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\File; +use PHPUnit_Framework_TestCase; -class FileTest extends \PHPUnit_Framework_TestCase +class FileTest extends PHPUnit_Framework_TestCase { public function testGetUseUploadTempDirectory() { diff --git a/tests/PhpSpreadsheetTests/Shared/FontTest.php b/tests/PhpSpreadsheetTests/Shared/FontTest.php index c104cb14..76a40d1c 100644 --- a/tests/PhpSpreadsheetTests/Shared/FontTest.php +++ b/tests/PhpSpreadsheetTests/Shared/FontTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Font; +use PHPUnit_Framework_TestCase; -class FontTest extends \PHPUnit_Framework_TestCase +class FontTest extends PHPUnit_Framework_TestCase { public function testGetAutoSizeMethod() { diff --git a/tests/PhpSpreadsheetTests/Shared/PasswordHasherTest.php b/tests/PhpSpreadsheetTests/Shared/PasswordHasherTest.php index 444883cb..271deefc 100644 --- a/tests/PhpSpreadsheetTests/Shared/PasswordHasherTest.php +++ b/tests/PhpSpreadsheetTests/Shared/PasswordHasherTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher; +use PHPUnit_Framework_TestCase; -class PasswordHasherTest extends \PHPUnit_Framework_TestCase +class PasswordHasherTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerHashPassword diff --git a/tests/PhpSpreadsheetTests/Shared/StringTest.php b/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php similarity index 73% rename from tests/PhpSpreadsheetTests/Shared/StringTest.php rename to tests/PhpSpreadsheetTests/Shared/StringHelperTest.php index 83643127..67b82f7e 100644 --- a/tests/PhpSpreadsheetTests/Shared/StringTest.php +++ b/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PHPUnit_Framework_TestCase; -class StringTest extends \PHPUnit_Framework_TestCase +class StringHelperTest extends PHPUnit_Framework_TestCase { public function setUp() { @@ -72,4 +73,28 @@ class StringTest extends \PHPUnit_Framework_TestCase $result = StringHelper::getCurrencyCode(); $this->assertEquals($expectedResult, $result); } + + public function testControlCharacterPHP2OOXML() + { + $expectedResult = 'foo_x000B_bar'; + $result = StringHelper::controlCharacterPHP2OOXML('foo' . chr(11) . 'bar'); + + $this->assertEquals($expectedResult, $result); + } + + public function testControlCharacterOOXML2PHP() + { + $expectedResult = 'foo' . chr(11) . 'bar'; + $result = StringHelper::controlCharacterOOXML2PHP('foo_x000B_bar'); + + $this->assertEquals($expectedResult, $result); + } + + public function testSYLKtoUTF8() + { + $expectedResult = 'foo' . chr(11) . 'bar'; + $result = StringHelper::SYLKtoUTF8("foo\x1B ;bar"); + + $this->assertEquals($expectedResult, $result); + } } diff --git a/tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php b/tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php index 58f791d1..706955c2 100644 --- a/tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php +++ b/tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\TimeZone; +use PHPUnit_Framework_TestCase; -class TimeZoneTest extends \PHPUnit_Framework_TestCase +class TimeZoneTest extends PHPUnit_Framework_TestCase { public function testSetTimezone() { diff --git a/tests/PhpSpreadsheetTests/Style/BorderTest.php b/tests/PhpSpreadsheetTests/Style/BorderTest.php new file mode 100644 index 00000000..4055c870 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Style/BorderTest.php @@ -0,0 +1,26 @@ +getActiveSheet()->getStyle('A1')->getBorders(); + $allBorders = $borders->getAllBorders(); + $bottom = $borders->getBottom(); + + $actual = $bottom->getBorderStyle(); + $this->assertSame(Border::BORDER_NONE, $actual, 'should default to none'); + + $allBorders->setBorderStyle(Border::BORDER_THIN); + + $actual = $bottom->getBorderStyle(); + $this->assertSame(Border::BORDER_THIN, $actual, 'should have been set via allBorders'); + } +} diff --git a/tests/PhpSpreadsheetTests/Style/ColorTest.php b/tests/PhpSpreadsheetTests/Style/ColorTest.php index 8dca92f1..6ed161d2 100644 --- a/tests/PhpSpreadsheetTests/Style/ColorTest.php +++ b/tests/PhpSpreadsheetTests/Style/ColorTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Style; use PhpOffice\PhpSpreadsheet\Style\Color; +use PHPUnit_Framework_TestCase; -class ColorTest extends \PHPUnit_Framework_TestCase +class ColorTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerColorGetRed diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormatDateTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormatDateTest.php index 01c51c59..af462e41 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormatDateTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormatDateTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Style; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; +use PHPUnit_Framework_TestCase; -class NumberFormatDateTest extends \PHPUnit_Framework_TestCase +class NumberFormatDateTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php index d900962a..72c7fbe4 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php @@ -4,8 +4,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Style; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; +use PHPUnit_Framework_TestCase; -class NumberFormatTest extends \PHPUnit_Framework_TestCase +class NumberFormatTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/Column/RuleTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/Column/RuleTest.php index 15d29f32..b7760e25 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/Column/RuleTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/Column/RuleTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; +use PHPUnit_Framework_TestCase; -class RuleTest extends \PHPUnit_Framework_TestCase +class RuleTest extends PHPUnit_Framework_TestCase { private $testAutoFilterRuleObject; private $mockAutoFilterColumnObject; diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php index 8a92c8ad..e171e814 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php @@ -3,8 +3,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; +use PHPUnit_Framework_TestCase; -class ColumnTest extends \PHPUnit_Framework_TestCase +class ColumnTest extends PHPUnit_Framework_TestCase { private $testInitialColumn = 'H'; private $testAutoFilterColumnObject; diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilterTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilterTest.php index 7a943642..974dbd70 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilterTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilterTest.php @@ -6,8 +6,9 @@ use PhpOffice\PhpSpreadsheet\Collection\Cells; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; +use PHPUnit_Framework_TestCase; -class AutoFilterTest extends \PHPUnit_Framework_TestCase +class AutoFilterTest extends PHPUnit_Framework_TestCase { private $testInitialRange = 'H2:O256'; private $testAutoFilterObject; diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php index 997307a4..5af397a5 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator; +use PHPUnit_Framework_TestCase; -class ColumnCellIteratorTest extends \PHPUnit_Framework_TestCase +class ColumnCellIteratorTest extends PHPUnit_Framework_TestCase { public $mockWorksheet; public $mockColumnCell; diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php index 3fdcd446..3f107f45 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Column; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator; +use PHPUnit_Framework_TestCase; -class ColumnIteratorTest extends \PHPUnit_Framework_TestCase +class ColumnIteratorTest extends PHPUnit_Framework_TestCase { public $mockWorksheet; public $mockColumn; diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php index e63d3f95..edb76a55 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator; +use PHPUnit_Framework_TestCase; -class RowCellIteratorTest extends \PHPUnit_Framework_TestCase +class RowCellIteratorTest extends PHPUnit_Framework_TestCase { public $mockWorksheet; public $mockRowCell; diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php index 1bfa69d7..071baf7d 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Row; use PhpOffice\PhpSpreadsheet\Worksheet\RowIterator; +use PHPUnit_Framework_TestCase; -class RowIteratorTest extends \PHPUnit_Framework_TestCase +class RowIteratorTest extends PHPUnit_Framework_TestCase { public $mockWorksheet; public $mockRow; diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetColumnTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetColumnTest.php index 7c1c3487..c8730e25 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetColumnTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetColumnTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Column; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator; +use PHPUnit_Framework_TestCase; -class WorksheetColumnTest extends \PHPUnit_Framework_TestCase +class WorksheetColumnTest extends PHPUnit_Framework_TestCase { public $mockWorksheet; public $mockColumn; diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetRowTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetRowTest.php index 59901f44..d16149fb 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetRowTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetRowTest.php @@ -5,8 +5,9 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Row; use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator; +use PHPUnit_Framework_TestCase; -class WorksheetRowTest extends \PHPUnit_Framework_TestCase +class WorksheetRowTest extends PHPUnit_Framework_TestCase { public $mockWorksheet; public $mockRow; diff --git a/tests/PhpSpreadsheetTests/WorksheetTest.php b/tests/PhpSpreadsheetTests/WorksheetTest.php new file mode 100644 index 00000000..1a7389b0 --- /dev/null +++ b/tests/PhpSpreadsheetTests/WorksheetTest.php @@ -0,0 +1,126 @@ +setTitle($testTitle); + $this->assertSame($testTitle, $worksheet->getTitle()); + } + + public function setTitleInvalidProvider() + { + return [ + [str_repeat('a', 32), 'Maximum 31 characters allowed in sheet title.'], + ['invalid*title', 'Invalid character found in sheet title'], + ]; + } + + /** + * @param string $title + * @param string $expectMessage + * @dataProvider setTitleInvalidProvider + */ + public function testSetTitleInvalid($title, $expectMessage) + { + // First, test setting title with validation disabled -- should be successful + $worksheet = new Worksheet(); + $worksheet->setTitle($title, true, false); + + // Next, test again with validation enabled -- this time we should fail + $worksheet = new Worksheet(); + $this->expectException(\Exception::class); + $this->expectExceptionMessage($expectMessage); + $worksheet->setTitle($title); + } + + public function testSetTitleDuplicate() + { + // Create a Spreadsheet with three Worksheets (the first is created automatically) + $spreadsheet = new Spreadsheet(); + $spreadsheet->createSheet(); + $spreadsheet->createSheet(); + + // Set unique title -- should be unchanged + $sheet = $spreadsheet->getSheet(0); + $sheet->setTitle('Test Title'); + $this->assertSame('Test Title', $sheet->getTitle()); + + // Set duplicate title -- should have numeric suffix appended + $sheet = $spreadsheet->getSheet(1); + $sheet->setTitle('Test Title'); + $this->assertSame('Test Title 1', $sheet->getTitle()); + + // Set duplicate title with validation disabled -- should be unchanged + $sheet = $spreadsheet->getSheet(2); + $sheet->setTitle('Test Title', true, false); + $this->assertSame('Test Title', $sheet->getTitle()); + } + + public function testSetCodeName() + { + $testCodeName = str_repeat('a', 31); + + $worksheet = new Worksheet(); + $worksheet->setCodeName($testCodeName); + $this->assertSame($testCodeName, $worksheet->getCodeName()); + } + + public function setCodeNameInvalidProvider() + { + return [ + [str_repeat('a', 32), 'Maximum 31 characters allowed in sheet code name.'], + ['invalid*code*name', 'Invalid character found in sheet code name'], + ]; + } + + /** + * @param string $codeName + * @param string $expectMessage + * @dataProvider setCodeNameInvalidProvider + */ + public function testSetCodeNameInvalid($codeName, $expectMessage) + { + // First, test setting code name with validation disabled -- should be successful + $worksheet = new Worksheet(); + $worksheet->setCodeName($codeName, false); + + // Next, test again with validation enabled -- this time we should fail + $worksheet = new Worksheet(); + $this->expectException(\Exception::class); + $this->expectExceptionMessage($expectMessage); + $worksheet->setCodeName($codeName); + } + + public function testSetCodeNameDuplicate() + { + // Create a Spreadsheet with three Worksheets (the first is created automatically) + $spreadsheet = new Spreadsheet(); + $spreadsheet->createSheet(); + $spreadsheet->createSheet(); + + // Set unique code name -- should be massaged to Snake_Case + $sheet = $spreadsheet->getSheet(0); + $sheet->setCodeName('Test Code Name'); + $this->assertSame('Test_Code_Name', $sheet->getCodeName()); + + // Set duplicate code name -- should be massaged and have numeric suffix appended + $sheet = $spreadsheet->getSheet(1); + $sheet->setCodeName('Test Code Name'); + $this->assertSame('Test_Code_Name_1', $sheet->getCodeName()); + + // Set duplicate code name with validation disabled -- should be unchanged, and unmassaged + $sheet = $spreadsheet->getSheet(2); + $sheet->setCodeName('Test Code Name', false); + $this->assertSame('Test Code Name', $sheet->getCodeName()); + } +} diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php index 8a4aae64..00cf5cc5 100644 --- a/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Ods/ContentTest.php @@ -12,8 +12,9 @@ use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Writer\Ods; use PhpOffice\PhpSpreadsheet\Writer\Ods\Content; +use PHPUnit_Framework_TestCase; -class ContentTest extends \PHPUnit_Framework_TestCase +class ContentTest extends PHPUnit_Framework_TestCase { private $samplesPath = __DIR__ . '/../../../data/Writer/Ods'; diff --git a/tests/data/CellMergeRangesInCollection.php b/tests/data/CellMergeRangesInCollection.php new file mode 100644 index 00000000..9cb71125 --- /dev/null +++ b/tests/data/CellMergeRangesInCollection.php @@ -0,0 +1,58 @@ + 'x', + 'A4' => 'y', + ], + [ + 'A1' => 'x', + 'A2' => 'x', + 'A3' => 'x', + 'A4' => 'y', + ], + ], + [ + [ + 'A1:A4' => 'x', + 'A6:A7' => 'x', + 'A9' => 'x', + ], + [ + 'A7' => 'x', + 'A1' => 'x', + 'A4' => 'x', + 'A6' => 'x', + 'A2' => 'x', + 'A9' => 'x', + 'A3' => 'x', + ], + ], + [ + [ + 'A1:A3' => 'x', + 'B1:B3' => 'x', + ], + [ + 'A1' => 'x', + 'B3' => 'x', + 'A2' => 'x', + 'B2' => 'x', + 'A3' => 'x', + 'B1' => 'x', + ], + ], + [ + [ + 'A1' => 'x', + 'A2' => 'y', + 'A3' => 'z', + ], + [ + 'A1' => 'x', + 'A2' => 'y', + 'A3' => 'z', + ], + ], +];