내 Laravel 응용 프로그램에서 PHPOffice/PHPWord를 사용하고 있습니다. 테이블에 결과가있는 .docx 문서를 생성하는 데 사용됩니다. 이 6 행 3 개 테이블의 문서에 대해 잘 작동하지만,이 문서가 생성됩니다 더 많은 행이 있지만 그것을 다음과 같은 오류를 열 때하는 것이 발생했을 때 :XML 구문 분석 오류입니다. PHPWord
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.
을 지금, 나는 또 다른 결과 페이지 위치에 작업을 시작했습니다 .docx 문서를 생성하고 싶습니다. 여기에는 5 개의 표가 포함되지만 3 행으로 동일한 XML 구문 분석 오류가 있지만 다른 위치 (위치 : 부분 : /word/document.xml, 줄 : 4, 열 : 2888)에 있습니다. 누군가 내 코드 또는 phpword/words에 오류가 있는지 설명 할 수 있습니까?
나는 모든 것을 삭제하고 새로운 행을 천천히 추가함으로써 몇 가지 문제 해결을했습니다. 오류를 발견했지만 어떻게 해결할 수 있습니까? 처음 두 테이블은 훌륭하게 생성됩니다.
$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);
고마워요!
해결 방법 오크, 그래서 전체 문서를 삭제하고 오류가 발생한 곳을보기 위해 모든 문장을 따로 추가했습니다. 이로 인해 오류가 내가 얻은 데이터에서 비롯된 것으로 나타났습니다. ">"및 "&"표지판을 처리 할 수 없습니다.
모든 오류가 발생하면 인쇄중인 데이터를 확인하십시오!
이상한 점은 .. -> addRow()에서 매개 변수를 제거하고 한 번에 한 번씩 all -> addCell을 추가하고 다시 작동하는 방식입니다. 문제는 테이블 머리가 너무 많았던 것입니까? ... –