diff --git a/bin/migrate-from-phpexcel b/bin/migrate-from-phpexcel index 416c3a42..51c60d49 100755 --- a/bin/migrate-from-phpexcel +++ b/bin/migrate-from-phpexcel @@ -1,6 +1,8 @@ #!/usr/bin/env php migrate(); diff --git a/docs/Examples/Calculations/Database/DAVERAGE.php b/docs/Examples/Calculations/Database/DAVERAGE.php index b54a7d1d..c2d31a6a 100644 --- a/docs/Examples/Calculations/Database/DAVERAGE.php +++ b/docs/Examples/Calculations/Database/DAVERAGE.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DCOUNT.php b/docs/Examples/Calculations/Database/DCOUNT.php index 2cd0661d..d7bf2045 100644 --- a/docs/Examples/Calculations/Database/DCOUNT.php +++ b/docs/Examples/Calculations/Database/DCOUNT.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DGET.php b/docs/Examples/Calculations/Database/DGET.php index d64b1d6e..819120cb 100644 --- a/docs/Examples/Calculations/Database/DGET.php +++ b/docs/Examples/Calculations/Database/DGET.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DMAX.php b/docs/Examples/Calculations/Database/DMAX.php index 58d2f039..4fe13da6 100644 --- a/docs/Examples/Calculations/Database/DMAX.php +++ b/docs/Examples/Calculations/Database/DMAX.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DMIN.php b/docs/Examples/Calculations/Database/DMIN.php index e4fb7658..b765c061 100644 --- a/docs/Examples/Calculations/Database/DMIN.php +++ b/docs/Examples/Calculations/Database/DMIN.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DPRODUCT.php b/docs/Examples/Calculations/Database/DPRODUCT.php index 382227df..4cf234d3 100644 --- a/docs/Examples/Calculations/Database/DPRODUCT.php +++ b/docs/Examples/Calculations/Database/DPRODUCT.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DSTDEV.php b/docs/Examples/Calculations/Database/DSTDEV.php index e1273e5a..8aeaf2d8 100644 --- a/docs/Examples/Calculations/Database/DSTDEV.php +++ b/docs/Examples/Calculations/Database/DSTDEV.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DSTDEVP.php b/docs/Examples/Calculations/Database/DSTDEVP.php index 3af791bb..0a562c65 100644 --- a/docs/Examples/Calculations/Database/DSTDEVP.php +++ b/docs/Examples/Calculations/Database/DSTDEVP.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DVAR.php b/docs/Examples/Calculations/Database/DVAR.php index 44e63994..b49020bf 100644 --- a/docs/Examples/Calculations/Database/DVAR.php +++ b/docs/Examples/Calculations/Database/DVAR.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/Database/DVARP.php b/docs/Examples/Calculations/Database/DVARP.php index c630e731..83d06fba 100644 --- a/docs/Examples/Calculations/Database/DVARP.php +++ b/docs/Examples/Calculations/Database/DVARP.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/DateTime/DATE.php b/docs/Examples/Calculations/DateTime/DATE.php index 1af05e3e..5b0a8717 100644 --- a/docs/Examples/Calculations/DateTime/DATE.php +++ b/docs/Examples/Calculations/DateTime/DATE.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/DateTime/DATEVALUE.php b/docs/Examples/Calculations/DateTime/DATEVALUE.php index 42996a4e..437b6aa8 100644 --- a/docs/Examples/Calculations/DateTime/DATEVALUE.php +++ b/docs/Examples/Calculations/DateTime/DATEVALUE.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/DateTime/TIME.php b/docs/Examples/Calculations/DateTime/TIME.php index 9c206304..588eadf9 100644 --- a/docs/Examples/Calculations/DateTime/TIME.php +++ b/docs/Examples/Calculations/DateTime/TIME.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Calculations/DateTime/TIMEVALUE.php b/docs/Examples/Calculations/DateTime/TIMEVALUE.php index c5745cc2..26996b61 100644 --- a/docs/Examples/Calculations/DateTime/TIMEVALUE.php +++ b/docs/Examples/Calculations/DateTime/TIMEVALUE.php @@ -1,5 +1,7 @@ getActiveSheet(); // Add some data diff --git a/docs/Examples/Reader/exampleReader01.php b/docs/Examples/Reader/exampleReader01.php index 9ef1f565..d20207a2 100644 --- a/docs/Examples/Reader/exampleReader01.php +++ b/docs/Examples/Reader/exampleReader01.php @@ -1,5 +1,7 @@

PhpSpreadsheet Reader Example #01

-

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

+

Simple File Reader using IOFactory::load()

'; -$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); +$spreadsheet = IOFactory::load($inputFileName); echo '
'; diff --git a/docs/Examples/Reader/exampleReader02.php b/docs/Examples/Reader/exampleReader02.php index b98b860d..9d301f69 100644 --- a/docs/Examples/Reader/exampleReader02.php +++ b/docs/Examples/Reader/exampleReader02.php @@ -1,5 +1,7 @@ '; -$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls(); +$reader = new Xls(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xml(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods(); diff --git a/docs/Examples/Reader/exampleReader03.php b/docs/Examples/Reader/exampleReader03.php index dbd584b4..07dfa7ae 100644 --- a/docs/Examples/Reader/exampleReader03.php +++ b/docs/Examples/Reader/exampleReader03.php @@ -1,5 +1,7 @@

PhpSpreadsheet Reader Example #03

-

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

+

Simple File Reader using the IOFactory to Return a Reader

'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); $spreadsheet = $reader->load($inputFileName); echo '
'; diff --git a/docs/Examples/Reader/exampleReader04.php b/docs/Examples/Reader/exampleReader04.php index 2267a9df..d26d6525 100644 --- a/docs/Examples/Reader/exampleReader04.php +++ b/docs/Examples/Reader/exampleReader04.php @@ -1,5 +1,7 @@

PhpSpreadsheet Reader Example #04

-

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

+

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

'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with the identified reader type
'; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); $spreadsheet = $reader->load($inputFileName); echo '
'; diff --git a/docs/Examples/Reader/exampleReader05.php b/docs/Examples/Reader/exampleReader05.php index 807e910d..ff72be92 100644 --- a/docs/Examples/Reader/exampleReader05.php +++ b/docs/Examples/Reader/exampleReader05.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo 'Turning Formatting off for Load
'; $reader->setReadDataOnly(true); $spreadsheet = $reader->load($inputFileName); diff --git a/docs/Examples/Reader/exampleReader06.php b/docs/Examples/Reader/exampleReader06.php index 84675c17..ccc59373 100644 --- a/docs/Examples/Reader/exampleReader06.php +++ b/docs/Examples/Reader/exampleReader06.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo 'Loading all WorkSheets
'; $reader->setLoadAllSheets(); $spreadsheet = $reader->load($inputFileName); diff --git a/docs/Examples/Reader/exampleReader07.php b/docs/Examples/Reader/exampleReader07.php index 0463f37b..cde1c409 100644 --- a/docs/Examples/Reader/exampleReader07.php +++ b/docs/Examples/Reader/exampleReader07.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo 'Loading Sheet "',$sheetname,'" only
'; $reader->setLoadSheetsOnly($sheetname); $spreadsheet = $reader->load($inputFileName); diff --git a/docs/Examples/Reader/exampleReader08.php b/docs/Examples/Reader/exampleReader08.php index c5e9b39d..0a739f75 100644 --- a/docs/Examples/Reader/exampleReader08.php +++ b/docs/Examples/Reader/exampleReader08.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only
'; $reader->setLoadSheetsOnly($sheetnames); $spreadsheet = $reader->load($inputFileName); diff --git a/docs/Examples/Reader/exampleReader09.php b/docs/Examples/Reader/exampleReader09.php index e2464447..8dde497c 100644 --- a/docs/Examples/Reader/exampleReader09.php +++ b/docs/Examples/Reader/exampleReader09.php @@ -1,5 +1,8 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo 'Loading Sheet "',$sheetname,'" only
'; $reader->setLoadSheetsOnly($sheetname); echo 'Loading Sheet using filter
'; diff --git a/docs/Examples/Reader/exampleReader10.php b/docs/Examples/Reader/exampleReader10.php index 965a1bb2..f62c98d93 100644 --- a/docs/Examples/Reader/exampleReader10.php +++ b/docs/Examples/Reader/exampleReader10.php @@ -1,5 +1,8 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo 'Loading Sheet "',$sheetname,'" only
'; $reader->setLoadSheetsOnly($sheetname); echo 'Loading Sheet using configurable filter
'; diff --git a/docs/Examples/Reader/exampleReader11.php b/docs/Examples/Reader/exampleReader11.php index 5435629a..2b7225a9 100644 --- a/docs/Examples/Reader/exampleReader11.php +++ b/docs/Examples/Reader/exampleReader11.php @@ -1,5 +1,8 @@ '; /* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo '
'; diff --git a/docs/Examples/Reader/exampleReader12.php b/docs/Examples/Reader/exampleReader12.php index 673b2f14..50580f2a 100644 --- a/docs/Examples/Reader/exampleReader12.php +++ b/docs/Examples/Reader/exampleReader12.php @@ -1,5 +1,8 @@ '; /* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo '
'; diff --git a/docs/Examples/Reader/exampleReader13.php b/docs/Examples/Reader/exampleReader13.php index 9977a83c..c5107c87 100644 --- a/docs/Examples/Reader/exampleReader13.php +++ b/docs/Examples/Reader/exampleReader13.php @@ -1,5 +1,7 @@ '; $spreadsheet = $reader->load($inputFileName); diff --git a/docs/Examples/Reader/exampleReader14.php b/docs/Examples/Reader/exampleReader14.php index 933be4ac..aad066dc 100644 --- a/docs/Examples/Reader/exampleReader14.php +++ b/docs/Examples/Reader/exampleReader14.php @@ -1,5 +1,9 @@ '; /* Create a new Reader of the type defined in $inputFileType **/ -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); echo '
'; @@ -71,7 +75,7 @@ $reader->setReadFilter($chunkFilter) ->setContiguous(true); /* Instantiate a new PhpSpreadsheet object manually **/ -$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); +$spreadsheet = new Spreadsheet(); /* Set a sheet index **/ $sheet = 0; diff --git a/docs/Examples/Reader/exampleReader15.php b/docs/Examples/Reader/exampleReader15.php index a04a1adc..fdf38b05 100644 --- a/docs/Examples/Reader/exampleReader15.php +++ b/docs/Examples/Reader/exampleReader15.php @@ -1,5 +1,8 @@ '; $reader->setDelimiter("\t"); $spreadsheet = $reader->load($inputFileName); diff --git a/docs/Examples/Reader/exampleReader16.php b/docs/Examples/Reader/exampleReader16.php index 6e6a7583..9436bd2e 100644 --- a/docs/Examples/Reader/exampleReader16.php +++ b/docs/Examples/Reader/exampleReader16.php @@ -1,5 +1,8 @@ '; try { - $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); -} catch (\InvalidArgumentException $e) { + $spreadsheet = IOFactory::load($inputFileName); +} catch (InvalidArgumentException $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } diff --git a/docs/Examples/Reader/exampleReader17.php b/docs/Examples/Reader/exampleReader17.php index f76994e9..763805ac 100644 --- a/docs/Examples/Reader/exampleReader17.php +++ b/docs/Examples/Reader/exampleReader17.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); /* Read the list of Worksheet Names from the Workbook file **/ echo 'Read the list of Worksheets in the WorkBook
'; diff --git a/docs/Examples/Reader/exampleReader18.php b/docs/Examples/Reader/exampleReader18.php index 6688e481..9822b209 100644 --- a/docs/Examples/Reader/exampleReader18.php +++ b/docs/Examples/Reader/exampleReader18.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); $worksheetNames = $reader->listWorksheetNames($inputFileName); echo '

Worksheet Names

'; diff --git a/docs/Examples/Reader/exampleReader19.php b/docs/Examples/Reader/exampleReader19.php index 5ad3e5ba..5749d1b6 100644 --- a/docs/Examples/Reader/exampleReader19.php +++ b/docs/Examples/Reader/exampleReader19.php @@ -1,5 +1,7 @@ '; -$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); +$reader = IOFactory::createReader($inputFileType); $worksheetData = $reader->listWorksheetInfo($inputFileName); echo '

Worksheet Information

'; diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php index aa9bddd7..8a6b4726 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader01.php @@ -1,5 +1,7 @@ load($inputFileName); diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php index c021728c..b9cfc196 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader02.php @@ -1,5 +1,7 @@ load($inputFileName); diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php index c02f51bd..81327481 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader03.php @@ -1,5 +1,7 @@ load($inputFileName); diff --git a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php index 88c7f9e0..e3a71d34 100644 --- a/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php +++ b/docs/Examples/Reading WorkBook Data/exampleWorkBookReader04.php @@ -1,5 +1,7 @@ load($inputFileName); 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..ea4cd804 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, + 'type' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFCCFFCC'], ], 'borders' => [ - 'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], - 'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], + 'bottom' => ['style' => Border::BORDER_THIN], + 'right' => ['style' => Border::BORDER_MEDIUM], ], ] ); $spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray( ['fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, + 'type' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFFFFF00'], ], ] diff --git a/samples/23_Sharedstyles.php b/samples/23_Sharedstyles.php index 48ffb1ad..74e3d8d6 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, + 'type' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFCCFFCC'], ], 'borders' => [ - 'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], - 'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], + 'bottom' => ['style' => Border::BORDER_THIN], + 'right' => ['style' => Border::BORDER_MEDIUM], ], ] ); $sharedStyle2->applyFromArray( ['fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, + 'type' => Fill::FILL_SOLID, 'color' => ['argb' => 'FFFFFF00'], ], 'borders' => [ - 'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], - 'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], + 'bottom' => ['style' => Border::BORDER_THIN], + 'right' => ['style' => 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..76a9f478 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..af9fb542 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..12903ea6 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..8ea8d791 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('String', 'Worksheet!$C$1', null, 1), // 'Budget' + new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 'Forecast' + new DataSeriesValues('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('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('Number', 'Worksheet!$C$2:$C$13', null, 12), + new DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), + new DataSeriesValues('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..d050a3e9 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('String', 'Worksheet!$B$1', null, 1), // Temperature ]; $dataSeriesLabels2 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // Rainfall + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // Rainfall ]; $dataSeriesLabels3 = [ - new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // Humidity + new DataSeriesValues('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('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('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('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('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..b2d6e4f3 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..fe20b76d 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..895e0429 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('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('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('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('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('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('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..df81f38c 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('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec + new DataSeriesValues('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('Number', 'Worksheet!$C$2:$C$13', null, 12), + new DataSeriesValues('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..df5564d7 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..78d16e3f 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('String', 'Worksheet!$B$1', null, 1), //Max / Open + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), //Min / Close + new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), //Min Threshold / Min + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$6', null, 5), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$6', null, 5), + new DataSeriesValues('Number', 'Worksheet!$D$2:$D$6', null, 5), + new DataSeriesValues('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/Header.php b/samples/Header.php index b406ba1b..e9ada9f7 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 : '
'); } diff --git a/samples/templates/chartSpreadsheet.php b/samples/templates/chartSpreadsheet.php index f6fb8b00..c462f533 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('String', 'Worksheet!$B$1', null, 1), // 2010 + new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 + new DataSeriesValues('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('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('Number', 'Worksheet!$B$2:$B$5', null, 4), + new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), + new DataSeriesValues('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..0ab6ebc1 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, + 'style' => 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, + 'style' => 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,15 +188,15 @@ $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, + 'style' => Border::BORDER_THIN, ], ], 'fill' => [ - 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR, + 'type' => Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, 'startcolor' => [ 'argb' => 'FFA0A0A0', @@ -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, + 'style' => 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, + 'style' => 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 46414a4a..684070ab 100644 --- a/src/PhpSpreadsheet/Calculation.php +++ b/src/PhpSpreadsheet/Calculation.php @@ -2066,7 +2066,7 @@ class Calculation } if (!isset(self::$instance) || (self::$instance === null)) { - self::$instance = new \PhpOffice\PhpSpreadsheet\Calculation(); + self::$instance = new self(); } return self::$instance; @@ -2084,7 +2084,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() { 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..d8a1d000 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) { @@ -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'); } @@ -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/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..305494be 100644 --- a/src/PhpSpreadsheet/Calculation/Financial.php +++ b/src/PhpSpreadsheet/Calculation/Financial.php @@ -3,6 +3,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; /* FINANCIAL_MAX_ITERATIONS */ +use PhpOffice\PhpSpreadsheet\Shared\Date; + define('FINANCIAL_MAX_ITERATIONS', 128); /* FINANCIAL_PRECISION */ @@ -64,10 +66,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 +80,7 @@ class Financial $result->modify('-1 day'); } - return \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($result); + return Date::PHPToExcel($result); } private static function isValidFrequency($frequency) diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index 88346ed0..b13e987d 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -3,6 +3,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; /* MAX_VALUE */ +use PhpOffice\PhpSpreadsheet\Calculation; + define('MAX_VALUE', 1.2e308); /* 2 / PI */ @@ -298,7 +300,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 +310,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..5492cc6e 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. * @@ -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..010aea93 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; @@ -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 6ea7ba66..25200205 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. * @@ -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(); } } @@ -1231,11 +1235,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]; } @@ -1280,10 +1284,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]; } diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 2f743e70..b379b1ba 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -3,6 +3,9 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; /* LOG_GAMMA_X_MAX_VALUE */ +use PhpOffice\PhpSpreadsheet\Calculation; +use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend; + define('LOG_GAMMA_X_MAX_VALUE', 2.55e305); /* XMININ */ @@ -883,10 +886,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; @@ -1194,7 +1197,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(); } @@ -1317,10 +1320,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 +1358,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(); } @@ -1649,7 +1652,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); } @@ -1829,7 +1832,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(); } @@ -1956,7 +1959,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(); } @@ -2084,7 +2087,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 +2156,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 [ [ @@ -2347,10 +2350,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; } @@ -2510,10 +2513,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; } @@ -3005,7 +3008,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(); } @@ -3075,7 +3078,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(); } @@ -3379,7 +3382,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(); } @@ -3530,7 +3533,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(); } 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/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..4fee7c28 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. * @@ -111,9 +116,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 @@ -277,17 +282,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 +300,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 +313,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..a968a931 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,7 +675,7 @@ 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); 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..313fcf00 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']); @@ -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,45 +484,45 @@ 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']; // 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; } @@ -528,64 +540,64 @@ class Gnumeric extends BaseReader implements IReader $styleArray['fill']['endcolor']['rgb'] = $RGB2; switch ($shade) { case '1': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID; + $styleArray['fill']['type'] = Fill::FILL_SOLID; break; case '2': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR; + $styleArray['fill']['type'] = Fill::FILL_GRADIENT_LINEAR; break; case '3': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_PATH; + $styleArray['fill']['type'] = Fill::FILL_GRADIENT_PATH; break; case '4': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKDOWN; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKDOWN; break; case '5': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRAY; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKGRAY; break; case '6': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKGRID; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKGRID; break; case '7': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKHORIZONTAL; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKHORIZONTAL; break; case '8': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKTRELLIS; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKTRELLIS; break; case '9': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKUP; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKUP; break; case '10': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_DARKVERTICAL; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_DARKVERTICAL; break; case '11': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY0625; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_GRAY0625; break; case '12': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_GRAY125; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_GRAY125; break; case '13': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTDOWN; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTDOWN; break; case '14': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRAY; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTGRAY; break; case '15': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTGRID; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTGRID; break; case '16': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTHORIZONTAL; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTHORIZONTAL; break; case '17': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTTRELLIS; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTTRELLIS; break; case '18': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTUP; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTUP; break; case '19': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_LIGHTVERTICAL; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_LIGHTVERTICAL; break; case '20': - $styleArray['fill']['type'] = \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_PATTERN_MEDIUMGRAY; + $styleArray['fill']['type'] = Fill::FILL_PATTERN_MEDIUMGRAY; break; } } @@ -598,19 +610,19 @@ class Gnumeric extends BaseReader implements IReader $styleArray['font']['strike'] = ($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']) { @@ -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['style'] = Border::BORDER_NONE; break; case '1': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleArray['style'] = Border::BORDER_THIN; break; case '2': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM; + $styleArray['style'] = Border::BORDER_MEDIUM; break; case '3': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_SLANTDASHDOT; + $styleArray['style'] = Border::BORDER_SLANTDASHDOT; break; case '4': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHED; + $styleArray['style'] = Border::BORDER_DASHED; break; case '5': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK; + $styleArray['style'] = Border::BORDER_THICK; break; case '6': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE; + $styleArray['style'] = Border::BORDER_DOUBLE; break; case '7': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOTTED; + $styleArray['style'] = Border::BORDER_DOTTED; break; case '8': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHED; + $styleArray['style'] = Border::BORDER_MEDIUMDASHED; break; case '9': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT; + $styleArray['style'] = Border::BORDER_DASHDOT; break; case '10': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOT; + $styleArray['style'] = Border::BORDER_MEDIUMDASHDOT; break; case '11': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOTDOT; + $styleArray['style'] = Border::BORDER_DASHDOTDOT; break; case '12': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT; + $styleArray['style'] = Border::BORDER_MEDIUMDASHDOTDOT; break; case '13': - $styleArray['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUMDASHDOTDOT; + $styleArray['style'] = 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..4db753b5 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, + 'style' => 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) { @@ -450,7 +455,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 +463,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 +479,7 @@ class Html extends BaseReader implements IReader $sheet->getStyle($column . $row)->applyFromArray( [ 'fill' => [ - 'type' => PHPExcel_Style_Fill::FILL_SOLID, + 'type' => Fill::FILL_SOLID, 'color' => ['rgb' => $attributeArray['bgcolor']], ], ] diff --git a/src/PhpSpreadsheet/Reader/IReader.php b/src/PhpSpreadsheet/Reader/IReader.php index 7ef8d48b..3d4bfa99 100644 --- a/src/PhpSpreadsheet/Reader/IReader.php +++ b/src/PhpSpreadsheet/Reader/IReader.php @@ -42,7 +42,7 @@ interface IReader * * @throws Exception * - * @return \PhpOffice\PhpSpreadsheet\Spreadsheet + * @return Spreadsheet */ public function load($pFilename); } diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index 13f48ea4..e82d2d4e 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'); @@ -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; @@ -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..5a0950a6 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 (;;) @@ -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']['style'] = Border::BORDER_THIN; break; case 'B': - $formatArray['borders']['bottom']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['bottom']['style'] = Border::BORDER_THIN; break; case 'L': - $formatArray['borders']['left']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['left']['style'] = Border::BORDER_THIN; break; case 'R': - $formatArray['borders']['right']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $formatArray['borders']['right']['style'] = 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']['style'] = Border::BORDER_THIN; break; case 'B': - $styleData['borders']['bottom']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['bottom']['style'] = Border::BORDER_THIN; break; case 'L': - $styleData['borders']['left']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['left']['style'] = Border::BORDER_THIN; break; case 'R': - $styleData['borders']['right']['style'] = \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN; + $styleData['borders']['right']['style'] = 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..a7fe48e4 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; } } @@ -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 @@ -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); } @@ -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 @@ -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); @@ -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); @@ -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); } @@ -1861,7 +1885,7 @@ class Xls extends BaseReader implements IReader // offset: 0; size: 2; code page identifier $codepage = self::getInt2d($recordData, 0); - $this->codepage = \PhpOffice\PhpSpreadsheet\Shared\CodePage::numberToName($codepage); + $this->codepage = CodePage::numberToName($codepage); } /** @@ -1885,9 +1909,9 @@ class Xls extends BaseReader implements IReader $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); } } @@ -1903,7 +1927,7 @@ class Xls extends BaseReader implements IReader $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); @@ -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; } @@ -2040,7 +2064,7 @@ class Xls extends BaseReader implements IReader // 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 @@ -2058,7 +2082,7 @@ class Xls extends BaseReader implements IReader 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)) !== '') { + } elseif (($code = NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') { // then we have built-in format code $numberformat = ['code' => $code]; } else { @@ -2072,11 +2096,11 @@ class Xls extends BaseReader implements IReader $xfTypeProt = self::getInt2d($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; @@ -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; } @@ -2768,7 +2792,7 @@ class Xls extends BaseReader implements IReader try { $formula = $this->getFormulaFromStructure($formulaStructure); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { $formula = ''; } @@ -3064,7 +3088,7 @@ class Xls extends BaseReader implements IReader $cl = self::getInt2d($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); } } } @@ -3091,7 +3115,7 @@ class Xls extends BaseReader implements IReader $rl = self::getInt2d($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); } } } @@ -3292,10 +3316,10 @@ class Xls extends BaseReader implements IReader $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; } @@ -3562,7 +3586,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size: 2; index to column $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { @@ -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); } } @@ -3606,7 +3630,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size: 2; index to column $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $columnString = Cell::stringFromColumnIndex($column); $emptyCell = true; // Read cell? @@ -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; } } @@ -3699,7 +3723,7 @@ class Xls extends BaseReader implements IReader $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())) { @@ -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; @@ -3743,7 +3767,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size 2; index to column $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { @@ -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); } } @@ -3784,7 +3808,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size: 2; col index $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $columnString = Cell::stringFromColumnIndex($column); // offset: 20: size: variable; formula structure $formulaStructure = substr($recordData, 20); @@ -3808,7 +3832,7 @@ class Xls extends BaseReader implements IReader // 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); + $this->_baseCell = Cell::stringFromColumnIndex($baseCol) . ($baseRow + 1); } // Read cell? @@ -3826,7 +3850,7 @@ class Xls extends BaseReader implements IReader // 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); @@ -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 { @@ -3968,7 +3992,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size: 2; column index $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { @@ -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; } @@ -4030,7 +4054,7 @@ class Xls extends BaseReader implements IReader // 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())) { @@ -4066,7 +4090,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size: 2; index to column $column = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($column); + $columnString = Cell::stringFromColumnIndex($column); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { @@ -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 @@ -4110,7 +4134,7 @@ class Xls extends BaseReader implements IReader // offset: 2; size: 2; col index $col = self::getInt2d($recordData, 2); - $columnString = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($col); + $columnString = Cell::stringFromColumnIndex($col); // Read cell? if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { @@ -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; @@ -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. @@ -4327,7 +4351,7 @@ class Xls extends BaseReader implements IReader 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 } @@ -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) { @@ -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; } @@ -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); } } @@ -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; } @@ -4755,10 +4779,10 @@ 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; @@ -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); @@ -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; @@ -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; @@ -6624,7 +6648,7 @@ class Xls extends BaseReader implements IReader $cellAddress = $this->readBIFF8CellAddress(substr($formulaData, 3, 4)); $data = "$sheetRange!$cellAddress"; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { // deleted sheet reference $data = '#REF!'; } @@ -6642,7 +6666,7 @@ class Xls extends BaseReader implements IReader $cellRangeAddress = $this->readBIFF8CellRangeAddress(substr($formulaData, 3, 8)); $data = "$sheetRange!$cellRangeAddress"; - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (PhpSpreadsheetException $e) { // deleted sheet reference $data = '#REF!'; } @@ -6676,7 +6700,7 @@ class Xls extends BaseReader implements IReader // 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::getInt2d($cellAddressStructure, 2)); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) if (!(0x4000 & self::getInt2d($cellAddressStructure, 2))) { @@ -6702,8 +6726,8 @@ 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); @@ -6715,11 +6739,11 @@ class Xls extends BaseReader implements IReader // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) if (!(0x4000 & self::getInt2d($cellAddressStructure, 2))) { - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($colIndex); + $column = Cell::stringFromColumnIndex($colIndex); $column = '$' . $column; } else { $colIndex = ($colIndex <= 127) ? $colIndex : $colIndex - 256; - $column = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $colIndex); + $column = Cell::stringFromColumnIndex($baseCol + $colIndex); } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) @@ -6764,8 +6788,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"; @@ -6805,8 +6829,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"; @@ -6838,7 +6862,7 @@ class Xls extends BaseReader implements IReader // 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::getInt2d($subData, 4)); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) if (!(0x4000 & self::getInt2d($subData, 4))) { @@ -6853,7 +6877,7 @@ class Xls extends BaseReader implements IReader // 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::getInt2d($subData, 6)); // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) if (!(0x4000 & self::getInt2d($subData, 6))) { @@ -6880,8 +6904,8 @@ 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' ? @@ -6900,12 +6924,12 @@ class Xls extends BaseReader implements IReader // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) if (!(0x4000 & self::getInt2d($subData, 4))) { // absolute column index - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($fcIndex); + $fc = Cell::stringFromColumnIndex($fcIndex); $fc = '$' . $fc; } else { // column offset $fcIndex = ($fcIndex <= 127) ? $fcIndex : $fcIndex - 256; - $fc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $fcIndex); + $fc = Cell::stringFromColumnIndex($baseCol + $fcIndex); } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) @@ -6924,17 +6948,17 @@ class Xls extends BaseReader implements IReader // 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))) { // absolute column index - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($lcIndex); + $lc = Cell::stringFromColumnIndex($lcIndex); $lc = '$' . $lc; } else { // column offset $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256; - $lc = \PhpOffice\PhpSpreadsheet\Cell::stringFromColumnIndex($baseCol + $lcIndex); + $lc = Cell::stringFromColumnIndex($baseCol + $lcIndex); } // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) @@ -7395,7 +7419,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 +7449,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); } /** @@ -7467,7 +7491,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..270272c6 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::getInt2d($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::getInt2d($this->data, $this->pos); // offset: 2; size: 2: Record Type - $fbt = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($this->data, $this->pos + 2); + $fbt = Xls::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($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::getInt2d($recordData, 4); // offset: 6; size: 2; upper-left corner row index (0-based) - $r1 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 6); + $r1 = Xls::getInt2d($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::getInt2d($recordData, 8); // offset: 10; size: 2; bottom-right corner column index (0-based) - $c2 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 10); + $c2 = Xls::getInt2d($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::getInt2d($recordData, 12); // offset: 14; size: 2; bottom-right corner row index (0-based) - $r2 = \PhpOffice\PhpSpreadsheet\Reader\Xls::getInt2d($recordData, 14); + $r2 = Xls::getInt2d($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::getInt2d($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::getInt2d($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..3d39016d 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; } } diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Chart.php b/src/PhpSpreadsheet/Reader/Xlsx/Chart.php index 48564d6d..2e6c1d84 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,7 +307,7 @@ 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) @@ -306,24 +316,24 @@ class Chart $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('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); } 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('Number', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); } 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('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); } 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('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); } 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'); @@ -444,11 +454,11 @@ class Chart $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..d7aff065 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; } @@ -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['style'] = Border::BORDER_MEDIUM; break; case 'Weight': break; @@ -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..99c27711 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(JAMAError(MatrixSPDException)); } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MATRIX_DIMENSION_EXCEPTION)); + throw new CalculationException(JAMAError(MATRIX_DIMENSION_EXCEPTION)); } } 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..e9ec3d06 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.'; @@ -86,15 +90,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 +171,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 +193,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 +215,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 +237,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 +259,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 +276,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 +299,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 +380,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 +402,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 +474,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 +493,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -511,14 +515,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 +532,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 +570,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 +589,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -607,14 +611,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 +628,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 +667,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 +686,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -705,14 +709,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 +726,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 +765,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 +782,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 +796,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 +826,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 +845,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -864,14 +868,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 +887,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -906,14 +910,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 +929,7 @@ class Matrix return $M; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION); + throw new CalculationException(self::POLYMORPHIC_ARGUMENT_EXCEPTION); } /** @@ -947,7 +951,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 +971,7 @@ class Matrix return $C; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MatrixDimensionMismatch)); + throw new CalculationException(JAMAError(MatrixDimensionMismatch)); case 'array': $B = new self($args[0]); if ($this->n == $B->m) { @@ -984,7 +988,7 @@ class Matrix return $C; } - throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(JAMAError(MatrixDimensionMismatch)); + throw new CalculationException(JAMAError(MatrixDimensionMismatch)); case 'integer': $C = new self($this->A); for ($i = 0; $i < $C->m; ++$i) { @@ -1013,10 +1017,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 +1043,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 +1060,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 +1098,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 +1117,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/OLE.php b/src/PhpSpreadsheet/Shared/OLE.php index a2763f72..4f293659 100644 --- a/src/PhpSpreadsheet/Shared/OLE.php +++ b/src/PhpSpreadsheet/Shared/OLE.php @@ -26,6 +26,9 @@ namespace PhpOffice\PhpSpreadsheet\Shared; * OLE_ChainedBlockStream::stream_open(). * @var array */ +use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; +use PhpOffice\PhpSpreadsheet\Shared\OLE\ChainedBlockStream; + $GLOBALS['_OLE_INSTANCES'] = []; /** @@ -101,7 +104,7 @@ class OLE * * @param string $file * - * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception + * @throws ReaderException * * @return bool true on success, PEAR_Error on failure */ @@ -109,18 +112,18 @@ class OLE { $fh = fopen($file, 'r'); if (!$fh) { - throw new \PhpOffice\PhpSpreadsheet\Reader\Exception("Can't open file $file"); + throw new ReaderException("Can't open file $file"); } $this->_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..3c36561e 100644 --- a/src/PhpSpreadsheet/Shared/OLERead.php +++ b/src/PhpSpreadsheet/Shared/OLERead.php @@ -26,6 +26,8 @@ namespace PhpOffice\PhpSpreadsheet\Shared; * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL */ +use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; + defined('IDENTIFIER_OLE') || define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1)); @@ -71,7 +73,7 @@ class OLERead * * @param $pFilename string Filename * - * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception + * @throws ReaderException */ public function read($pFilename) { @@ -83,7 +85,7 @@ class OLERead // 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'); + throw new ReaderException('The filename ' . $pFilename . ' is not recognised as an OLE file'); } // Get the file data @@ -303,10 +305,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..b7e8e568 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. * @@ -588,7 +590,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 +623,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 +656,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 +694,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 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/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/Style.php b/src/PhpSpreadsheet/Style.php index 65902077..8f7f9407 100644 --- a/src/PhpSpreadsheet/Style.php +++ b/src/PhpSpreadsheet/Style.php @@ -184,13 +184,13 @@ class Style extends Style\Supervisor implements IComparable * ), * 'borders' => array( * 'bottom' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'style' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) * ), * 'top' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'style' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) diff --git a/src/PhpSpreadsheet/Style/Alignment.php b/src/PhpSpreadsheet/Style/Alignment.php index 6ee25160..6ea74462 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'; @@ -144,7 +147,6 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray( * array( @@ -154,11 +156,11 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara * 'wrap' => TRUE * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Alignment */ @@ -287,7 +289,7 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara * * @param int $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Alignment */ @@ -307,7 +309,7 @@ class Alignment extends Supervisor implements \PhpOffice\PhpSpreadsheet\ICompara $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; diff --git a/src/PhpSpreadsheet/Style/Border.php b/src/PhpSpreadsheet/Style/Border.php index 9c2d8891..38246d47 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(); @@ -167,7 +170,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray( * array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'style' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) @@ -177,7 +180,7 @@ class Border extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Border */ @@ -252,7 +255,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..bc599235 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; @@ -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, + * 'style' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) * ), * 'top' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'style' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) @@ -203,18 +205,18 @@ class Borders extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparabl * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( * array( * 'allborders' => array( - * 'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DASHDOT, + * 'style' => Border::BORDER_DASHDOT, * 'color' => array( * 'rgb' => '808080' * ) * ) * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Borders */ @@ -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 */ 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 */ 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; diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index 3fdd6308..ec5e6ffb 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'; @@ -141,14 +144,13 @@ class Color extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable /** * 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..dca4ea8d 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,11 +134,10 @@ 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, + * 'type' => Fill::FILL_GRADIENT_LINEAR, * 'rotation' => 0, * 'startcolor' => array( * 'rgb' => '000000' @@ -145,11 +147,11 @@ class Fill extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * ) * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Fill */ @@ -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..c51a945c 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'; @@ -156,7 +159,6 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->applyFromArray( * array( @@ -170,11 +172,11 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * ) * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Font */ @@ -524,7 +526,7 @@ class Font extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComparable * * @param Color $pValue * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return Font */ diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 779fb2f9..21aaf40e 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'; @@ -140,18 +146,17 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp /** * Apply styles from array. - * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getNumberFormat()->applyFromArray( * array( - * 'code' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE + * 'code' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE * ) * ); - * + * . * * @param array $pStyles Array containing style information * - * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws PhpSpreadsheetException * * @return NumberFormat */ @@ -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); } @@ -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..b2278e7d 100644 --- a/src/PhpSpreadsheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet.php @@ -1657,7 +1657,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 */ diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index a9298433..88042565 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); @@ -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..9f9ad163 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. @@ -210,14 +214,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 +244,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 +483,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..0a08bc0b 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() . '.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,11 +972,11 @@ 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 = ''; @@ -980,11 +996,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 +1020,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 +1033,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 +1052,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 +1073,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 +1089,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 +1124,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 +1153,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 +1173,7 @@ class Html extends BaseWriter implements IWriter /** * Generate table footer. * - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + * @throws WriterException */ private function generateTableFooter() { @@ -1169,16 +1185,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,7 +1233,7 @@ 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; @@ -1239,19 +1255,19 @@ 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()) { @@ -1265,7 +1281,7 @@ class Html extends BaseWriter implements IWriter $cellText = $element->getText(); $cellData .= htmlspecialchars($cellText); - if ($element instanceof \PhpOffice\PhpSpreadsheet\RichText\Run) { + if ($element instanceof RichText\Run) { if ($element->getFont()->getSuperScript()) { $cellData .= ''; } elseif ($element->getFont()->getSubScript()) { @@ -1277,13 +1293,13 @@ 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'] @@ -1321,7 +1337,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 +1364,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(); } @@ -1559,15 +1575,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 +1613,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 +1647,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/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..84b21981 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. * @@ -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); 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..3e02af33 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); @@ -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; @@ -1423,7 +1439,7 @@ class Worksheet extends BIFFwriter { // 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 +1448,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 +1526,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 +1656,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 +1729,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 +1829,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 +1878,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 +1902,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 +2072,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 +2174,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 +2425,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 +2436,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 +2593,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 +2601,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 +2631,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 +2652,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 +2711,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(); @@ -2809,28 +2825,28 @@ class Worksheet extends BIFFwriter // data type $type = $dataValidation->getType(); switch ($type) { - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_NONE: + 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; } @@ -2840,13 +2856,13 @@ class Worksheet extends BIFFwriter // error style $errorStyle = $dataValidation->getErrorStyle(); switch ($errorStyle) { - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP: + 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; } @@ -2873,28 +2889,28 @@ class Worksheet extends BIFFwriter // condition operator $operator = $dataValidation->getOperator(); switch ($operator) { - case \PhpOffice\PhpSpreadsheet\Cell\DataValidation::OPERATOR_BETWEEN: + 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 +2922,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 +2948,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 +2959,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 +3026,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 +3046,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 +3098,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 +3132,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 { @@ -3199,7 +3215,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) { @@ -3458,22 +3474,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 +3499,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 +3534,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 +3718,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 +3767,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 +4187,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 +4236,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..93ea21db 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 @@ -145,7 +165,7 @@ class Xlsx extends BaseWriter implements IWriter // 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..a86b1a88 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) { @@ -1225,9 +1228,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 +1263,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 +1357,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 +1403,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 +1473,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 +1503,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..41092f55 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); @@ -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..8b141e1b 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'); @@ -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..da49970d 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'); @@ -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'); } @@ -444,13 +454,13 @@ class Style extends WriterPart $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..f5bf2bf7 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'; @@ -316,12 +326,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 +339,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 +352,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 +379,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 +396,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 +445,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 +481,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 +498,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 +509,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,12 +555,12 @@ 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(); @@ -612,12 +622,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 +664,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 +694,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 +720,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 +747,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 +781,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) { @@ -790,17 +800,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 +821,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 +862,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 +898,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 +924,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 +949,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 +967,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 +982,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 +997,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 +1005,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 +1026,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 +1069,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 +1116,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 +1126,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 +1151,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 +1185,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 +1206,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 +1224,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..118978f9 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 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..b1b51a59 100644 --- a/tests/PhpSpreadsheetTests/Reader/HTMLTest.php +++ b/tests/PhpSpreadsheetTests/Reader/HTMLTest.php @@ -3,8 +3,9 @@ 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() { 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/StringTest.php index 83643127..9fbaba33 100644 --- a/tests/PhpSpreadsheetTests/Shared/StringTest.php +++ b/tests/PhpSpreadsheetTests/Shared/StringTest.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 StringTest extends PHPUnit_Framework_TestCase { public function setUp() { 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/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/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';