zoukankan      html  css  js  c++  java
  • word输出

    <?php
    require_once '../PHPWord.php';
    
    // New Word Document
    $PHPWord = new PHPWord();
    
    // New portrait section
    $section = $PHPWord->createSection();
    
    // Define table style arrays
    $styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80);
    $styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF');
    
    // Define cell style arrays
    $styleCell = array('valign'=>'center');
    $styleCellBTLR = array('valign'=>'center', 'textDirection'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);
    
    // Define font style for first row
    $fontStyle = array('bold'=>true, 'align'=>'center');
    
    // Add table style
    $PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
    
    // Add table
    $table = $section->addTable('myOwnTableStyle');
    
    // Add row
    $table->addRow(900);
    
    // Add cells
    $table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
    $table->addCell(2000, $styleCell)->addText('Row 2', $fontStyle);
    $table->addCell(2000, $styleCell)->addText('Row 3', $fontStyle);
    $table->addCell(2000, $styleCell)->addText('Row 4', $fontStyle);
    $table->addCell(500, $styleCellBTLR)->addText('Row 5', $fontStyle);
    
    // Add more rows / cells
    for($i = 1; $i <= 10; $i++) {
        $table->addRow();
        $table->addCell(2000)->addText("Cell $i");
        $table->addCell(2000)->addText("Cell $i");
        $table->addCell(2000)->addText("Cell $i");
        $table->addCell(2000)->addText("Cell $i");
        
        $text = ($i % 2 == 0) ? '中文中文' : '中文中文中文中文';
        if ($i%2) {
            $table->addCell(500)->addText(mb_convert_encoding($text, 'UTF-8', 'gbk'));
        } else {
            $table->addCell(500)->addImage('_mars.jpg');
        }
    }
    
    
    // Save File
    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
    $objWriter->save('AdvancedTable.docx');
    ?>
  • 相关阅读:
    (转载) Hadoop科普文——常见的45个问题解答
    JSP---设置CooKIe
    JSP---使用HTML完成定时跳转功能
    JSP接受全部请求参数名称及其对应内容
    JSP用户登录程序实现
    jsp连接数据库MySql
    MapReduce程序--成绩统计
    Java中的StringTokenizer类的使用方法
    eclipse hadoop开发环境配置
    解决SDK Manager无法更新问题
  • 原文地址:https://www.cnblogs.com/heyafei/p/6518924.html
Copyright © 2011-2022 走看看