在线报名系统开发 php+mysql程序开发

微信、手机号码:18012098617 QQ:2373311510
当前位置:首页 > 程序详细介绍

php循环生成表格文件到word

发布时间:2021-01-01 浏览次数:

//列出数据
            $sql="SELECT * FROM XXW_BSZN order by BAC001";
            $r = $db_oci->getAll($sql);
            
            $PHPWord = new PHPWord();
            // New portrait section
            $section = $PHPWord->createSection();
            
            foreach($r as $i => $vo){
            
            $PHPWord->addFontStyle('rStyle', array('bold'=>true,'color'=>'000000','size'=>16));
            $PHPWord->addParagraphStyle('pStyle', array('align'=>'center'));
            $section->addText($vo['主事项名称'], 'rStyle', 'pStyle');
            $section->addTextBreak(1);
            
            $section->addText($vo['子事项名称'], 'rStyle', 'pStyle');
            $section->addTextBreak(1);
             
            // Define table style arrays
            $styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80);
             
             
            // Add table style
            $PHPWord->addTableStyle('myOwnTableStyle', $styleTable);
             
            // Add table
            $table = $section->addTable('myOwnTableStyle');
            $fontStyle = array('bold'=>true, 'align'=>'center');
             
            
            // Add more rows / cells
                $table->addRow();
                $table->addCell(2000)->addText("主事项名称",$fontStyle);
                $table->addCell(8000)->addText($vo['主事项名称'],$fontStyle);
                
                $table->addRow();
                $table->addCell(2000)->addText("子事项名称",$fontStyle);
                $table->addCell(8000)->addText($vo['子事项名称'],$fontStyle);
                 
                $table->addRow();
                $table->addCell(2000)->addText("受理对象",$fontStyle);
                $table->addCell(8000)->addText($vo['受理对象'],$fontStyle);
                
                $table->addRow();
                $table->addCell(2000)->addText("申请材料",$fontStyle);
                $table->addCell(8000)->addText($vo['申请材料'],$fontStyle);
                
                $table->addRow();
                $table->addCell(2000)->addText("咨询电话",$fontStyle);
                $table->addCell(8000)->addText($vo['咨询电话'],$fontStyle);
                
                $table->addRow();
                $table->addCell(2000)->addText("投诉电话",$fontStyle);
                $table->addCell(8000)->addText($vo['投诉电话'],$fontStyle);
                
                $table->addRow();
                $table->addCell(2000)->addText("办理地点",$fontStyle);
                $table->addCell(8000)->addText($vo['窗口'],$fontStyle);
                
                $table->addRow();
                $table->addCell(2000)->addText("办理时间",$fontStyle);
                $table->addCell(8000)->addText($vo['办事时间'],$fontStyle);
                
                
                 
                $section->addPageBreak();
            }

            $objWrite = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
            $objWrite->save('index.docx');