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

1

-1

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 :

enter image description here

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

Javelin answered 5/6, 2019 at 23:34 Comment(7)
Is there no one who can answer this question?Javelin
Would you like to have automatic height or width?Weaver
@Vikash Pathak I want to have automatic heightJavelin
Check if $sheet->autoSize(true); could work for you.Weaver
There exist error : Call to undefined method PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::setAutoSize()Javelin
@Vikash Pathak Do you have a solution?Javelin
Hi @SuccessMan, can you check if $event->sheet->getDefaultRowDimension()->setRowHeight(-1); works for the table?Prickett
E
1

public function registerEvents(): array
    {
        return [
            AfterSheet::class    => function(AfterSheet $event) {
                ...
                $event->sheet->getDelegate()
                    ->getStyle('R37:Z37')
                    ->applyFromArray([ 'alignment' => ['wrapText' => true]])
            },
        ];
    }
Eshman answered 20/12, 2019 at 7:59 Comment(1)
Welcome to Stackoverflow. Please explain your code so other can understand clearly.Trojan

© 2022 - 2024 — McMap. All rights reserved.