KoolReport's Forum

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

Download excel report not working #448

Open Nick opened this topic on on Sep 5, 2018 - 6 comments

Nick commented on Sep 5, 2018

Hi,

I have integrated koolreport to Laravel. Now I am trying to export a report to Excel using the code: We have one array with settings and $report = new GeneralReport(["ds"=> $wsettings]); $report->run()->exportToExcel()->toBrowser("myreport.xlsx");

But instead of generating the report show nothing. When i going on Network tab from Chrome, on specified request i see status 200, on response header i have "Content-Disposition : attachment; filename ='myreport.xlsx' ", "Content-Lenght:6117" ,"Content-Type: application/vnd.ms-excel" and "Content-Transfer-Encoding: binary". On response tab i have binary chars.

On "GET" method working, i have problems on "POST".

No download starting.

Can anybody help me to resolve the issue?

KoolReport commented on Sep 5, 2018

Please make sure that there is nothing is sent browse (for example, echo some content or render any view) before and after toBrowser() function is called.

Nick commented on Sep 5, 2018

Hi,

This is the function that will be executed :

public function operations(Request $request) {

    $selected  = $request->selected;
    $wsettings = json_decode(base64_decode($request->settings));

    if(($selected !== "all") && (isset($selected))){
        $sdatasource = $wsettings->datasources[$selected];
        $wsettings->datasources = [];
        array_push($wsettings->datasources, $sdatasource);
    }

    $report     = new GeneralReport(["ds"=> $wsettings]);
    $report->run()->exportToExcel()->toBrowser("myreport.xlsx");
}

Here i want to do something for exporting the data in Excel, pdf, csv, etc... For example, for POST i have a button in GET view..then will be pressed i do ajax request on specified route..and bring me on function above. No other operations.

Thanks for your quick response..

KoolReport commented on Sep 5, 2018

Oh! So you use made ajax request to get the file, dont you? You can not download file with ajax request. Please make a normal request (get or post) to the route, you will get the file downloaded.

Nick commented on Sep 6, 2018

Hi,

I quit Ajax and made a request through the classic POST .. so I return an excel but it is empty. Just Excel with no data inside. So, thank you for now, I think it is from me .. that I still have to check. Thank you..

Nick commented on Sep 6, 2018

Hi,

Excel working..Thanks a lot.. Was from me..settings array was not included..for POST request.

KoolReport commented on Sep 6, 2018

That's great!

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
solved

None