KoolReport's Forum

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

The Downloaded Excel File shows corrupted Data #1230

Open Sowmya opened this topic on on Dec 27, 2019 - 6 comments

Sowmya commented on Dec 27, 2019

Dear Sir,

I implemented my code as following example "https://www.koolreport.com/examples/reports/excel/excel_template/"

I got the grid output. But the downloaded excel file shows corrupted data. Please provide me any solution. The Download Excel File is Very Very important feature in my project.

ExcelExport.php

class ExcelExport extends CI_Controller
{
	public function index()
	{
		$this->load->helper('url');
   		$this->load->database('MainiDM');
   		
   		include APPPATH."reports\ExcelExport_Ex.php";
                 $report = new ExcelExport_Ex;
                 $report->run()->render();
	}

	public function export()
	{
		$this->load->helper('url');
   		$this->load->database('MainiDM');
   		
   		include APPPATH."reports\ExcelExport_Ex.php";
                $report = new ExcelExport_Ex;

                $report->run();
                $report->exportToExcel('ExcelExport')->toBrowser("ExcelExport.xlsx");
	}

ExcelExport_Ex.php

class ExcelExport_Ex extends \koolreport\KoolReport
{
    use \koolreport\codeigniter\Friendship;
    use \koolreport\amazing\Theme;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;

    public function settings()
    {
        return array(
            
            "dataSources"=>array(
                "enquiry"=>array(
                    "connectionString"=>"......",
                    "username"=>"sa",
                    "password"=>"....",
                    "charset"=>"utf8"
                )
            )
        );
    }

    public function setup()
    {
        $this->src('enquiry')
        ->query("SELECT * from EnquiryDataView")
        ->pipe($this->dataStore('exceldata'));
    }

}

ExcelExport_Ex.view.php

<form>
<button type="submit" class="btn btn-primary" formaction="<?php echo site_url();?>/ExcelExport/export">Download Excel</button>
</form>
</div>
<div class='box-container'>
    <div>
	<?php
		Table::create(array(
			"dataSource"=>$this->dataStore('exceldata'),
			"paging"=>array(
			"pageSize"=>5
			)
		));
	?>
	</div>
	</div>

ExcelExport.excel.php:

<?php
    use \koolreport\excel\Table;
    use \koolreport\excel\PivotTable;
    use \koolreport\excel\BarChart;
    use \koolreport\excel\LineChart;

    $sheet1 = "Enquires";
?>
<meta>
and                             These are same as Example
<?php                   
$styleArray
?>
<div cell="A1" range="A1:N1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Enquires
    </div>
    <div>Enquires</div>

    <div>
    	<?php
    		Table::create(array(
    			"dataSource"=>$this->dataStore('exceldata'),
    			 "headersExcelStyle" => [
                'CustomerName' => [
                    'font' => [
                        'italic' => true,
                        'color' => [
                            'rgb' => '808080',
                        ]
                    ],
                ]
            ],
            "columnsExcelStyle" => [
                'CustomerName' => [
                    'font' => [
                        'italic' => true,
                        'color' => [
                            'rgb' => '808080',
                        ]
                    ],
                ]
            ],
    		));
    	?>
Sowmya commented on Dec 28, 2019

Is Supoort is there? or Not?

David Winterburn commented on Dec 31, 2019

Hi,

Please change your excel view file from ExcelExport.excel.php to ExcelExportExcel.view.php and use the following export command:

$report->exportToExcel('ExcelExportExcel')->toBrowser("ExcelExport.xlsx");

Let us know the result. Thanks!

Sowmya commented on Jan 2, 2020

Thank you sir for your reply. I done same as you told. But same output.

Sowmya commented on Jan 3, 2020

Please give me some alternative solution

PYDeret commented on Mar 4, 2020

I don't know if your issue is still up @Sowmya, but I've got the same issue, I've found out that if you overextend toBrowser() function, and remove the last header (Content-Length), it works.

ankit raj commented on Apr 17, 2020

Topic #1329: DataTable export to Excel

To anyone who is having difficulty in exporting to excel, please use Datatables package,its excellent .It has searching ,sorting capabilities too along with one click export option. you wont have to struggle so hard.

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