How do I make automatic height row based on content in the maatwebsite version 3 laravel excel?

好久不见. 提交于 2019-12-29 09:31:56

问题


I had search reference and the reference say to try like this :

<?php   
...
class ReportExport implements ShouldAutoSize, FromView, WithColumnFormatting, WithEvents
{
    ...
    public function registerEvents(): array
    {
        return [
            AfterSheet::class    => function(AfterSheet $event) {
                ...
                $event->sheet->getDelegate()->getRowDimension(37)->setRowHeight(-1);
                $event->sheet->getDelegate()->getStyle('R37:Z37')->getAlignment()->setWrapText(true);
            },
        ];
    }
}

I try like that, but the result like this :

Should the height of row automatic added based content/text. But it does not added

How can I solve this problem?

Update :

Seems this script : $event->sheet->getDelegate()->getRowDimension(37)->setRowHeight(-1); is not working in the table

I tried the script outside the table, it worked. So the script only work outside table tag

My table like this :

<table>
    ....
    @php ($group = 'A')
    @php ($number = 0)
    @foreach($values as $item)
    @if($number==0 || $group!=$item['group'])
    <tr>
        <td colspan="9">Kelompok {{$item['group']}}</td>
        <td colspan="2"></td>
        <td colspan="3"></td>
        <td colspan="3"></td>
        <td colspan="9"></td>
        <td colspan="2"></td>
        <td colspan="3"></td>
        <td colspan="3"></td>
        <td colspan="9"></td>
    </tr>
    @php ($number = 0)
    @endif
    <tr>
        <td style="text-align:center;" colspan="2">{{++$number}}</td>
        <td colspan="7">{{$item['lesson_name']}}</td>
        <td style="text-align:center;" colspan="2">{{$item['kb_pengetahuan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['nilai_pengetahuan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['predikat_pengetahuan']}}</td>
        <td colspan="9">{{$item['deskripsi_pengetahuan']}}</td>
        <td style="text-align:center;" colspan="2">{{$item['kb_keterampilan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['nilai_keterampilan']}}</td>
        <td style="text-align:center;" colspan="3">{{$item['predikat_keterampilan']}}</td>
        <td colspan="9">{{$item['deskripsi_keterampilan']}}</td>
    </tr>
    @php ($group = $item['group'])
    @endforeach
</table>

Please help me. I need support for PhpSpreadsheet functionality


回答1:


public function registerEvents(): array
    {
        return [
            AfterSheet::class    => function(AfterSheet $event) {
                ...
                $event->sheet->getDelegate()
                    ->getStyle('R37:Z37')
                    ->applyFromArray([ 'alignment' => ['wrapText' => true]])
            },
        ];
    }


来源:https://stackoverflow.com/questions/56469303/how-do-i-make-automatic-height-row-based-on-content-in-the-maatwebsite-version-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!