KoolReport's Forum

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

Excel Document Unreadable on Export - Do I Need To Specify dataStore? #128

Open John Lawson opened this topic on on Oct 6, 2017 - 5 comments

John Lawson commented on Oct 6, 2017

Hi!

The Problem: I'm working on implementing the excel export package. I can get my PHP view to display my reports, but when I hit the export button on the front end, the excel file that's downloaded is un-openable. I get no error codes or anything.

The Project: I'm reporting on rooms in a building from a SQL datasource. I've got my code set up to choose which room you want data on, then radiolist select if a summary view or a detailed view of the room should be returned.

Essentially, I'm dealing with three datastores. One for the room dropdown select list. And two for the two different kinds of report views.

I suspect that the excel export package can't tell which datasource I'm trying to export.

Is that the case?

How do I tell exportexcel which datastore to use?

My view code for the export button is below.

                    <div class="text-center">
                        <form method="post" action="Room_excel_export.php">
                            <button class="btn btn-primary">Export to Excel</button>
                        </form>
                    </div>

My export code to Room_excel_export.php is below.

<?php
require_once "Room.php";
$room = new Room;

$room->run()->exportToExcel('Room.view')->toBrowser("Room_view.xlsx");

Environment: Ubuntu 16.04 Apache server

KoolReport commented on Oct 7, 2017

Hi John,

If you export simply like this, does it work?

$room->run()->exportToExcel()->toBrowser("Room_view.xlsx");
John Lawson commented on Oct 7, 2017

Hey Kool report Team! Thanks for responding so quickly!

I have tried exporting using

$room->run()->exportToExcel()->toBrowser("Room_view.xlsx");

and like

$room->run()->exportToExcel('Room.view')->toBrowser("Room_view.xlsx");

with the same result. Both produce a near identical excel document that is unreadable in excel. I opened the document with the script editor atom. Inside is a bunch of mishmash I don't understand and the contents for the the initial room select list mentioned in my last post. That one was piped over from on of my three datastores. Nowhere to be seen is the actual datastore I want to export.

David Winterburn commented on Oct 9, 2017

Hi John,

When you export a report to excel, by default it would export all of the report's data stores to an excel file with separated sheet for each data store.

If you only want to export selected data stores, please use this setting:

$report->run()->exportToExcel(array(
  "datastores" => array(
    'sales',
    'employees',
    'customers'
  )
))->toBrowser("myreport.xlsx");

Please try this to export each of your data stores and see how it goes. Thanks!

John Lawson commented on Oct 9, 2017

This worked using "dataStores" (instead of "datastores"), thank you for the tip in the right direction!

KoolReport commented on Oct 10, 2017

Thank you, John. FYI, we have found that our documentation has the same mistake so we have fixed it.

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
solved

Excel