phpword 右缩进

1 位置 PhpOffice\PHPWord\Writer\Word2007\Base.php

2 替换 _writeParagraphStyle  方法
protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Paragraph $style, $withoutPPR = false) {
       $indent = isset($style->_indent)?$style->_indent:null;
       $align = $style->getAlign();
   $spaceBefore = $style->getSpaceBefore();
   $spaceAfter = $style->getSpaceAfter();
   $spacing = $style->getSpacing();


   if($indent||!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter)) {
      
           if(!$withoutPPR) {
               $objWriter->startElement('w:pPr');
           }
      
      if(!is_null($align)) {
         $objWriter->startElement('w:jc');
            $objWriter->writeAttribute('w:val', $align);
         $objWriter->endElement();
      }
           //yuhy 右侧缩进  案号
           if($indent) {
               $objWriter->startElement('w:ind');
               $objWriter->writeAttribute('w:right', $indent);
               //$objWriter->writeAttribute('w:firstLineChars',$indent);
               $objWriter->endElement();
           }
      if(!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) {
         
         $objWriter->startElement('w:spacing');
         
            if(!is_null($spaceBefore)) {
               $objWriter->writeAttribute('w:before', $spaceBefore);
            }
            if(!is_null($spaceAfter)) {
               $objWriter->writeAttribute('w:after', $spaceAfter);
            }
            if(!is_null($spacing)) {
               $objWriter->writeAttribute('w:line', $spacing);
               $objWriter->writeAttribute('w:lineRule', 'auto');
            }

         $objWriter->endElement();
      }
      
           if(!$withoutPPR) {
          $objWriter->endElement(); // w:pPr
           }
   }
   
}

 

3 样式 加上'indent'=>400  每 200 一个中文长度

$paragraphStyle = ['align' => 'right','indent'=>400,'spacing'=>'95%'];

你可能感兴趣的:(phpword 右缩进)