Modified example 2 to use bootstrap

This commit is contained in:
MarkBaker 2015-07-15 22:33:50 +01:00
parent 67dee17d67
commit 88711dc7b9
1 changed files with 91 additions and 58 deletions

View File

@ -34,7 +34,7 @@ date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */ /** Include PHPExcel */
require_once dirname(__FILE__) . '/../classes/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PHPExcel object
@ -43,98 +43,131 @@ $objPHPExcel = new \PHPExcel\Spreadsheet();
// Set document properties // Set document properties
echo date('H:i:s') , " Set document properties" , EOL; echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPHPExcel->getProperties()
->setLastModifiedBy("Maarten Balliauw") ->setCreator("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setLastModifiedBy("Maarten Balliauw")
->setSubject("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setSubject("Office 2007 XLSX Test Document")
->setKeywords("office 2007 openxml php") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setCategory("Test result file"); ->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
// Set default font // Set default font
echo date('H:i:s') , " Set default font" , EOL; echo date('H:i:s') , " Set default font" , EOL;
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial') $objPHPExcel->getDefaultStyle()
->setSize(10); ->getFont()
->setName('Arial')
->setSize(10);
// Add some data, resembling some different data types // Add some data, resembling some different data types
echo date('H:i:s') , " Add some data" , EOL; echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String') $objPHPExcel->getActiveSheet()
->setCellValue('B1', 'Simple') ->setCellValue('A1', 'String')
->setCellValue('C1', 'PHPExcel'); ->setCellValue('B1', 'Simple')
->setCellValue('C1', 'PHPExcel');
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'String') $objPHPExcel->getActiveSheet()
->setCellValue('B2', 'Symbols') ->setCellValue('A2', 'String')
->setCellValue('C2', '!+&=()~§±æþ'); ->setCellValue('B2', 'Symbols')
->setCellValue('C2', '!+&=()~§±æþ');
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'String') $objPHPExcel->getActiveSheet()
->setCellValue('B3', 'UTF-8') ->setCellValue('A3', 'String')
->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов'); ->setCellValue('B3', 'UTF-8')
->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов');
$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number') $objPHPExcel->getActiveSheet()
->setCellValue('B4', 'Integer') ->setCellValue('A4', 'Number')
->setCellValue('C4', 12); ->setCellValue('B4', 'Integer')
->setCellValue('C4', 12);
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number') $objPHPExcel->getActiveSheet()
->setCellValue('B5', 'Float') ->setCellValue('A5', 'Number')
->setCellValue('C5', 34.56); ->setCellValue('B5', 'Float')
->setCellValue('C5', 34.56);
$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number') $objPHPExcel->getActiveSheet()
->setCellValue('B6', 'Negative') ->setCellValue('A6', 'Number')
->setCellValue('C6', -7.89); ->setCellValue('B6', 'Negative')
->setCellValue('C6', -7.89);
$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean') $objPHPExcel->getActiveSheet()
->setCellValue('B7', 'True') ->setCellValue('A7', 'Boolean')
->setCellValue('C7', true); ->setCellValue('B7', 'True')
->setCellValue('C7', true);
$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean') $objPHPExcel->getActiveSheet()
->setCellValue('B8', 'False') ->setCellValue('A8', 'Boolean')
->setCellValue('C8', false); ->setCellValue('B8', 'False')
->setCellValue('C8', false);
$dateTimeNow = time(); $dateTimeNow = time();
$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time') $objPHPExcel->getActiveSheet()
->setCellValue('B9', 'Date') ->setCellValue('A9', 'Date/Time')
->setCellValue('C9', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); ->setCellValue('B9', 'Date')
$objPHPExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); ->setCellValue('C9', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet()
->getStyle('C9')
->getNumberFormat()
->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Date/Time') $objPHPExcel->getActiveSheet()
->setCellValue('B10', 'Time') ->setCellValue('A10', 'Date/Time')
->setCellValue('C10', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); ->setCellValue('B10', 'Time')
$objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4); ->setCellValue('C10', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet()
->getStyle('C10')
->getNumberFormat()
->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_TIME4);
$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Date/Time') $objPHPExcel->getActiveSheet()
->setCellValue('B11', 'Date and Time') ->setCellValue('A11', 'Date/Time')
->setCellValue('C11', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); ->setCellValue('B11', 'Date and Time')
$objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME); ->setCellValue('C11', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet()
->getStyle('C11')
->getNumberFormat()
->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_DATETIME);
$objPHPExcel->getActiveSheet()->setCellValue('A12', 'NULL') $objPHPExcel->getActiveSheet()
->setCellValue('C12', NULL); ->setCellValue('A12', 'NULL')
->setCellValue('C12', NULL);
$objRichText = new PHPExcel_RichText(); $objRichText = new \PHPExcel\RichText();
$objRichText->createText('你好 '); $objRichText->createText('你好 ');
$objPayable = $objRichText->createTextRun('你 好 吗?'); $objPayable = $objRichText->createTextRun('你 好 吗?');
$objPayable->getFont()->setBold(true); $objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true); $objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) ); $objPayable->getFont()->setColor( new \PHPExcel\Style\Color( \PHPExcel\Style\Color::COLOR_DARKGREEN ) );
$objRichText->createText(', unless specified otherwise on the invoice.'); $objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text') $objPHPExcel->getActiveSheet()
->setCellValue('C13', $objRichText); ->setCellValue('A13', 'Rich Text')
->setCellValue('C13', $objRichText);
$objRichText2 = new PHPExcel_RichText(); $objRichText2 = new \PHPExcel\RichText();
$objRichText2->createText("black text\n"); $objRichText2->createText("black text\n");
$objRed = $objRichText2->createTextRun("red text"); $objRed = $objRichText2->createTextRun("red text");
$objRed->getFont()->setColor( new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED ) ); $objRed->getFont()->setColor( new \PHPExcel\Style\Color(\PHPExcel\Style\Color::COLOR_RED ) );
$objPHPExcel->getActiveSheet()->getCell("C14")->setValue($objRichText2); $objPHPExcel->getActiveSheet()
$objPHPExcel->getActiveSheet()->getStyle("C14")->getAlignment()->setWrapText(true); ->getCell("C14")
->setValue($objRichText2);
$objPHPExcel->getActiveSheet()
->getStyle("C14")
->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); $objPHPExcel->getActiveSheet()
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); ->getColumnDimension('B')
->setAutoSize(true);
$objPHPExcel->getActiveSheet()
->getColumnDimension('C')
->setAutoSize(true);
// Rename worksheet // Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL; echo date('H:i:s') , " Rename worksheet" , EOL;