KoolReport's Forum

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

Excel corrupted file #2398

Open Epitello opened this topic on on Oct 18, 2021 - 5 comments

Epitello commented on Oct 18, 2021

Hi,

I'm working on excel export feature. I want export chart's datas into excel file. The file well downloaded but the file is corrupted.

My excel view:

data:

columns:

Thanks

Sebastian Morales commented on Oct 19, 2021

Would you pls open the corrupted excel files in a text editor and let us know if there's any warning/error message in there? Tks,

Epitello commented on Oct 19, 2021

No, the file is not readable

Sebastian Morales commented on Oct 19, 2021

Pls try with a simple excel view file with one sheet div and one table like this:

//MyReportExcel.view.php
<div sheet-name="sheet1">
    <div>
        <?php
        $ds = $this->getDatastore(...); // fill in one datastore name with data here
        Table::creat(array(
            "name" => "table1",
            "dataSource" => $ds,
        )); // test it with no "columns" property
        ?>
    </div>
</div>

Let us know the result. Send us the exported excel file to support@koolphp.net or support@koolreport.com if it's still corrupted. Tks,

Epitello commented on Oct 19, 2021

No, it doesn't work with a simple excel. I sent the excel file

Thanks

Sebastian Morales commented on Oct 19, 2021

Hi, thanks for sending the corrupted excel file. After checking the content of the file we found that there are a couple of curly brace characters at the end of the file ("{}"), which corrupted it. It looks like the output of the excel file was followed by some other output. To prevent such case pls don't include the end of php script sign ?> at the end of your export php file, as well as try to add ob_start() like this:

<?php
//Export.php
ob_start(); //Turn on output buffering so that any warning/notice message wouldn't be output

$report = new MyReport();
$report->run();

ob_end_clean(); // clear buffering without outputting it

// output excel file content
$report
->exportToExcel('MyReportExcel')
->toBrowser("MyReport.xlsx");

// it's a good practice to not include ?> at the end of php file because any blank space or special character after ?> would be output as well. In this case it would have corrupted the excel file content

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
None yet

None