Страница 1 из 1

Не находит class PHPWord_Shared_Font

Добавлено: 2019.07.28, 17:45
svil
Не могу найтит аналог класса PHPWord_Shared_Font - отвечает за отступы внутри ячейки
и не получается сделать border для таблицы: $styleTable = array('borderSize'=>1); - не срабатывает
и с ошибкой открыаается в Word

Код: Выделить всё

<?php

use PhpOffice\PhpWord\PhpWord;


$general_edu_company="...";
$general_edu_company_full="...";
$general_edu_company_ceo="...";



$PHPWord = new \PhpOffice\PhpWord\PhpWord();
$PHPWord->setDefaultFontName('Times New Roman');
$PHPWord->setDefaultFontSize(12);


$sectionStyle = array(
'marginTop' => '634' // по-умолчанию равен 1418* и соответствует 2,5 см отступа сверху
,'marginLeft' => '718' // по-умолчанию равен 1418* и соответствует 2,5 см отступа слева
,'marginRight' => '718' // по-умолчанию равен 1418* и соответствует 2,5 см отступа справа
,'marginBottom' => '634' // по-умолчанию равен 1134* и соответствует 2 см отступа снизу
    
);

// New portrait section
$section = $PHPWord->createSection($sectionStyle);

// Add text elements
$PHPWord->addFontStyle('rStyle14', array('bold'=>true, 'size'=>14));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>400, 'spaceAfter'=>400));
$section->addText($general_edu_company_full, 'rStyle14', 'pStyle');

$section->addText('ПРИКАЗ', 'rStyle14', 'pStyle');

$PHPWord->addFontStyle('rStyle12', array('size'=>12, 'bold'=>true));
$section->addText('№                                          от '.Yii::$app->formatter->asDate($model->start,'php:d.m.Y').' г.', 'rStyle12');
$section->addText('«Об организации обучения»');

$section->addText('ПРИКАЗЫВАЮ:', 'rStyle14', 'pStyle');

$PHPWord->addFontStyle('rStyle12n', array('size'=>12));
$PHPWord->addParagraphStyle('pStyle12n', array('spaceAfter'=>100));
$section->addText('1. Провести обучение c '.Yii::$app->formatter->asDate($model->start,'php:d.m.Y').' по '.Yii::$app->formatter->asDate($model->end,'php:d.m.Y').' в соответствии с учебным планом и программой обучения «'.$model->courses->ord1.'».', 'rStyle12n', 'pStyle12n');
$section->addTextBreak(1);

$section->addText('2. Зачислить в группу № '.$model['num'].' следующих специалистов:', 'rStyle12n', 'pStyle12n');

// Add table
$styleTable = array('borderSize'=>1);
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable);
$table = $section->addTable('myOwnTableStyle');

// Add row
$table->addRow();

// Add cells
$styleCell = array('valign' => 'center');
$PHPWord->addFontStyle('myOwnCellStyle', array('bold'=>true, 'italic'=>true, 'size'=>12));
$table->addCell(2000, $styleCell)->addText('№ п/п', 'myOwnCellStyle');
$table->addCell(2000, $styleCell)->addText('Фамилия, имя, отчество', 'myOwnCellStyle');
$table->addCell(2000, $styleCell)->addText('Должность', 'myOwnCellStyle');
$table->addCell(2000, $styleCell)->addText('Организация', 'myOwnCellStyle');

$r = 1;

foreach ($model->listeners as $list)
{
    $table->addRow();

   
    $uname = $list->listeners->surname." ".$list->listeners->name." ".$list->listeners->thirdname;
    $ucompany =  $list->jobs->companies->name;
    $ujob = $list->jobs->name;

    $table->addCell(null)->addText("$r");
    $table->addCell(null)->addText("$uname");
    $table->addCell(null)->addText("$ujob");
    $table->addCell(null)->addText("$ucompany");

    $r++;

  //  echo $list->jobs->companies->name."<br> "." ".$list->jobs->name." ".$list->id_group."-".$list->id_user."-".$list->listeners->surname." ".$list->listeners->name." ".$list->listeners->thirdname."<br>";
}

$section->addTextBreak(1);

$section->addText('3. '.$model->courses->ord2, 'rStyle12n', 'pStyle12n');
$section->addTextBreak(1);

// Add table
$table = $section->addTable();

// Add row
$table->addRow();

// Add cells


$table->addCell([u]\PhpOffice\PhpWord\PHPWord_Shared_Font::centimeterSizeToTwips(9[/u]))->addText('Директор'); //здесь не видит класс
$table->addCell(\PhpOffice\PhpWord\PHPWord_Shared_Font::centimeterSizeToTwips(9))->addText($general_edu_company_ceo);

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');

$gname = 'Order'.$model->num."-".Yii::$app->formatter->asDate($model->start,'php:d.m.Y');

$objWriter->save("$gname.docx");

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; filename=$gname.docx");
readfile("$gname.docx");
unlink("$gname.docx");
?>




Re: Не находит class PHPWord_Shared_Font

Добавлено: 2019.07.28, 19:05
svil
Исправила так
Вместо

Код: Выделить всё

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');

$gname = 'Order'.$model->num."-".Yii::$app->formatter->asDate($model->start,'php:d.m.Y');

$objWriter->save("$gname.docx");

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; filename=$gname.docx");
readfile("$gname.docx");
unlink("$gname.docx");
Это

Код: Выделить всё

$file = 'Order'.$model->num."-".Yii::$app->formatter->asDate($model->start,'php:d.m.Y').".docx";


$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');
$xmlWriter->save($file);
$dir = Yii::getAlias('@app/web/'.$file);
Yii::$app->response->sendFile($dir);

Re: Не находит class PHPWord_Shared_Font

Добавлено: 2019.07.29, 21:28
svil
Класс PHPWord_Shared_Font даже нагуглить не удалось и в пространстве имен yii2 его нет.