Mam taki kod do generowania plików w Wordzie w Laravel 5.8:
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $month = $request->input('month'); if ($month == null) { $now = Carbon::now(); $month = $now->month; } $events = $this->frontendGateway->getEventCalendarDownload($request, $month); $logo = public_path('assets/images/logo3.jpg'); $view_content = View::make('psCMS.prints.events-view', ['events' => $events, 'logo' => $logo])->render(); $section = $phpWord->addSection(); $text = $section->addText('aaaaaaaa'); $text = $section->addText('bbbbbbbbbb'); $text = $section->addText('ccccccccccc'); $text = $section->addText($view_content); //ob_clean(); $fileName = 'Event_calendar' . '-' . now()->toDateString() . '.doc'; $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save($fileName);
Mój Blade:
<div id="header" class="fontSize14"> <table width="100%"> <tr> <td align="left" style="width: 20%;"> <img src="{{ $logo }}" class="logo" /> </td> <td align="left" style="width: 80%;"> <span class="fontSize19"><b>my name</b></span><br /> street<br /> </td> </tr> </table> </div> <div id="content" class="fontSize11"> <b class="fontSize19">Kalendarz wydarzeń</b><br /><br /> <table width="100%"> <thead style="background-color: lightgray;"> <tr> <th>#</th> <th>Data</th> <th>Godzina</th> <th>Nazwa imprezy</th> <th>Miejsce</th> </tr> </thead> <tbody> @foreach($events as $event) @php $hourFrom = $hourFromX['0'].":".$hourFromX['1']; $hourTo = $hourToX['0'].":".$hourToX['1']; @endphp <tr> <th scope="row">{{ $loop->iteration }}</th> <td>{{ $event->date_from }}</td> <td align="left">{{ $hourFrom }}-{{ $hourTo }}</td> <td align="left">{{ $event->title }}</td> {{ $event->localization->city }} {{ $event->localization->street }} @endif</td> </tr> @endforeach </tbody> </table> </div>
Kiedy uruchamiam ten kod mam komunikat: plik Word jest uszkodzony.
Kiedy zakomentuję tą linię:
$text = $section->addText($view_content);
Plik Worda jest wygenerowany bez problemu, otwiera się.
W jaki sposób można to naprawić?