jeudi 2 janvier 2020

Generate Word file in PHPWord in Laravel 5.8

I am beginner in Laravel. I use in my project Laravel 5.8.

I have function to generate PDF file:

public function getCallendar(Request $request)
    {
        $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');

        $pdf = \PDF::loadView('prints.events-view', ['events' => $events, 'logo' => $logo]);
        $pdf->setOptions(['isPhpEnabled' => true, 'dpi' => 150, 'setIsRemoteEnabled' => true]);
        $pdf->setPaper('A4', 'letter');
        return $pdf->download('Event Callendar' .  '-' . now()->toDateString() . '.pdf');
    }

My Blade:

<div id="header" class="fontSize14">
    <table width="100%">
        <tr>
            <td align="left" style="width: 20%;">
                <img src="" 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">Callendar</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
                $hourFromX = explode(":", $event->hour_from);
                $hourToX = explode(":", $event->hour_to);
                $hourFrom = $hourFromX['0'].":".$hourFromX['1'];
                $hourTo = $hourToX['0'].":".$hourToX['1'];
            @endphp
            <tr>
                <th scope="row"></th>
            <td></td>
            <td align="left">-</td>
            <td align="left"></td>
            <td align="left">@if(isset($event->localization)) ,
                
                 @endif</td>
            </tr>
            @endforeach
        </tbody>
    </table>


</div><div id="header" class="fontSize14">
    <table width="100%">
        <tr>
            <td align="left" style="width: 20%;">
                <img src="" class="logo" />
            </td>
            <td align="left" style="width: 80%;">
                <span class="fontSize19"><b>My name</b></span><br />
                street name
            </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
                $hourFromX = explode(":", $event->hour_from);
                $hourToX = explode(":", $event->hour_to);
                $hourFrom = $hourFromX['0'].":".$hourFromX['1'];
                $hourTo = $hourToX['0'].":".$hourToX['1'];
            @endphp
            <tr>
                <th scope="row"></th>
            <td></td>
            <td align="left">-</td>
            <td align="left"></td>
            <td align="left">@if(isset($event->localization)) ,
                
                 @endif</td>
            </tr>
            @endforeach
        </tbody>
    </table>


</div>

It's work fine.

Now I want make generate Word file. I found this lib: https://github.com/PHPOffice/PHPWord

I try change my function to this lib (export to Word file):

use PhpOffice\PhpWord\PhpWord; ....

public function getCallendar(Request $request)
    {
        $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');
...
    }

How can I add my data and view to Word?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/35dQwqn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire