KoolReport's Forum

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

Downloaded Excel File shows corrupted data #1214

Open Sowmya opened this topic on on Dec 12, 2019 - 17 comments

Sowmya commented on Dec 12, 2019

Dear KoolReport team,

I am working on Excel Export feature. I got the Table data. My Excel file is also downloaded. But the data in the Excel file is corrupted. Why it happens, I can't understand. Please help me. I am working with Codeigniter3 and SqlServer

Here is my code.

Controller

class Enquiry extends CI_Controller
{
    public function export()
    {      
      include APPPATH."reports\EnquiryReport.php";
      $report = new EnquiryReport;
      $report->run();
      $report->exportToExcel('EnquiryExcel')->toBrowser("EnquiryReport.xls");
    }
}

If I given extension as "xls", then the corrupted data is displaying in Excel. else for the extension "xlsx", it opens the empty file.

KoolReport commented on Dec 12, 2019

Can you post the EnquiryReport.php file?

David Winterburn commented on Dec 13, 2019

Do you have a file called EnquiryExcel.view.php? If your view file is EnquiryReportExcel.view.php your export command should be:

$report->exportToExcel('EnquiryReportExcel')->toBrowser("EnquiryReport.xls");

Thanks!

Sowmya commented on Dec 13, 2019

Hello David, I done as you specified. But no use. Here is my code.

EnquiryReport.php

class EnquiryReport extends \koolreport\KoolReport
{
	use \koolreport\codeigniter\Friendship;
	use \koolreport\export\Exportable;
        use \koolreport\excel\ExcelExportable;

    public function settings()
	{
		return array(
			
            "dataSources"=>array(
                "excelTemplate"=>array(
                   ....
                   .....
                )
            )
        );
	}

	public function setup()
    {
        $this->src('excelTemplate')
        ->query("SELECT EnqRefNo, CustomerName, Email, city, state, country, ContactNumber, salesManger from EnquiryDataView")
        ->pipe($this->dataStore('enquiry'));
    }

EnquiryReport.view.php

<div class='box-container'>
    <div>
      <?php
        Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo',
              'CustomerName',
              'Email',
              'city',
              'state',
              'country',
              'ContactNumber',
              'salesManger'
            ),
             "paging"=>array(
                "pageSize"=>5
              )


        ));
      ?>

    </div>
  </div>

EnquiryReportExcel.view.php

<div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Enquiry Report
    </div>

    <div>
    	<?php
    	Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo',
              'CustomerName',
              'Email',
              'city',
              'state',
              'country',
              'ContactNumber',
              'salesManger'
            ),
            ));
    	?>
    </div>
David Winterburn commented on Dec 13, 2019

Hi,

Your excel view file should have 2 levels of div like this:

<div sheet-name="sheet1">
    <div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Enquiry Report
    </div>

    <div>
    	<?php
    	Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo',
              'CustomerName',
              'Email',
              'city',
              'state',
              'country',
              'ContactNumber',
              'salesManger'
            ),
            ));
    	?>
    </div> 
</div>

The 1st level divs are for sheet and the 2nd ones are text/table/chart inside a sheet. For more information please check this documentation:

https://www.koolreport.com/docs/excel/export_to_excel/#excel-export-template-(version-%3E=-6.0.0)

Thanks!

David Winterburn commented on Dec 13, 2019

Hi,

Your excel view file should have 2 levels of div like this:

<div sheet-name="sheet1">
    <div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Enquiry Report
    </div>

    <div>
    	<?php
    	Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo',
              'CustomerName',
              'Email',
              'city',
              'state',
              'country',
              'ContactNumber',
              'salesManger'
            ),
            ));
    	?>
    </div> 
</div>

The 1st level divs are for sheets and the 2nd ones are text/table/chart inside a sheet. For more information please check this documentation:

https://www.koolreport.com/docs/excel/export_to_excel/#excel-export-template-(version-%3E=-6.0.0)

Thanks!

Sowmya commented on Dec 13, 2019

Yes Sir, I also done like this only.

<div sheet-name="<?php echo $sheet1; ?>">

<?php
    $styleArray =[
        -------
        -------]
?>
<div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Enquiry Report
    </div>

    <div>
    	<?php
    	Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo',
              'CustomerName',
              'Email',
              'city',
              'state',
              'country',
              'ContactNumber',
              'salesManger'
            ),
            ));
    	?>
    </div>
David Winterburn commented on Dec 13, 2019

Would you please upload your exported excel file and send us a link to see its content? Thanks!

Sowmya commented on Dec 17, 2019

Dear Sir, I sent the mail to "support@koolreport.com" from my mail id "sowmya.g@icsoft.co.in". In that mail I attached my coding files and output files too.

Please check and give me the solution as early as possible...

David Winterburn commented on Dec 17, 2019

Hi Sowmya,

Checking your excel view file, I think you lack a closing </div> at the end for

<div sheet-name="<?php echo $sheet1; ?>">

Please use the following content for your excel view file:

<div sheet-name="<?php echo $sheet1; ?>">

    <div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
        Enquiry Report
    </div>

    <div>
    	<?php
    	Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo',
              'CustomerName',
              'Email',
              'city',
              'state',
              'country',
              'ContactNumber',
              'salesManger'
            ),
            ));
    	?>
    </div> 

</div>

and let us know the result. Thanks!

Sowmya commented on Dec 17, 2019

Yes Sir, I closed the <div> tag. But still same error.

David Winterburn commented on Dec 17, 2019

Ok, please try the following content for excel view file and let me know the result:

<div sheet-name="sheet1">

    <div cell="A1" range="A1:H1" >
        Enquiry Report
    </div>
</div> 

If this works, please try the next one:

<div sheet-name="sheet1">

    <div>
    	<?php
    	Table::create(array(
            "dataSource" => $this->dataStore('enquiry'),
            "columns"=>array(
              'EnqRefNo'
            ),
            ));
    	?>
    </div> 

</div> 

Thanks!

Sowmya commented on Dec 17, 2019

No sir, same Error message as above.

David Winterburn commented on Dec 17, 2019

Please change your export function in Enquiry.php like this:

    public function export()
    {      
      ob_start();
      include APPPATH."reports\EnquiryReport.php";
      $report = new EnquiryReport;
      $report->run();
      ob_end_clean();
      $report->exportToExcel('EnquiryReportExcel')->toBrowser("EnquiryReport.xlsx");
    }

Thanks!

Sowmya commented on Dec 17, 2019
public function export()
    {      
      //$this->load->helper('url');
      //$this->load->database('MainiDM');
      ob_start();
      include APPPATH."reports\EnquiryReport.php";
      $report = new EnquiryReport;
      $report->run();
      ob_end_clean();
      $report->exportToExcel('EnquiryReportExcel')->toBrowser("EnquiryReport.xlsx");
    }

But Same Error sir.

Sowmya commented on Dec 17, 2019

Is there any Excel version problem?

David Winterburn commented on Dec 17, 2019

Please send us your latest php code and exported excel file via email. Thanks!

Sowmya commented on Dec 17, 2019

Yes sir I sent the mail from sowmya.g@icsoft.co.in. Please check the attached files.

Thank you....

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