Проблема с добавлением новой строки с помощью PhpWord\TemplateProcessor.Php

Кемеровские программисты php общаются здесь
Anonymous
Проблема с добавлением новой строки с помощью PhpWord\TemplateProcessor.

Сообщение Anonymous »

Я пытаюсь заполнить шаблон Word текстом, полученным из html-файла. Проблема в том, что новые строки не создаются в новом созданном файле docx. Я получаю что-то вроде:

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

- Ingredienti :
- 2 Melanzane (circa 1 kg)
- 3 spicchi d'aglio
- 30 ml di succo di limone

Как видите,
не переводится на новую строку. Вот код, который я использую:

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

use PhpOffice\PhpWord\TemplateProcessor;

....
function fillTemplate($templatePath, $outputPath, $context) {
try {
// Load the template
$templateProcessor = new TemplateProcessor($templatePath);
PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
// Replace placeholders with provided content
foreach ($context as $placeholder => $content) {
// Replace the placeholder
$templateProcessor->setValue($placeholder, $content);
}
// Save the generated document
$templateProcessor->saveAs($outputPath);

// Output debug information
echo "Template processed successfully. Output saved to: $outputPath\n";
} catch (Exception $e) {
// Handle errors
echo "Error processing template: " . $e->getMessage() . "\n";
}
}
Любая помощь/совет приветствуется.
В полученном выходном файле docx отображается «
» вместо создания новой строки в документе Word. .

Подробнее здесь: https://stackoverflow.com/questions/780 ... eprocessor

Вернуться в «Php»