最近一个项目因为要生成doc报告,所以用到了PHPWord这个开源项目,看名字你也许会联想到PHPExcel这个项目,找到PHPWord的确也是通过PHPExcel首页的链接过去的,但是因为现在是beta版的,这个东西绝对比PHPExcel难用的多,当前版本甚至连文本缩进都不支持。下面是通过修改源码形式让其支持文本缩进的一些方法。
1、/PHPWord/Style/Paragraph.php 添加以下属性
/**
* 缩进 indentleft and indentright段落缩进值,单位为twips
*
* 缩进indentFirstLine and indentFirstChars 首行缩进twips数
*
* @var int
*/
private $_indentLeft;
private $_indentRight;
private $_indentFirstLine;
private $_indentFirstLineChars;
// 获取左缩进值
public function getIndentLeft()
{
return $this->_indentLeft;
}
// 设置左缩进值
public function setIndentLeft($pValue = null)
{
$this->_indentLeft = $pValue;
return $this;
}
// 获取右缩进值
public function getIndentRight()
{
return $this->_indentRight;
}