Exemplo n.º 1
0
$queryEj = " select UPPER(Frase) Frase from catejercicio where Ejercicio =  '" . $ano . "'";
$rsEje = $cnx->Execute($queryEj);
$nRowsEj = $rsEje->_numOfRows;
$dataEje = array();
if ($nRowsEj > 0) {
    while (!$rsEje->EOF) {
        array_push($dataEje, array_map('utf8_encode', $rsEje->fields));
        $rsEje->movenext();
    }
    $dataEje = end($dataEje);
}
include_once 'Sample_Header.php';
// New Word document
//echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array('align' => 'both', 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12), 'spacing' => 15, 'name' => 'Tahoma'));
// Sample
$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText(htmlspecialchars($dataEje['Frase']), array('bold' => false), array('space' => array('before' => 600, 'after' => 250), 'align' => 'center'));
$section->addText(htmlspecialchars('203200-' . $dataOfi['PfjOfi'] . '-' . substr($dataOfi['CveOfi'], 2, 4) . '/' . substr($ano, 2, 2)), array('bold' => false), array('space' => array('before' => 80, 'after' => 80), 'align' => 'right'));
$section->addText(htmlspecialchars('Toluca de Lerdo, México;'), array('bold' => false), array('space' => array('before' => 80, 'after' => 80), 'align' => 'right'));
$section->addText(htmlspecialchars($fechaOficio), array('bold' => false), array('space' => array('before' => 80, 'after' => 80), 'align' => 'right'));
$table = $section->addTable('Table');
$table->addRow(300);
$table->addCell(6000, array('valign' => 'center'))->addText(htmlspecialchars('Asunto:'), array('bold' => true), array('align' => 'right'));
$table->addCell(4000, array('valign' => 'center'))->addText(htmlspecialchars(nl2br($dataOfi['AsuOfi'])), array('bold' => false), array('align' => 'right'));
//Acentos
$tit = nl2br($dataOfi['TitOfi']);
$titular = explode("<br />", $tit);
foreach ($titular as $tit) {
    $section = $phpWord->addSection(array('colsNum' => 2, 'colsSpace' => 100, 'breakType' => 'continuous'));
<?php

include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::BOTH, 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12), 'spacing' => 120));
// Sample
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Below are the samples on how to control your paragraph ' . 'pagination. See "Line and Page Break" tab on paragraph properties ' . 'window to see the attribute set by these controls.', ENT_COMPAT, 'UTF-8'), array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
$section->addText(htmlspecialchars('Paragraph with widowControl = false (default: true). ' . 'A "widow" is the last line of a paragraph printed by itself at the top ' . 'of a page. An "orphan" is the first line of a paragraph printed by ' . 'itself at the bottom of a page. Set this option to "false" if you want ' . 'to disable this automatic control.', ENT_COMPAT, 'UTF-8'), null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
$section->addText(htmlspecialchars('Paragraph with keepNext = true (default: false). ' . '"Keep with next" is used to prevent Word from inserting automatic page ' . 'breaks between paragraphs. Set this option to "true" if you do not want ' . 'your paragraph to be separated with the next paragraph.', ENT_COMPAT, 'UTF-8'), null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
$section->addText(htmlspecialchars('Paragraph with keepLines = true (default: false). ' . '"Keep lines together" will prevent Word from inserting an automatic page ' . 'break within a paragraph. Set this option to "true" if you do not want ' . 'all lines of your paragraph to be in the same page.', ENT_COMPAT, 'UTF-8'), null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
$section->addText(htmlspecialchars('Keep scrolling. More below.', ENT_COMPAT, 'UTF-8'));
$section->addText(htmlspecialchars('Paragraph with pageBreakBefore = true (default: false). ' . 'Different with all other control above, "page break before" separates ' . 'your paragraph into the next page. This option is most useful for ' . 'heading styles.', ENT_COMPAT, 'UTF-8'), null, array('pageBreakBefore' => true));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}
<?php

include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array('align' => 'both', 'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(12), 'spacing' => 120));
// Sample
$section = $phpWord->addSection();
$section->addText('Below are the samples on how to control your paragraph ' . 'pagination. See "Line and Page Break" tab on paragraph properties ' . 'window to see the attribute set by these controls.', array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
$section->addText('Paragraph with widowControl = false (default: true). ' . 'A "widow" is the last line of a paragraph printed by itself at the top ' . 'of a page. An "orphan" is the first line of a paragraph printed by ' . 'itself at the bottom of a page. Set this option to "false" if you want ' . 'to disable this automatic control.', null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
$section->addText('Paragraph with keepNext = true (default: false). ' . '"Keep with next" is used to prevent Word from inserting automatic page ' . 'breaks between paragraphs. Set this option to "true" if you do not want ' . 'your paragraph to be separated with the next paragraph.', null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
$section->addText('Paragraph with keepLines = true (default: false). ' . '"Keep lines together" will prevent Word from inserting an automatic page ' . 'break within a paragraph. Set this option to "true" if you do not want ' . 'all lines of your paragraph to be in the same page.', null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
$section->addText('Keep scrolling. More below.');
$section->addText('Paragraph with pageBreakBefore = true (default: false). ' . 'Different with all other control above, "page break before" separates ' . 'your paragraph into the next page. This option is most useful for ' . 'heading styles.', null, array('pageBreakBefore' => true));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}
Exemplo n.º 4
0
 /**
  * just an example
  * */
 public static function Report($cid)
 {
     $m = InvoicePallet::model()->findByAttributes(array('id' => $cid));
     $n = Supplier::model()->findByAttributes(array('number' => $m->supplier_no));
     $i = Pallet::model()->findByAttributes(array('id' => $m->pid));
     spl_autoload_unregister(array('YiiBase', 'autoload'));
     require_once Yii::getPathOfAlias('webroot') . '/assets/phpword/samples/Sample_Header.php';
     spl_autoload_register(array('YiiBase', 'autoload'));
     $phpWord = new \PhpOffice\PhpWord\PhpWord();
     $phpWord->setDefaultFontName('新宋体');
     $phpWord->setDefaultFontSize(12);
     $phpWord->setDefaultParagraphStyle(array('align' => 'both', 'lineHeight' => '2'));
     $section = $phpWord->addSection();
     $section->addText('开票通知', array('bold' => true, 'size' => 24), array('align' => 'center', 'space' => array('before' => 200, 'after' => 100)));
     $section->addText('注意:请收到立即开票!谢谢!', array('bold' => true, 'size' => 20), array('align' => 'center', 'space' => array('before' => 200, 'after' => 200)));
     $section->addText('TO:' . ' ' . $n->name . '        传真:', null, array('align' => 'left'));
     $section->addText('公司名称:拓泓贸易(上海)有限公司', null, array('align' => 'left'));
     $section->addText('纳税人识别号:310112690186868', null, array('align' => 'left'));
     $section->addText('开票地址电话:上海市闵行区元江路5500号D1幢869室(021-54846073)', null, array('align' => 'left'));
     $section->addText('开户行及账号:上海浦东发展银行闵行支行 98280154740006293', null, array('align' => 'left'));
     $section->addTextBreak(1);
     $section->addText('开票资料如下:', array('bold' => true, 'size' => 16), array('align' => 'left'));
     $styleTable = array('borderSize' => 2, 'borderColor' => '686868', 'align' => 'center');
     $styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
     $styleCell = array('valign' => 'center', 'halign' => 'center');
     $fontStyle = array('bold' => false, 'size' => 11, 'borderSize' => 2);
     $center = array('spaceBefore' => 10, 'spaceAfter' => 0, 'align' => 'center', 'valign' => 'center');
     $phpWord->addTableStyle('table1', $styleTable, array('align' => 'center'));
     $table = $section->addTable('table1');
     $table->addRow();
     $table->addCell(1800)->addText('开票品名', $fontStyle, $center);
     $table->addCell(1000)->addText('型号', $fontStyle, $center);
     $table->addCell(800)->addText('数量', $fontStyle, $center);
     $table->addCell(800)->addText('单位', $fontStyle, $center);
     $table->addCell(1000)->addText('单价', $fontStyle, $center);
     $table->addCell(1800)->addText('总价', $fontStyle, $center);
     $table->addCell(2500)->addText('合同号', $fontStyle, $center);
     $table->addRow();
     $table->addCell(1800)->addText($m->type, $fontStyle, $center);
     $table->addCell(1000)->addText($m->model, $fontStyle, $center);
     $table->addCell(800)->addText($m->num, $fontStyle, $center);
     $table->addCell(800)->addText($m->unit, $fontStyle, $center);
     $table->addCell(800)->addText($m->unit_price, $fontStyle, $center);
     $table->addCell(1800)->addText($m->unit_price * $m->num, $fontStyle, $center);
     $table->addCell(2500)->addText($i->purchase_contract_no, $fontStyle, $center);
     $table->addRow();
     $table->addCell(1800)->addText('合计', $fontStyle, $center);
     $table->addCell(1000)->addText('', $fontStyle, $center);
     $table->addCell(800)->addText('', $fontStyle, $center);
     $table->addCell(800)->addText('', $fontStyle, $center);
     $table->addCell(800)->addText('', $fontStyle, $center);
     $table->addCell(1800)->addText('¥' . $m->unit_price * $m->num, $fontStyle, $center);
     $table->addCell(2500)->addText($i->purchase_contract_no, $fontStyle, $center);
     $section->addText('请开票后,全套发票寄至以下地址:', array('bold' => true, 'size' => 12), array('align' => 'left'));
     $section->addText('上海市闵行区曲吴路589号9号楼205', null, array('align' => 'left'));
     $section->addText('拓泓贸易(上海)有限公司', null, array('align' => 'left'));
     $section->addText('电话:021-54846073 	13661561440', null, array('align' => 'left'));
     $section->addText('联系人:叶建伟', null, array('align' => 'left'));
     $section->addText('如有疑问,请今日联系!', null, array('align' => 'left'));
     $section->addText('日期:' . date('Y-m-d'), null, array('align' => 'left'));
     $fileName = "{$n->name}.doc";
     //         $fileName = iconv ( "utf-8", "gb2312", $fileName);
     //         $fileName = mb_convert_encoding($fileName, "utf-8", "auto");
     $absPath = Yii::getPathOfAlias('webroot');
     $relPath = '/uploads/files/';
     $file = $absPath . $relPath . $fileName;
     $fPath = $relPath . $fileName;
     $fName = '开票通知 - ' . date("Ymd");
     $res = array('name' => $fName, 'url' => $fPath);
     write($phpWord, $file, $writers);
     return $res;
 }