123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
-
- class HomeController extends BaseController {
-
-
-
-
- public function showWelcome()
- {
- try {
- require_once 'PHPWord-0.12.1/src/PhpWord/Autoloader.php';
- \PhpOffice\PhpWord\Autoloader::register();
-
-
- $phpWord = new \PhpOffice\PhpWord\PhpWord();
-
- $styleTable = array('borderColor'=>'006699',
- 'borderSize'=>6,
- 'cellMargin'=>50);
- $styleFirstRow = array('bgColor'=>'66BBFF');
- $phpWord->addTableStyle('myTable', $styleTable, $styleFirstRow);
-
-
-
-
- $section = $phpWord->addSection();
-
- $section->addText(
- htmlspecialchars(
- '"Learn from yesterday, live for today, hope for tomorrow. '
- . 'The important thing is not to stop questioning." '
- . '(Albert Einstein)'
- )
- );
-
- $table = $section->addTable('myTable');
- $table->addRow(3);
- $table->addCell(1200)->addText("Col 1");
- $table->addCell(1200)->addText("Col 2");
- $table->addCell(1200)
- ->addTable('myTable')
- ->addRow(2)->addCell(1200)
- ->addText("Col 1");
-
-
-
-
-
- $section->addText(
- htmlspecialchars(
- '"Great achievement is usually born of great sacrifice, '
- . 'and is never the result of selfishness." '
- . '(Napoleon Hill)'
- ),
- array('name' => 'Tahoma', 'size' => 10)
- );
-
-
-
- $fontStyleName = 'oneUserDefinedStyle';
- $phpWord->addFontStyle(
- $fontStyleName,
- array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
- );
- $section->addText(
- htmlspecialchars(
- '"The greatest accomplishment is not in never falling, '
- . 'but in rising again after you fall." '
- . '(Vince Lombardi)'
- ),
- $fontStyleName
- );
-
-
-
- $fontStyle = new \PhpOffice\PhpWord\Style\Font();
- $fontStyle->setBold(true);
- $fontStyle->setName('Tahoma');
- $fontStyle->setSize(13);
- $myTextElement = $section->addText(
- htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
- );
- $myTextElement->setFontStyle($fontStyle);
-
-
- $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
-
-
- $objWriter->save('helloWorld2.docx');
-
- return Response::download('helloWorld2.docx');
-
- }
- catch(Exception $e)
- {
- }
- }
- }
|