KoolReport's Forum

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

Excel export #201

Open bysystem opened this topic on on Jan 24, 2018 - 8 comments

bysystem commented on Jan 24, 2018

Dear support team,

I need you help for the package Export a table to an Excel file. Allthough I've followed the example documentation for the Excel export, it's not possible to triggering the export!

My autorepchart.php

class autorepchart extends koolreport\KoolReport
{
	use \koolreport\clients\FontAwesome; //für die Collapse + icons
	use \koolreport\clients\Bootstrap;
	use \koolreport\inputs\Bindable;
	use \koolreport\inputs\POSTBinding;
	use \koolreport\export\Exportable;
	use \koolreport\excel\ExcelExportable;

My autorepchart.view.php

<script type="text/javascript">
function doExportExcel()
{
	//alert(1);
    var _form = document.getElementById("parameterForm");
    _form.action = "exportexcel.php";
    _form.submit();
	_form.action = "index.php";
}
</script>

...


	<div id="col1">
		<h3>&nbsp;&nbsp;<img src="icon_barchart.png"/>&nbsp;&nbsp;&nbsp;Tabellarische Detailansicht</h3>
		<div style="float:right"><button style="min-width:200px;" onclick="doExportExcel()" class="btn btn-primary">Export<br />Test</button></div>		
		<?php
			Table::create(array(
				"dataStore"=>$this->dataStore('AutoRepTabelle'),
				"showFooter"=>"bottom",
				"columns"=>array(
					"WerbegruppeVerbund"=>array(
						"label"=>"Werbegruppe",							
					),
					"KdName"=>array(
						"label"=>"Kundenname",
					),
					"Ort"=>array(
						"label"=>"Kundenort",
					),
					"ArtBez"=>array(
						"label"=>"Artikel",
					),	
					"Verkaufsmenge"=>array(
						"label"=>"Menge",
						"footer"=>"sum",
						"footerText"=>"<span style='font-size:150%;'><b>@value</b></span>",									
						"cssStyle"=>"text-align:right;font-weight:bold;font-size:100%;",
					),
				),
				"removeDuplicate"=>array("WerbegruppeVerbund", "KdName", "Ort", "ArtBez"),				
			));
		?>		
	</div>	

My exportexcel.php

error_reporting(0);
require_once "autorepchart.php";
$report = new autorepchart;
$report->run()->exportToExcel()
->toBrowser("autorepchartexcel.xlsx");

If I click in the "Test export" button nothing happen! I trie to alert(1) to test whether the JavaScript is working or not: It works!

What could be the reason?

Kind regards,

bysystem commented on Jan 29, 2018

Dear support team,

I can imagine you had a lot of todos related to the newest koolreport version!

May I ask you for a hint related to the issue above?

Kind regards

David Winterburn commented on Jan 30, 2018

Hi bysystem,

I could not see your form element "parameterForm" in this view file, is it in your index.php? If it's not there, please add the form to your page so the javascript function can run correctly. Otherwise, you could change the button's onclick function with a link href to "excelexport.php" directly and see how it goes. Please also try to run export using our examples in the package and let us know if the export works? Thanks!

bysystem commented on Jan 30, 2018

Dear Dave,

I never had needed a form tag (also for my PDF exports) as I've used always the javascript above for triggering the Export button. But I've now added the link href to "excelreport.php" (see below). Unfortunately I get still a blank page and nothing happens!

		<!-- <div style="float:right"><button style="min-width:200px;" onclick="doExportExcel()" class="btn btn-primary">Export<br />Test</button></div>  -->
		<div style="float:right"><a href="exportexcel.php">Export</a></div>			
		<?php
			Table::create(array(
				"dataStore"=>$this->dataStore('AutoRepTabelle'),
				"showFooter"=>"bottom",

Any further idea?

David Winterburn commented on Jan 31, 2018

Hi bysystem,

It seems strange. Can you please try exporting with our examples in the package and let us know the result? Thanks!

bysystem commented on Jan 31, 2018

Dear David,

there are some export examples for PDF export but not for EXCEL export.

Do you have a link for me for such an EXCEL export example?

Kind regards,

bysystem commented on Feb 1, 2018

Dear David,

still need your help! I just tried the following from the forum examples and I can now download an excel file BUT the content of the Excel file is empty!!!

Here is my setup for the dataStore:

		// TABELLE: Detailansicht		
		if(count($this->params["Werbegruppe"])>0){$whereWerbegruppe="WerbegruppeVerbund IN (:Werbegruppe) ";}else{$whereWerbegruppe="WerbegruppeVerbund IS NOT NULL ";}			
		if(count($this->params["Ort"])>0){$whereOrt="Ort IN (:Ort) ";}else{$whereOrt="Ort IS NOT NULL ";}		
		if(count($this->params["KdName"])>0){$whereKdName="KdName IN (:KdName) ";}else{$whereKdName="KdName IS NOT NULL ";}	
		if(count($this->params["ADBezirk"])>0){$whereADBezirk="ADBezirk IN (:ADBezirk) ";}else{$whereADBezirk="ADBezirk IS NOT NULL ";}	
		if(count($this->params["ProdGruppe"])>0){$whereProdGruppe="ProdGruppe IN (:ProdGruppe) ";}else{$whereProdGruppe="ProdGruppe IS NOT NULL ";}		
		if(count($this->params["ArtBez"])>0){$whereArtBez="ArtBez IN (:ArtBez) ";}else{$whereArtBez="ArtBez IS NOT NULL ";}		
		if(count($this->params["Quartal"])>0){$whereQuartal="Quartal IN (:Quartal) ";}else{$whereQuartal="Quartal IS NOT NULL ";}		
		if(count($this->params["Monat"])>0){$whereMonat="Monat IN (:Monat) ";}else{$whereMonat="Monat IS NOT NULL ";}		

        $this->src('autorep')
		->query("
			SELECT
				Createdate, WerbegruppeVerbund, Monat, Quartal, KdName, Ort, ProdGruppe, ArtBez, BestandHaendler_aktuell, BestandZentrale_aktuell, Umsatz, Verkaufsmenge
			FROM Reporting.autorep_v_noNulls
			WHERE 
				Sell = (:Sell) AND
				KdName IN (:KdName) AND
				$whereWerbegruppe AND
				$whereKdName AND
				$whereOrt AND
				$whereADBezirk AND
				$whereProdGruppe AND
				$whereArtBez AND
				$whereQuartal AND
				$whereMonat AND
				(Createdate BETWEEN (:vonDatum) AND (:bisDatum))
				
			")->params(array(
			":Sell"=>$this->params["Sell"],
			":KdName"=>$this->params["KdName"],
			":Werbegruppe"=>$this->params["Werbegruppe"],
			":KdName"=>$this->params["KdName"],
			":Ort"=>$this->params["Ort"],
			":ADBezirk"=>$this->params["ADBezirk"],
			":ProdGruppe"=>$this->params["ProdGruppe"],
			":ArtBez"=>$this->params["ArtBez"],
			":Quartal"=>$this->params["Quartal"],
			":Monat"=>$this->params["Monat"],
			":vonDatum"=>$this->params["vonDatum"],
			":bisDatum"=>$this->params["bisDatum"]			
			))		

		->pipe(new Sort(array(
			"WerbegruppeVerbund"=>"asc",
			"KdName"=>"asc",
			"Ort"=>"asc"
		)))
		->pipe(new FillNull(array(
			"targetColumns"=>("KdName"),
			"newValue"=>"???"
		)))		
        ->pipe($this->dataStore('AutoRepTabelle'));

My view.php where I added now a form tag:

		<div style="float:right">
			<form method="post" action="exportexcel.php">
				<button class="btn btn-primary">Export</button>
			</form>
		</div>		
		
		<?php
			Table::create(array(
				"dataStore"=>$this->dataStore('AutoRepTabelle'),
				"showFooter"=>"bottom",
				"columns"=>array(
					"WerbegruppeVerbund"=>array(
						"label"=>"Werbegruppe",
						//"formatValue"=>function($value)
						//{
						//	return ""; //Leere Spalte in der Tabelle
						//},
						//"footerText"=>"<span style='font-size:150%;'><b>".$Werbegruppe_Verbund."</b></span>",									
					),
					"KdName"=>array(
						"label"=>"Kundenname",
					),
					"Ort"=>array(
						"label"=>"Kundenort",
					),
					"ArtBez"=>array(
						"label"=>"Artikel",
					),	
					"Verkaufsmenge"=>array(
						"label"=>"Menge",
						"footer"=>"sum",
						"footerText"=>"<span style='font-size:150%;'><b>@value</b></span>",									
						"cssStyle"=>"text-align:right;font-weight:bold;font-size:100%;",
					),
				),
				"removeDuplicate"=>array("WerbegruppeVerbund", "KdName", "Ort", "ArtBez"),				
			));
		?>

And the exportexcel.php (tried it also with simple run()->exportToExcel() see below the line commented out >> I get a blank page!

error_reporting(0);
require_once "autorepchart.php";
$report = new autorepchart;

// $report->run()->exportToExcel()->toBrowser("autorepchart.xls");

$report->run()->exportToExcel(array(
  "dataStores" => array(
    'AutoRepTabelle'
  )
))->toBrowser("autorepchart.xls");

Any idea?

David Winterburn commented on Feb 2, 2018

Hi bysystem,

Where are your inputs where you bind params with? Please put those inputs inside your form tag and see if export returns data. Thanks!

bysystem commented on Feb 5, 2018

Hi David,

you had right! In my <form> tag the id "parameterForm" was missing which I've defined in the script as var _form:

<script type="text/javascript"> function doExportExcel() {

//alert(1);
var _form = document.getElementById("parameterForm");
_form.action = "exportexcel.php";
_form.submit();
_form.action = "index.php";

} </script>

It works fine now! Thx a lot for your hints!

Kind regards,

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

Export