Reputation: 2654
I have the following code but i cannot figure out how to remove the line space or set custom line height etc.
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')
);
}
It should be a title and each for each section should be spaced apart and all the lines within shoudl have no spaces.
Upvotes: 1
Views: 4670
Reputation: 2710
You are giving the paragraph options incorrectly to the $section->addText() function. The second parameter is font styling, i.e. you need to update the function call to:
$section->addText(
htmlspecialchars('Total % Complete - '.$percent),
null,
$paragraphOptions
);
Updated:
to use both your font style and paragraph style, you can give them both as parameters instead of using the setFontStyle function (i.e. you shouldn't have the need for the $myTextElement variable at all when giving the styles as parameters when needed):
$fontStyle = array('name' => 'Calibri', 'size' => 11, 'bold' => true);
$section->addText(
htmlspecialchars('Action items for SI'),
$fontStyle,
$paragraphOptions
);
Upvotes: 1