如何使用phpword删除addtext函数之间的间距
how to remove spacing inbetween addtext function using phpword
我有以下代码,但我不知道如何删除行 space 或设置自定义行高等。
require_once '/opt/html/paradox/protected/extensions/PHPWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$filename = "Weekly-Report - " . date('d F Y') ;
// adding the necessary font styles
$phpWord->addFontStyle('font_default', array('name'=>'HelveticaNeueLT Std Lt', 'size'=>11, 'color'=>'000000'));
$phpWord->addFontStyle('font_h2', array('name'=>'HelveticaNeueLT Std Med', 'size'=>14, 'color'=>'6D6D6D'));
$phpWord->addFontStyle('font_h3', array('name'=>'HelveticaNeueLT Std Med', 'size'=>12, 'color'=>'949494'));
//adding the necessary header/title styles
$phpWord->addTitleStyle(1, array('name'=>'Cambria (Headings)', 'size'=>16, 'align'=>'center','underline'=>'UNDERLINE_SINGLE')); //h1
//$phpWord->addTitleStyle(2, "font_h2"); //h2
//$phpWord->addTitleStyle(3, "font_h3"); //h3
//adding the necessary paragraph styles
$phpWord->addParagraphStyle('paragraph_default', array('spaceBefore' => 0, 'spaceAfter' => 0));
$paragraphOptions = array(
'spaceBefore' => 0, 'spaceAfter' => 0
);
$fontStyleSubHeading = new \PhpOffice\PhpWord\Style\Font();
$fontStyleSubHeading->setBold(true);
$fontStyleSubHeading->setName('Calibri');
$fontStyleSubHeading->setSize(11);
//############################### STARTING DOCUMENT AND DEFINING STYLES ###############################
/* Note: any element you append to a document must reside inside of a Section. */
$section = $phpWord->addSection();
$section->addTitle(
htmlspecialchars('Weekly Multi-Client Project Status Report '. date('d/M/Y'))
);
//$myTextElement->setFontStyle($fontStyleHeading);
$criteria = new CDbCriteria;
$criteria->select = "PROJECT, PERCENT, ExpectedCompletionDate, PROJINFO";
$criteria->compare('NES',1);
$criteria->addCondition('PERCENT < 100');
$criteria->compare('PROJCODE','W');
$criteria->compare('deleted','0');
$projects = Projects::model()->findAll($criteria);
foreach ($projects as $project) {
$myTextElement = $section->addText(
htmlspecialchars($project->PROJECT . ":")
);
$myTextElement->setFontStyle($fontStyleSubHeading);
// Adding Text element to the Section having font styled by default...
$percent = round($project->PERCENT,2);
$section->addText(
htmlspecialchars('Total % Complete - '.$percent),
$paragraphOptions
);
$section->addText(
htmlspecialchars($project->PROJINFO)
);
$myTextElement = $section->addText(
htmlspecialchars('Action items for SI')
);
$myTextElement->setFontStyle($fontStyleSubHeading);
$section->addText(
htmlspecialchars('None')
);
$myTextElement = $section->addText(
htmlspecialchars('Action items for MC')
);
$myTextElement->setFontStyle($fontStyleSubHeading);
$section->addText(
htmlspecialchars('None')
);
}
它应该是一个标题,每个部分的每个部分应该相隔 spaced,并且其中的所有行都应该没有 spaces。
您错误地为 $section->addText() 函数提供了段落选项。第二个参数是字体样式,即您需要将函数调用更新为:
$section->addText(
htmlspecialchars('Total % Complete - '.$percent),
null,
$paragraphOptions
);
已更新:
要同时使用您的字体样式和段落样式,您可以将它们都作为参数而不是使用 setFontStyle 函数(即,在将样式作为参数时,您根本不需要 $myTextElement 变量需要时):
$fontStyle = array('name' => 'Calibri', 'size' => 11, 'bold' => true);
$section->addText(
htmlspecialchars('Action items for SI'),
$fontStyle,
$paragraphOptions
);
我有以下代码,但我不知道如何删除行 space 或设置自定义行高等。
require_once '/opt/html/paradox/protected/extensions/PHPWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$filename = "Weekly-Report - " . date('d F Y') ;
// adding the necessary font styles
$phpWord->addFontStyle('font_default', array('name'=>'HelveticaNeueLT Std Lt', 'size'=>11, 'color'=>'000000'));
$phpWord->addFontStyle('font_h2', array('name'=>'HelveticaNeueLT Std Med', 'size'=>14, 'color'=>'6D6D6D'));
$phpWord->addFontStyle('font_h3', array('name'=>'HelveticaNeueLT Std Med', 'size'=>12, 'color'=>'949494'));
//adding the necessary header/title styles
$phpWord->addTitleStyle(1, array('name'=>'Cambria (Headings)', 'size'=>16, 'align'=>'center','underline'=>'UNDERLINE_SINGLE')); //h1
//$phpWord->addTitleStyle(2, "font_h2"); //h2
//$phpWord->addTitleStyle(3, "font_h3"); //h3
//adding the necessary paragraph styles
$phpWord->addParagraphStyle('paragraph_default', array('spaceBefore' => 0, 'spaceAfter' => 0));
$paragraphOptions = array(
'spaceBefore' => 0, 'spaceAfter' => 0
);
$fontStyleSubHeading = new \PhpOffice\PhpWord\Style\Font();
$fontStyleSubHeading->setBold(true);
$fontStyleSubHeading->setName('Calibri');
$fontStyleSubHeading->setSize(11);
//############################### STARTING DOCUMENT AND DEFINING STYLES ###############################
/* Note: any element you append to a document must reside inside of a Section. */
$section = $phpWord->addSection();
$section->addTitle(
htmlspecialchars('Weekly Multi-Client Project Status Report '. date('d/M/Y'))
);
//$myTextElement->setFontStyle($fontStyleHeading);
$criteria = new CDbCriteria;
$criteria->select = "PROJECT, PERCENT, ExpectedCompletionDate, PROJINFO";
$criteria->compare('NES',1);
$criteria->addCondition('PERCENT < 100');
$criteria->compare('PROJCODE','W');
$criteria->compare('deleted','0');
$projects = Projects::model()->findAll($criteria);
foreach ($projects as $project) {
$myTextElement = $section->addText(
htmlspecialchars($project->PROJECT . ":")
);
$myTextElement->setFontStyle($fontStyleSubHeading);
// Adding Text element to the Section having font styled by default...
$percent = round($project->PERCENT,2);
$section->addText(
htmlspecialchars('Total % Complete - '.$percent),
$paragraphOptions
);
$section->addText(
htmlspecialchars($project->PROJINFO)
);
$myTextElement = $section->addText(
htmlspecialchars('Action items for SI')
);
$myTextElement->setFontStyle($fontStyleSubHeading);
$section->addText(
htmlspecialchars('None')
);
$myTextElement = $section->addText(
htmlspecialchars('Action items for MC')
);
$myTextElement->setFontStyle($fontStyleSubHeading);
$section->addText(
htmlspecialchars('None')
);
}
它应该是一个标题,每个部分的每个部分应该相隔 spaced,并且其中的所有行都应该没有 spaces。
您错误地为 $section->addText() 函数提供了段落选项。第二个参数是字体样式,即您需要将函数调用更新为:
$section->addText(
htmlspecialchars('Total % Complete - '.$percent),
null,
$paragraphOptions
);
已更新:
要同时使用您的字体样式和段落样式,您可以将它们都作为参数而不是使用 setFontStyle 函数(即,在将样式作为参数时,您根本不需要 $myTextElement 变量需要时):
$fontStyle = array('name' => 'Calibri', 'size' => 11, 'bold' => true);
$section->addText(
htmlspecialchars('Action items for SI'),
$fontStyle,
$paragraphOptions
);