KoolReport's Forum

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

Excel File is Not Downloading #959

Open Sowmya opened this topic on on Jul 2, 2019 - 7 comments

Sowmya commented on Jul 2, 2019

Hi KoolReport team,

    I'm Sowmya. I'm Koolreport Pro User. I implemented Koolreport4 in CodeIgniter3. I got the Grid Output. But My Excel file is not Downloading. When I click on "Download" button, it redirects me to the empty page....

My Code:

Home.php:

public function index()
    {
         include APPPATH."reports\ExcelReport.php";
        $report = new ExcelReport;
        $report->run()->render();
      }  

export.php:

<?php
include "ExcelReport.php";
$report = new ExcelReport;
$report->run();
$report->exportToExcel('ExcelReport')->toBrowser("ExcelReport.xlsx");

ExcelReport.php:

<?php

require APPPATH."/libraries/koolreport/core/autoload.php";

use \koolreport\excel\ExcelDataSource;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;

class ExcelReport extends \koolreport\KoolReport
{
	use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;

	public function settings()
	{
		return array(
			"assets"=>array(
                "path"=>"../../assets",
                "url"=>"assets",
            ),
            "dataSources"=>array(
                "invoice"=>array(
                    "connectionString"=>"sqlsrv:Server=*****;Database=*****",
                    "username"=>"sa",
                    "password"=>"*****",
                    "charset"=>"utf8"
                )
            )
        );
	}

	public function setup()
	{
		
		$this->src('invoice')
		->query("select CostCentre,MONTH(Month) as MonFiled,YEAR(Month) as YearField,
			SUM(InvValue) as InvoiceValue 
			from MonthWiseSalesSummeries 
			group by CostCentre,MONTH(Month),YEAR(Month)
			order by CostCentre,MONTH(Month),YEAR(Month)")
		
		->pipe($this->dataStore("excelDataStore"));
	}
}

ExcelReport.view.php

<body>
    
            <?php
            Table::create(array(
                "dataSource" => $this->dataStore('excelDataStore'),
                "columns"=>array(
                   "CostCentre",
                   "InvoiceValue"=>array(
                   "type"=>"number",
                   "label"=>"InvoiceValue",
                   "prefix"=>"$"
                    )
                ),
                "paging"=>array(
                    "pageSize"=>5
                )
            ));
            ?>
      ```

### ExcelReport.excel.php


<div sheet-name="<?php echo $sheet1; ?>">
    <?php
    $styleArray = [
       ----------
       ---------
        ],
        'alignment' => [
            --------,
            --------
        ],
        'borders' => [
          --------
        ---------
           ],
        'fill' => [
           ----------
        -------------
            ],
            'startColor' => [
               ---------
               ---------
            ],
            'endColor' => [
              ----------
            ------------
    ];
    ?>
    <div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Sales Report
    </div>

    <div>
        <?php
        Table::create(array(
            "dataSource" => $this->dataStore('excelDataStore'),
            // "dataSource" => 'orders',
            "headersExcelStyle" => [
                'CostCentre' => [
                    'font' => [
                        'italic' => true,
                        'color' => [
                            'rgb' => '808080',
                        ]
                    ],
                ],
                'InvoiceValue'=> [
                    'font' => [
                        'italic' => true,
                        'color' => [
                            'rgb' => '808080',
                        ]
                    ],
                ]
            ],
            "columnsExcelStyle" => [
                'CostCentre' => [
                    'font' => [
                        'italic' => true,
                        'color' => [
                            'rgb' => '808080',
                        ]
                    ],
                ],
                'InvoiceValue' => [
                    'font' => [
                        'italic' => true,
                        'color' => [
                            'rgb' => '808080',
                        ]
                    ],
                ]
            ],

        ));
        ?>
    </div>

    <?php
    
        $datastores = ['excelDataStore'];
        foreach ($datastores as $datastore)
        { 
        	if ($datastore === 'excelDataStore')
        	{
                $title = 'excelDataStore';
                $name = 'customerSales';
                $column = 'CostCentre';
            } 
        }
      ?>
            <div>
            	<?php echo $title; ?>
            </div>
               <div>
                <?php
                Table::create(array(
                    "name" => $name,
                    // "dataSource" => $this->dataStore($datastore),
                    "dataSource" => $datastore,
                    "columns" =>[
                        $column, "InvoiceValue"
                    ],
                ));
                ?>
            </div>
        <?php }
    ?>
    <div>
        <?php
        PivotTable::create(array(
            "dataSource" => 'excelDataStore',
        ));
        ?>
    </div>

Sowmya commented on Jul 2, 2019

Please Please help me. I have to submit this task Today only. I'm the only Koolreport developer in my organization.....

                                Thank You in advance....
David Winterburn commented on Jul 2, 2019

Hi Sowmya,

Can you post your html/php code for your Download button with your form as well? Thanks!

Sowmya commented on Jul 2, 2019

Thank You for your response...

 <form>
       <button type="submit" class="btn btn-primary exportBtn"             
           formaction="export.php">Download Excel</button>
 </form>

export.php:

<?php
include "ExcelReport.php";
$report = new ExcelReport;
$report->run();
$report->exportToExcel('ExcelReport')->toBrowser("ExcelReport.xlsx");

David Winterburn commented on Jul 2, 2019

Hi excelDataStore,

I think in your report's setup, you only have one datastore called "excelDataStore" while in the excel template file there are many other datastores which are used. Please remove all those datastores and only use your "excelDataStore" datastore in the excel template file. Thanks!

Sowmya commented on Jul 2, 2019

Hi David, I again and again checked my Code. But I did n't find any issue there. I followed same as Example only "https://www.koolreport.com/examples/reports/excel/excel_template/" It redirects me to "http://localhost/CI3/export.php?" and Output is : 404 Page Not Found

Please help me..... I have to submit this task today only... Please Please..... Give me the proper guideline.....

David Winterburn commented on Jul 3, 2019

Hi Sowmya,

Please check Codeigniter's method to get current path and set your formaction="<current path>/export.php".

Sowmya commented on Jul 3, 2019

Hi David,

I am Sowmya, I am KoolReport Pro User. I raised the same ticket 3 Times. Upto now I didn't get any reply from You.
I implemented Koolreport4 in CodeIgniter3. Here I want to attach my report files(to show you how my report looks like). In your Blog it is not supported to upload the files. So that’s y I’m generating this ticket through OutLook. 

AIM: My main Aim is I want to render my Report when I click on Link button in Home Page View.

My Issue is:

### When I render my Report directly from HOME Controller Index method, it gives me nice OUTPUT.

application/controllers/Home.php:

class Home extends CI_Controller 
{
   public function index()
    {   
        include APPPATH."mainiDM\ProfitCenter_Wise_Report.php";
        $report = new ProfitCenter_Wise_Report;
        $report->run()->render();
      }  
}

Problem :

When I render my Report from HOME Controller ,<userDefinedMethodName>, it gives me Empty OUTPUT.

application/controllers/Home.php:

class Home extends CI_Controller 
{
            
    public function index()
    {
            $this->load->view('..\mainiDM\Multi_Drop_Down.php');
     }  
   public function ProfitCenter_Wise_Report()
    {
       include APPPATH."mainiDM\ProfitCenter_Wise_Report.php";
       $report = new ProfitCenter_Wise_Report;
       $report->run()->render();
    }
}

Application/mainiDM/ Multi_Drop_Down.php:

<div class="dropdown">
    <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Sales</button>
    <ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
       <li class="dropdown-submenu">
          <li><a href="<?php echo site_url('Home/ProfitCenter_Wise_Report'); ?>">ProfitCenter Wise Sales</a></li>

AIM: My main Aim is I want to render my Report when I click on Link button in Home Page View.

Thank You In Advance. Please give me reply as early as Possible……

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