вот привел к использованию в php-код в БП:
| Код |
|---|
Bitrix\Main\Loader::includeModule( 'disk' );
Bitrix\Main\Loader::includeModule( 'documentgenerator' );
$id = 123; // ID файла на диске
$template = Bitrix\Disk\File::loadById( $id );
if ( $template !== null ) {
$file = Bitrix\Main\Application::getDocumentRoot() . '/upload/' . $template->getFile()['SUBDIR'] . '/' . $template->getFile()['FILE_NAME'];
}
else
exit();
$body = new Bitrix\DocumentGenerator\Body\Docx( $file->getContents() );
$body->normalizeContent();
$placeholder = 'W4aTest'; // переменная в шаблоне
$value = 'tutut'; // значение переменной в шаблоне
$placeholderValues[ $placeholder ] = $value;
$body->setValues( $placeholderValues);
$result = $body->process();
$content = $body->getContent();
$tmpDir = Bitrix\Main\Application::getDocumentRoot() . '/upload/tmp';
$tmpName = 'temp_';
$tmpFile = $tmpDir . '/' . $tmpName . '.docx';
file_put_contents( $tmpFile, $content ); |