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 />');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/../classes/Bootstrap.php';
require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object
@ -43,7 +43,8 @@ $objPHPExcel = new \PHPExcel\Spreadsheet();
// Set document properties
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
$objPHPExcel->getProperties()
->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
@ -53,88 +54,120 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Set default font
echo date('H:i:s') , " Set default font" , EOL;
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')
$objPHPExcel->getDefaultStyle()
->getFont()
->setName('Arial')
->setSize(10);
// Add some data, resembling some different data types
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String')
$objPHPExcel->getActiveSheet()
->setCellValue('A1', 'String')
->setCellValue('B1', 'Simple')
->setCellValue('C1', 'PHPExcel');
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'String')
$objPHPExcel->getActiveSheet()
->setCellValue('A2', 'String')
->setCellValue('B2', 'Symbols')
->setCellValue('C2', '!+&=()~§±æþ');
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'String')
$objPHPExcel->getActiveSheet()
->setCellValue('A3', 'String')
->setCellValue('B3', 'UTF-8')
->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов');
$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number')
$objPHPExcel->getActiveSheet()
->setCellValue('A4', 'Number')
->setCellValue('B4', 'Integer')
->setCellValue('C4', 12);
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number')
$objPHPExcel->getActiveSheet()
->setCellValue('A5', 'Number')
->setCellValue('B5', 'Float')
->setCellValue('C5', 34.56);
$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number')
$objPHPExcel->getActiveSheet()
->setCellValue('A6', 'Number')
->setCellValue('B6', 'Negative')
->setCellValue('C6', -7.89);
$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean')
$objPHPExcel->getActiveSheet()
->setCellValue('A7', 'Boolean')
->setCellValue('B7', 'True')
->setCellValue('C7', true);
$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean')
$objPHPExcel->getActiveSheet()
->setCellValue('A8', 'Boolean')
->setCellValue('B8', 'False')
->setCellValue('C8', false);
$dateTimeNow = time();
$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time')
$objPHPExcel->getActiveSheet()
->setCellValue('A9', 'Date/Time')
->setCellValue('B9', 'Date')
->setCellValue('C9', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
$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('A10', 'Date/Time')
->setCellValue('B10', 'Time')
->setCellValue('C10', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
$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('A11', 'Date/Time')
->setCellValue('B11', 'Date and Time')
->setCellValue('C11', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
$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('A12', 'NULL')
->setCellValue('C12', NULL);
$objRichText = new PHPExcel_RichText();
$objRichText = new \PHPExcel\RichText();
$objRichText->createText('你好 ');
$objPayable = $objRichText->createTextRun('你 好 吗?');
$objPayable->getFont()->setBold(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.');
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text')
$objPHPExcel->getActiveSheet()
->setCellValue('A13', 'Rich Text')
->setCellValue('C13', $objRichText);
$objRichText2 = new PHPExcel_RichText();
$objRichText2 = new \PHPExcel\RichText();
$objRichText2->createText("black text\n");
$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()->getStyle("C14")->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()
->getCell("C14")
->setValue($objRichText2);
$objPHPExcel->getActiveSheet()
->getStyle("C14")
->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()
->getColumnDimension('B')
->setAutoSize(true);
$objPHPExcel->getActiveSheet()
->getColumnDimension('C')
->setAutoSize(true);
// Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL;