讨论数量:
已解决
$phpWord = IOFactory::load($request->file('word'));
$htmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
$content = '';
foreach ($phpWord->getSections() as $section) {
$writer = new \PhpOffice\PhpWord\Writer\HTML\Element\Container($htmlWriter, $section);
$content .= $writer->write();
}
$title = '';
$sections = $phpWord->getSections();
foreach ($sections as $section) {
$elements = $section->getElements();
foreach ($elements as $element) {
if ($element instanceof \PhpOffice\PhpWord\Element\Text) {
if ($title) break;
$title = $element->getText();
} elseif ($element instanceof \PhpOffice\PhpWord\Element\TextRun) {
foreach ($element->getElements() as $textElement) {
if ($textElement instanceof \PhpOffice\PhpWord\Element\Text) {
if ($title) break;
$title = $textElement->getText();
}
}
}
}
}
return app('show')->success([
'title' => $title,
'content' => $content
]);
已解决