KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Style Excel Columns to auto fit text #3113

Open iWorQ Systems opened this topic on on Aug 3, 2023 - 4 comments

iWorQ Systems commented on Aug 3, 2023

I am trying to figure out if there is a way to use excelstyle so that when I download my excel sheet that all the columns will fit without having to manually resize them every time.

Sebastian Morales commented on Aug 9, 2023

In case you use ExcelExportable (not BigSpreadsheetExportable) trait, there's an option for Excel package's Table widget called "columnAutoSize":

//MyReportExcel.view.php
excel\Table::create(array(
    ...
    "options" => array(
        "columnAutoSize" => true,
        ...
    )
));

Pls try it and let us know if it meets your requirement.

iWorQ Systems commented on Aug 16, 2023

that worked for my tables, but I am doing it for text lines instead of the table because I have row details, and those are not supported in the table yet. So I was wondering if you guys had a way to do it by the Excel style for divs.

Here is my code to show what I am talking about.

<?php

use koolreport\datagrid\DataTables;
use koolreport\excel\Table;

$sid = $_GET['sid'];
$date1 = $this->params['date1'];
$date2 = $this->params['date2'];
$title = $this->params['reportTitle'];
$columns = $this->params['ColumnHeaders'];
$groupBy = $this->params['groupby'];
$groupbyTitle = $this->params['groupbyTitle'];
$detail = $this->params['detail_yn'];
$range = $this->params['range'];
$resultArray = $this->dataStore('result')->data();
$this->params['detailCount'] = -1;
$this->params['detailCountArray'] = [];
$sheet1 = $title;
$style = $this->params['style'];
$showRange = $style['showrange'];
$showToday = $style['showtoday'];
$showTitle = $style['showtitle'];
$showLogo = $style['showlogo'];
$count = $style['showcount'];
$font = $style['font'];
$tableHeaderColor = $style['hf_back_color'];
$headerFontSize = $style['hf_font_size'];
$headerTextColor = $style['hf_font_color'];
$bodyBackgroundColor = $style['body_back_color'];
$bodyFontSize = $style['body_font_size'];
$bodyTextColor = $style['body_font_color'];
$titleFontColor = $style['title_font_color'];
$titleSize = $style['title_font_size'];
unset($columns['groupby']);
?>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="Excel,HTML,CSS,XML,JavaScript">
<meta name="creator" content="John Doe">
<meta name="subject" content="subject1">
<meta name="title" content="title1">
<meta name="category" content="category1">

<div sheet-name="<?php echo $sheet1; ?>">
    <?php
    $styleArray = [
        'font' => [
            'name' => 'Calibri', //'Verdana', 'Arial'
            'size' => 30,
            'bold' => true,
            'italic' => false,
            'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
            'strikethrough' => false,
            'superscript' => false,
            'subscript' => false,
            'color' => [
                'rgb' => '000000',
                'argb' => 'FF000000',
            ]
        ],
        'alignment' => [
            'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
            'vertical' => 'bottom',//top, center, justify, distributed
            'textRotation' => 0,
            'wrapText' => false,
            'shrinkToFit' => false,
            'indent' => 0,
            'readOrder' => 0,
        ],
        'borders' => [
            'top' => [
                'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
                'color' => [
                    'rgb' => '808080',
                    'argb' => 'FF808080',
                ]
            ],
            //left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
        ],
        'fill' => [
            'fillType' => 'none', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
            'rotation' => 90,
            'color' => [
                'rgb' => 'A0A0A0',
                'argb' => 'FFA0A0A0',
            ],
            'startColor' => [
                'rgb' => 'A0A0A0',
                'argb' => 'FFA0A0A0',
            ],
            'endColor' => [
                'argb' => 'FFFFFF',
                'argb' => 'FFFFFFFF',
            ],
        ],
    ];

    $bodyStyleArray =  [
        'font' => [
            'name' => $font, //'Verdana', 'Arial'
            'size' => $bodyFontSize,
            'bold' => false,
            'italic' => false,
            'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
            'strikethrough' => false,
            'superscript' => false,
            'subscript' => false,
            'color' => [
                'rgb' => $bodyTextColor,
                'argb' => $bodyTextColor,
            ]
        ],
        'alignment' => [
            'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
            'vertical' => 'bottom',//top, center, justify, distributed
            'textRotation' => 0,
            'wrapText' => false,
            'shrinkToFit' => false,
            'indent' => 0,
            'readOrder' => 0,
        ],
        'borders' => [
            'allBorders' => [
                'borderStyle' => 'hair', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
                'color' => [
                    'rgb' => '000000',
                    'argb' => '000000',
                ]
            ],
            //left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
        ],
        'fill' => [
            'fillType' => 'solid', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
            'rotation' => 90,
            'color' => [
                'rgb' => $bodyBackgroundColor,
                'argb' => $bodyBackgroundColor,
            ],
            'startColor' => [
                'rgb' => $bodyBackgroundColor,
                'argb' => $bodyBackgroundColor,
            ],
            'endColor' => [
                'argb' => $bodyBackgroundColor,
                'argb' => $bodyBackgroundColor,
            ],
        ],
    ];

    $headerStyleArray =  [
        'font' => [
            'name' => $font, //'Verdana', 'Arial'
            'size' => $headerFontSize,
            'bold' => true,
            'italic' => false,
            'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
            'strikethrough' => false,
            'superscript' => false,
            'subscript' => false,
            'color' => [
                'rgb' => $headerTextColor,
                'argb' => $headerTextColor,
            ]
        ],
        'alignment' => [
            'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
            'vertical' => 'bottom',//top, center, justify, distributed
            'textRotation' => 0,
            'wrapText' => false,
            'shrinkToFit' => false,
            'indent' => 0,
            'readOrder' => 0,
        ],
        'borders' => [
            'allBorders' => [
                'borderStyle' => 'hair', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
                'color' => [
                    'rgb' => '000000',
                    'argb' => '000000',
                ]
            ],
            //left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
        ],
        'fill' => [
            'fillType' => 'solid', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
            'rotation' => 90,
            'color' => [
                'rgb' => $tableHeaderColor,
                'argb' => $tableHeaderColor,
            ],
            'startColor' => [
                'rgb' => $tableHeaderColor,
                'argb' => $tableHeaderColor,
            ],
            'endColor' => [
                'argb' => $tableHeaderColor,
                'argb' => $tableHeaderColor,
            ],
        ],
    ];


    $detailStyleArray = [
        'font' => [
            'name' => 'Calibri', //'Verdana', 'Arial'
            'size' => 16,
            'bold' => true,
            'italic' => false,
            'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
            'strikethrough' => false,
            'superscript' => false,
            'subscript' => false,
            'color' => [
                'rgb' => '000000',
                'argb' => 'FF000000',
            ]
        ],
        'alignment' => [
            'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
            'vertical' => 'bottom',//top, center, justify, distributed
            'textRotation' => 0,
            'wrapText' => false,
            'shrinkToFit' => false,
            'indent' => 0,
            'readOrder' => 0,
        ],
        'borders' => [
            'top' => [
                'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
                'color' => [
                    'rgb' => '808080',
                    'argb' => 'FF808080',
                ]
            ],
            //left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
        ],
        'fill' => [
            'fillType' => 'solid', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
            'rotation' => 90,
            'color' => [
                'rgb' => 'FFFFFFFF',
                'argb' => 'FFFFFFFF',
            ],
            'startColor' => [
                'rgb' => 'FFFFFFFF',
                'argb' => 'FFFFFFFF',
            ],
            'endColor' => [
                'argb' => 'FFFFFF',
                'argb' => 'FFFFFFFF',
            ],
        ],
    ];
    ?>
    <div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Permit Report
    </div>
    <?php
    if (!$groupBy) {
        $alpha = 'A';
        $forward = 0;
        foreach ($resultArray[0] as $key => $val) {
            if ($key != 'identifier') {
                echo('<div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . '2">
                    ' . $key . '
                    </div>');
                $alpha++;
                $this->sheet->getColumnDimension($alpha.'2')->setAutoSize(true);
            }
        }
        $alpha = 'A';
        $numeric = 3;
        for ($i = 0; $i <= count($resultArray); $i++) {
            foreach ($resultArray[$i] as $key => $val) {
                if ($key != 'identifier') {
                    echo('<div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                        ' . $val . '
                        </div>');
                    $alpha++;
                }
                if ($key == 'identifier') {
                    $back = $numeric;
                    $numeric++;
                    $inspectionDetail = !$this->dataStore("inspectionDetails")->isEmpty() ? $this->dataStore("inspectionDetails")->filter("instance_id", '=', $val) : $this->dataStore("inspectionDetails");
                    if (!$inspectionDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Inspections
                                </div>
                            ');

                        $numeric++;
                        $inspections = $this->dataStore("inspectionDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($inspections[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($inspections); $j++) {
                            foreach ($inspections[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    if ($this->params['type'] == 'Permit') {
                        $noteDetail = !$this->dataStore("noteDetails")->isEmpty() ? $this->dataStore("noteDetails")->filter("instance_id", '=', $val) : $this->dataStore("noteDetails");
                    } else {
                        $noteDetail = !$this->dataStore("noteDetails")->isEmpty() ? $this->dataStore("noteDetails")->filter("property_id", '=', $val) : $this->dataStore("noteDetails");
                    }
                    if (!$noteDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Notes
                                </div>
                            ');

                        $numeric++;
                        $notes = $this->dataStore("noteDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($notes[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($notes); $j++) {
                            foreach ($notes[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray). ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $fileDetail = !$this->dataStore("fileDetails")->isEmpty() ? $this->dataStore("fileDetails")->filter("instance_id", '=', $val) : $this->dataStore("filesDetails");
                    if (!$fileDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Files
                                </div>
                            ');

                        $numeric++;
                        $files = $this->dataStore("fileDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($files[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($files); $j++) {
                            foreach ($files[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $letterDetail = !$this->dataStore("letterDetails")->isEmpty() ? $this->dataStore("letterDetails")->filter("instance_id", '=', $val) : $this->dataStore("letterDetails");
                    if (!$letterDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Letters
                                </div>
                            ');

                        $numeric++;
                        $letters = $this->dataStore("letterDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($letters[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($letters); $j++) {
                            foreach ($letters[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $feeDetail = !$this->dataStore("feeDetails")->isEmpty() ? $this->dataStore("feeDetails")->filter("instance_id", '=', $val) : $this->dataStore("feeDetails");
                    if (!$feeDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Fees
                                </div>
                            ');

                        $numeric++;
                        $fees = $this->dataStore("feeDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($fees[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($fees); $j++) {
                            foreach ($fees[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $contractorDetail = !$this->dataStore("contractorDetails")->isEmpty() ? $this->dataStore("contractorDetails")->filter("permit_id", '=', $val) : $this->dataStore("contractorDetails");
                    if (!$contractorDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Contractors
                                </div>
                            ');

                        $numeric++;
                        $contractors = $this->dataStore("contractorDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($contractors[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($contractors); $j++) {
                            foreach ($contractors[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    if ($this->params['type'] == 'Permit') {
                        $licenseDetail = !$this->dataStore("licenseDetails")->isEmpty() ? $this->dataStore("licenseDetails")->filter("permit_id", '=', $val) : $this->dataStore("licenseDetails");
                    } else {
                        $licenseDetail = !$this->dataStore("licenseDetails")->isEmpty() ? $this->dataStore("licenseDetails")->filter("contractor_id", '=', $val) : $this->dataStore("licenseDetails");
                    }
                    if (!$licenseDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Licenses
                                </div>
                            ');

                        $numeric++;
                        $licenses = $this->dataStore("licenseDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($licenses[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($licenses); $j++) {
                            foreach ($licenses[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $paymentDetail = !$this->dataStore("paymentDetails")->isEmpty() ? $this->dataStore("paymentDetails")->filter("instance_id", '=', $val) : $this->dataStore("paymentDetails");
                    if (!$paymentDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Payments
                                </div>
                            ');

                        $numeric++;
                        $payments = $this->dataStore("paymentDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($payments[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($payments); $j++) {
                            foreach ($payments[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $reviewDetail = !$this->dataStore("reviewDetails")->isEmpty() ? $this->dataStore("reviewDetails")->filter("permit_id", '=', $val) : $this->dataStore("reviewDetails");
                    if (!$reviewDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Reviews
                                </div>
                            ');

                        $numeric++;
                        $reviews = $this->dataStore("reviewDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($reviews[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($reviews); $j++) {
                            foreach ($reviews[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $valuationDetail = !$this->dataStore("valuationDetails")->isEmpty() ? $this->dataStore("valuationDetails")->filter("permit_id", '=', $val) : $this->dataStore("valuationDetails");
                    if (!$valuationDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('<div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                            Valuations
                            </div>');

                        $numeric++;
                        $valutions = $this->dataStore("valuationDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($valutions[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($valutions); $j++) {
                            foreach ($valutions[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $employeeDetail = !$this->dataStore("employeeDetails")->isEmpty() ? $this->dataStore("employeeDetails")->filter("contractor_id", '=', $val) : $this->dataStore("employeeDetails");
                    if (!$employeeDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Employees
                                </div>
                            ');

                        $numeric++;
                        $employees = $this->dataStore("employeeDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($employees[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($employees); $j++) {
                            foreach ($employees[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    if ($this->params['type'] == 'Permit') {
                        $restrictionDetail = !$this->dataStore("restrictionDetails")->isEmpty() ? $this->dataStore("restrictionDetails")->filter("permit_id", '=', $val) : $this->dataStore("restrictionDetails");
                    } else {
                        $restrictionDetail = !$this->dataStore("restrictionDetails")->isEmpty() ? $this->dataStore("restrictionDetails")->filter("property_id", '=', $val) : $this->dataStore("restrictionDetails");
                    }
                    if (!$restrictionDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Restrictions
                                </div>
                            ');

                        $numeric++;
                        $restrictions = $this->dataStore("restrictionDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($restrictions[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($restrictions); $j++) {
                            foreach ($restrictions[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $propertyDetail = !$this->dataStore("propertyDetails")->isEmpty() ? $this->dataStore("propertyDetails")->filter("permit_id", '=', $val) : $this->dataStore("propertyDetails");
                    if (!$propertyDetail->isEmpty()) {
                        $alpha = 'B';
                        echo('
                                <div cell="' . $alpha . $numeric . '" excelstyle=' . json_encode($detailStyleArray) . '>
                                    Properties
                                </div>
                            ');

                        $numeric++;
                        $properties = $this->dataStore("propertyDetails")->filter("instance_id", '=', $val)->data();
                        foreach ($properties[0] as $detailKey => $detailVal) {
                            if ($detailKey != 'instance_id') {
                                echo('
                                        <div excelstyle=' . json_encode($headerStyleArray) . ' cell="' . $alpha . $numeric . '">
                                            ' . $detailKey . '
                                        </div>
                                    ');
                                $alpha++;
                            }
                        }
                        $numeric++;
                        $alpha = 'B';
                        for ($j = 0; $j <= count($properties); $j++) {
                            foreach ($properties[$j] as $detailKey => $detailVal) {
                                if ($detailKey != 'instance_id') {
                                    echo('
                                            <div excelstyle=' . json_encode($bodyStyleArray) . ' cell="' . $alpha . $numeric . '">
                                                ' . $detailVal . '
                                            </div>
                                        ');
                                    $alpha++;
                                }
                            }
                            $alpha = 'B';
                            $numeric++;
                        }
                    }
                    $forward = $numeric;
                    $numeric = $back;
                    $alpha = 'A';
                }
            }
            $alpha = 'A';
            if ($forward != 0) {
                $numeric = $forward;
                $forward = 0;
            } else {
                $numeric++;
            }
        }
    } else {
        ?>
        <div>
        <?php

            Table::create([
            "dataSource" => $this->dataStore("result"),
            "cssClass" => [
                "td" => "tdcolor"
            ],
            "columns" => $columns,
            "excludedColumns" => ["groupby"],
            "rowGroup" => [
               $groupbyTitle  => [
                "label" => 'hello',
                'direction' => 'asc',
                "top" => "{" . $groupbyTitle . "}",
               ],
            ],
            "excelStyle" => [ //used in ExcelExportable's template
                "header" => function ($colName) use ($headerStyleArray) {
                    return $headerStyleArray;
                },
                "bottomHeader" => function ($colName) {
                    return [];
                },
                "cell" => function ($colName, $value, $row) use ($bodyStyleArray) {
                    return $bodyStyleArray;
                },
                "footer" => function ($colName, $footerValue) {
                    return [];
                },
            ],
            ]);
        ?>
        </div>
        <?php
    }

    ?>
    

Let me know what you guys think

Sebastian Morales commented on Aug 18, 2023

We will find a solution for users to set column width (either fixed or auto) for text div, i.e excel Text widget in the next version of Excel package.

iWorQ Systems commented on Sep 11, 2023

thank you, we appreciate that!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Excel