"Fossies" - the Fresh Open Source Software Archive

Member "groupoffice-6.4.215-php-71/vendor/phpoffice/phpexcel/Examples/02types.php" (22 Nov 2018, 8532 Bytes) of package /linux/www/groupoffice-6.4.215-php-71.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * PHPExcel
    4  *
    5  * Copyright (c) 2006 - 2015 PHPExcel
    6  *
    7  * This library is free software; you can redistribute it and/or
    8  * modify it under the terms of the GNU Lesser General Public
    9  * License as published by the Free Software Foundation; either
   10  * version 2.1 of the License, or (at your option) any later version.
   11  *
   12  * This library is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15  * Lesser General Public License for more details.
   16  *
   17  * You should have received a copy of the GNU Lesser General Public
   18  * License along with this library; if not, write to the Free Software
   19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
   20  *
   21  * @category   PHPExcel
   22  * @package    PHPExcel
   23  * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
   24  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
   25  * @version    ##VERSION##, ##DATE##
   26  */
   27 
   28 /** Error reporting */
   29 error_reporting(E_ALL);
   30 ini_set('display_errors', TRUE); 
   31 ini_set('display_startup_errors', TRUE); 
   32 date_default_timezone_set('Europe/London');
   33 
   34 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
   35 
   36 /** Include PHPExcel */
   37 require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
   38 
   39 
   40 // Create new PHPExcel object
   41 echo date('H:i:s') , " Create new PHPExcel object" , EOL;
   42 $objPHPExcel = new PHPExcel();
   43 
   44 // Set document properties
   45 echo date('H:i:s') , " Set document properties" , EOL;
   46 $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
   47                              ->setLastModifiedBy("Maarten Balliauw")
   48                              ->setTitle("Office 2007 XLSX Test Document")
   49                              ->setSubject("Office 2007 XLSX Test Document")
   50                              ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
   51                              ->setKeywords("office 2007 openxml php")
   52                              ->setCategory("Test result file");
   53 
   54 // Set default font
   55 echo date('H:i:s') , " Set default font" , EOL;
   56 $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')
   57                                           ->setSize(10);
   58 
   59 // Add some data, resembling some different data types
   60 echo date('H:i:s') , " Add some data" , EOL;
   61 $objPHPExcel->getActiveSheet()->setCellValue('A1', 'String')
   62                               ->setCellValue('B1', 'Simple')
   63                               ->setCellValue('C1', 'PHPExcel');
   64 
   65 $objPHPExcel->getActiveSheet()->setCellValue('A2', 'String')
   66                               ->setCellValue('B2', 'Symbols')
   67                               ->setCellValue('C2', '!+&=()~§±æþ');
   68 
   69 $objPHPExcel->getActiveSheet()->setCellValue('A3', 'String')
   70                               ->setCellValue('B3', 'UTF-8')
   71                               ->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов');
   72 
   73 $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number')
   74                               ->setCellValue('B4', 'Integer')
   75                               ->setCellValue('C4', 12);
   76 
   77 $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number')
   78                               ->setCellValue('B5', 'Float')
   79                               ->setCellValue('C5', 34.56);
   80 
   81 $objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number')
   82                               ->setCellValue('B6', 'Negative')
   83                               ->setCellValue('C6', -7.89);
   84 
   85 $objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean')
   86                               ->setCellValue('B7', 'True')
   87                               ->setCellValue('C7', true);
   88 
   89 $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean')
   90                               ->setCellValue('B8', 'False')
   91                               ->setCellValue('C8', false);
   92 
   93 $dateTimeNow = time();
   94 $objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time')
   95                               ->setCellValue('B9', 'Date')
   96                               ->setCellValue('C9', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
   97 $objPHPExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
   98 
   99 $objPHPExcel->getActiveSheet()->setCellValue('A10', 'Date/Time')
  100                               ->setCellValue('B10', 'Time')
  101                               ->setCellValue('C10', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
  102 $objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4);
  103 
  104 $objPHPExcel->getActiveSheet()->setCellValue('A11', 'Date/Time')
  105                               ->setCellValue('B11', 'Date and Time')
  106                               ->setCellValue('C11', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
  107 $objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME);
  108 
  109 $objPHPExcel->getActiveSheet()->setCellValue('A12', 'NULL')
  110                               ->setCellValue('C12', NULL);
  111 
  112 $objRichText = new PHPExcel_RichText();
  113 $objRichText->createText('你好 ');
  114 
  115 $objPayable = $objRichText->createTextRun('你 好 吗?');
  116 $objPayable->getFont()->setBold(true);
  117 $objPayable->getFont()->setItalic(true);
  118 $objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );
  119 
  120 $objRichText->createText(', unless specified otherwise on the invoice.');
  121 
  122 $objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text')
  123                               ->setCellValue('C13', $objRichText);
  124 
  125 
  126 $objRichText2 = new PHPExcel_RichText();
  127 $objRichText2->createText("black text\n");
  128 
  129 $objRed = $objRichText2->createTextRun("red text");
  130 $objRed->getFont()->setColor( new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED  ) );
  131 
  132 $objPHPExcel->getActiveSheet()->getCell("C14")->setValue($objRichText2);
  133 $objPHPExcel->getActiveSheet()->getStyle("C14")->getAlignment()->setWrapText(true);
  134 
  135 
  136 $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
  137 $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
  138 
  139 $objRichText3 = new PHPExcel_RichText();
  140 $objRichText3->createText("Hello ");
  141 
  142 $objUnderlined = $objRichText3->createTextRun("underlined");
  143 $objUnderlined->getFont()->setUnderline(true);
  144 $objRichText3->createText(' World.');
  145 
  146 $objPHPExcel->getActiveSheet()
  147     ->getCell("C15")
  148     ->setValue($objRichText3);
  149 
  150 
  151 $objPHPExcel->getActiveSheet()->setCellValue('A17', 'Hyperlink');
  152 
  153 $objPHPExcel->getActiveSheet()->setCellValue('C17', 'www.phpexcel.net');
  154 $objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setUrl('http://www.phpexcel.net');
  155 $objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setTooltip('Navigate to website');
  156 
  157 $objPHPExcel->getActiveSheet()->setCellValue('C18', '=HYPERLINK("mailto:abc@def.com","abc@def.com")');
  158 
  159 
  160 // Rename worksheet
  161 echo date('H:i:s') , " Rename worksheet" , EOL;
  162 $objPHPExcel->getActiveSheet()->setTitle('Datatypes');
  163 
  164 
  165 // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  166 $objPHPExcel->setActiveSheetIndex(0);
  167 
  168 
  169 // Save Excel 2007 file
  170 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
  171 $callStartTime = microtime(true);
  172 
  173 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  174 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  175 $callEndTime = microtime(true);
  176 $callTime = $callEndTime - $callStartTime;
  177 
  178 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  179 echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
  180 // Echo memory usage
  181 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
  182 
  183 
  184 echo date('H:i:s') , " Reload workbook from saved file" , EOL;
  185 $callStartTime = microtime(true);
  186 
  187 $objPHPExcel = PHPExcel_IOFactory::load(str_replace('.php', '.xlsx', __FILE__));
  188 
  189 $callEndTime = microtime(true);
  190 $callTime = $callEndTime - $callStartTime;
  191 echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
  192 // Echo memory usage
  193 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
  194 
  195 
  196 var_dump($objPHPExcel->getActiveSheet()->toArray());
  197 
  198 
  199 // Echo memory peak usage
  200 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
  201 
  202 // Echo done
  203 echo date('H:i:s') , " Done testing file" , EOL;
  204 echo 'File has been created in ' , getcwd() , EOL;