XML -Parsenfehler; PhpWordPhp

PHP-Programmierer chatten hier
Anonymous
 XML -Parsenfehler; PhpWord

Post by Anonymous »

Ich verwende Phpoffice/PhpWord in meiner Laravel -Anwendung. Es wird verwendet, um ein .docx -Dokument mit Ergebnissen in Tabellen zu generieren. Dies funktioniert hervorragend für ein Dokument mit 3 Tabellen mit 6 Zeilen. Wenn jedoch mehr Zeilen vorhanden sind, wird das Dokument generiert, aber beim Öffnen des folgenden Fehlers tritt der folgende Fehler auf: < /p>

We're sorry, We can't open (documentname) because we found a problem with its contents.

Details: XML parsing error Location: Part:/word/document.xml, Line: 2, Column 14349.
< /code>

Jetzt habe ich begonnen, an einer anderen Ergebnisseite zu arbeiten, auf der ich auch ein .docx -Dokument generieren möchte. Dies enthält 5 Tabellen, aber mit 3 Zeilen erhalte ich den gleichen XML -Parsing -Fehler, aber an einem anderen Ort (Ort: Teil: /word/document.xml, Zeile: 4, Spalte: 2888). Könnte mir jemand erklären, ob dies ein Fehler in meinem Code oder PhpWord/Wörtern ist? < /p>

Ich habe etwas Fehlerbehebung gemacht, indem ich alles gelöscht und langsam neue Zeilen hinzufügt. Ich habe den Fehler gefunden, aber wie könnte ich ihn beheben? Die ersten beiden Tabellen werden gut erzeugt .. < /p>

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$section = $phpWord->addSection();
$section->addImage('../public/img/2.jpg', array('width' => 230, 'height' => 65, 'alignment' => 'left'));
$section->addText('Project IDs:' . $parameter);
$header =$section->addHeader();
$header->addText('Results Summary');

$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(16),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
'positioning' => 'absolute',
)
);
$tableName = 'rStyle';
$phpWord->addFontStyle($tableName, array('italic' => true, 'size' => 12));
$thName = 'tStyle';
$phpWord->addFontStyle($thName, array('bold' => true, 'size' => 9));

$section->addText('General Information Table', $tableName);
$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '999999');
$spanTableStyleName = 'Overview tables';
$phpWord->addTableStyle($spanTableStyleName, $fancyTableStyle);
$table = $section->addTable($spanTableStyleName);
$table->addRow(null, array('tblHeader' => true, 'cantSplit' => true));
$table->addCell(1750)->addText('Project ID',$thName);
$table->addCell(1750)->addText('Description',$thName);
$table->addCell(1750)->addText('Notes',$thName);
foreach ($id_array_explode as $char) {
$table->addRow();
$singlenumber = (int)$char;
$cursor = $collection->find(array("id" => $singlenumber));
foreach ($cursor as $document) {
$table->addCell(1750)->addText($document["project_id"]);
$table->addCell(1750)->addText($document["description"]);
$table->addCell(1750)->addText($document["notes"]);
}
}
$section->addText('
');
$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(16),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
'positioning' => 'absolute',
)
);
$section->addText('Input Table', $tableName);
$table1 = $section->addTable($spanTableStyleName);
$table1->addRow(null, array('tblHeader' => true, 'cantSplit' => true));
$table1->addCell(1750)->addText('Project ID',$thName);
$table1->addCell(1750)->addText('#',$thName);
foreach ($id_array_explode as $char) {
$table1->addRow();
$singlenumber = (int)$char;
$cursor = $collection->find(array("id" => $singlenumber));
foreach ($cursor as $document) {
if (is_array($document['input'])) {
foreach ($document['input'] as $samples) {
$table1->addCell(1750)->addText($document["project_id"]);
$table1->addCell(1750)->addText($samples['nr']);
}
}
}
}
$section->addText('
');
$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(16),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
'positioning' => 'absolute',
)
);
$section->addText('Output Table', $tableName);
$table2 = $section->addTable($spanTableStyleName);
//// THIS IS WHERE THE ERROR OCCURS!!
$table2->addRow(null, array('tblHeader' => true, 'cantSplit' => true));
$table2->addCell(1750)->addText('ID',$thName);
< /code>

Danke! < /p>

Lösung < /strong>
Oke, daher habe ich das gesamte Dokument gelöscht und jeden einzelnen Satz separat hinzugefügt, um zu sehen, wo der Fehler aufgetreten ist. Dies führte dazu, dass der Fehler aus den Daten stammte, die ich erhielt. Es konnte nicht mit ">" und "&" Zeichen umgehen! < /p>

Wenn Sie also diesen Fehler haben, überprüfen Sie die Daten, die Sie drucken!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post