Get KoolPHP UI with 30% OFF!

Export to excel generate a blank page

ZTE Services Deutschland GmbH
Hi,
I tried to export a datagrid into excel file but I get a blank page. Here is my code:
<?php
	
	require "KoolControls/KoolGrid/koolgrid.php";
	require "KoolControls/KoolAjax/koolajax.php";
	$koolajax->scriptFolder = "KoolControls/KoolAjax";
	require "KoolControls/KoolGrid/ext/datasources/MySQLiDataSource.php";
	
	
	$db_con = mysql_connect('localhost','r51945ztea_admin','zteparola1');
    mysql_select_db("r51945ztea_zte", $db_con);
	
	
    $ds= new MySQLDataSource($db_con);
	$ds->SelectCommand = "SELECT `id`,`TAS`, `request`, `phone_number`, `comments`, `coordinator`, `technician_date`, `Status` from technician";
	$ds->UpdateCommand = "update technician set comments='@comments', coordinator='@coordinator', Status='@Status' where id='@id'";
 
	
	$gridTech = new KoolGrid("gridTech");
	$gridTech->scriptFolder = "KoolControls/KoolGrid";
	$gridTech->styleFolder="sunset";
	
	
	$gridTech->AjaxEnabled = true;
	$gridTech->AjaxLoadingImage =  $KoolControlsFolder."/KoolAjax/loading/5.gif";
	$gridTech->DataSource = $ds;
	$gridTech->MasterTable->Pager = new GridPrevNextAndNumericPager();
	$gridTech->Width = "1500px";
	$gridTech->ColumnWrap = true;
	$gridTech->AllowEditing = true;
	$gridTech->RowAlternative = true;
	$gridTech->MasterTable->Pager->PageSize = 10;
	
	$column = new GridBoundColumn();
	$column->DataField = "id";
	$column->ReadOnly = true;
	$column->Visible = false;
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "TAS";
	$column->HeaderText = "TAS";
	$column->ReadOnly = true;
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "request";
	$column->HeaderText = "Request";
	$column->ReadOnly = true;
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "phone_number";
	$column->HeaderText = "Phone Number";
	$column->ReadOnly = true;
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "coordinator";
	$column->HeaderText = "Coordinator";
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridTextAreaColumn();
	$column->DataField = "comments";
	$column->HeaderText = "Comments";
	$column->Width = "200px";
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "technician_date";
	$column->HeaderText = "Date";
	$column->Width = "180px";
	$column->ReadOnly = true;
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "Status";
	$column->HeaderText = "Status";
	$column->AddItem("Open");
	$column->AddItem("Closed");
	$column->Sort = -1;
	$gridTech->MasterTable->AddColumn($column);
	
	$column = new GridEditDeleteColumn();
	$column->ShowDeleteButton = false;
	$column->Align = "center";
	$gridTech->MasterTable->AddColumn($column);
	
	$gridTech->MasterTable->EditSettings->Mode = "Inline";
    $gridTech->Process();
	
	if(isset($_POST["IgnorePaging"]))
	{
		$gridTech->ExportSettings->IgnorePaging = true;
	}
	if(isset($_POST["ExportToExcel"]))
	{
		ob_end_clean();
		$gridTech->GetInstanceMasterTable()->ExportToExcel();
	}
		
?>
			<script type="text/javascript">
			   setInterval(function(){
				   gridTech.refresh();
				   gridTech.commit();
			   }, 300000);
			</script>
			
<?php	
	$db_con = mysql_connect('localhost','r51945ztea_admin','zteparola1');
    mysql_select_db("r51945ztea_zte", $db_con);
    
	$ds= new MySQLDataSource($db_con);
	$ds->SelectCommand = "SELECT `id`, `station_name`, `request`, `phone_number`, `comments`, `coordinator`, `konfig_date`, `Status` from konfig";
	$ds->UpdateCommand = "update konfig set comments='@comments', coordinator='@coordinator', Status='@Status' where id='@id'";
	
	$gridKonfig = new KoolGrid("gridKonfig");
	$gridKonfig->scriptFolder = "KoolControls/KoolGrid";
	$gridKonfig->styleFolder="sunset";
	
	
	$gridKonfig->AjaxEnabled = true;
	$gridKonfig->DataSource = $ds;
	$gridKonfig->MasterTable->Pager = new GridPrevNextAndNumericPager();
	$gridKonfig->Width = "1500px";
	$gridKonfig->ColumnWrap = true;
	$gridKonfig->AllowEditing = true;
	$gridKonfig->RowAlternative = true;
	
	$gridKonfig->MasterTable->Pager->PageSize = 10;
	
	$column = new GridBoundColumn();
	$column->DataField = "id";
	$column->ReadOnly = true;
	$column->Visible = false;
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "station_name";
	$column->HeaderText = "Station Name";
	$column->ReadOnly = true;
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "request";
	$column->HeaderText = "Request";
	$column->ReadOnly = true;
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "phone_number";
	$column->HeaderText = "Phone Number";
	$column->ReadOnly = true;
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "coordinator";
	$column->HeaderText = "Coordinator";
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridTextAreaColumn();
	$column->DataField = "comments";
	$column->HeaderText = "Comments";
	$column->Width = "200px";
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "konfig_date";
	$column->HeaderText = "Date";
	$column->Width = "180px";
	$column->ReadOnly = true;
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "Status";
	$column->HeaderText = "Status";
	$column->AddItem("Open");
	$column->AddItem("Closed");
	$column->Sort = -1;
	$gridKonfig->MasterTable->AddColumn($column);
	
	$column = new GridEditDeleteColumn();
	$column->ShowDeleteButton = false;
	$column->Align = "center";
	$gridKonfig->MasterTable->AddColumn($column);
	
	$gridKonfig->MasterTable->EditSettings->Mode = "Inline";
	
	$gridKonfig->Process();
	
	if(isset($_POST["IgnorePaging"]))
	{
		$gridKonfig->ExportSettings->IgnorePaging = true;
	}
	
	if(isset($_POST["ExportToExcel"]))
	{
		ob_end_clean();
		$gridKonfig->GetInstanceMasterTable()->ExportToExcel();
	}	
?>
			<script type="text/javascript">
			   setInterval(function(){
				   gridKonfig.refresh();
				   gridKonfig.commit();
			   }, 300000);
			</script>
 
 <?php	
	$db_con = mysql_connect('localhost','r51945ztea_admin','zteparola1');
    mysql_select_db("r51945ztea_zte", $db_con);
    
	$ds= new MySQLDataSource($db_con);
	$ds->SelectCommand = "SELECT `id`, `CRQ`, `station_name`, `phone_number`, `comments`, `coordinator`, `other_date`, `Status` FROM other_bo ";
	$ds->UpdateCommand = "update other_bo set comments='@comments', coordinator='@coordinator', Status='@Status' where id='@id'";
	
	$gridOther = new KoolGrid("gridOther");
	$gridOther->scriptFolder = "KoolControls/KoolGrid";
	$gridOther->styleFolder="sunset";
	
	
	$gridOther->AjaxEnabled = true;
	$gridOther->DataSource = $ds;
	$gridOther->MasterTable->Pager = new GridPrevNextAndNumericPager();
	$gridOther->Width = "1500px";
	$gridOther->ColumnWrap = true;
	$gridOther->AllowEditing = true;
	$gridOther->RowAlternative = true;
	
	$gridOther->MasterTable->Pager->PageSize = 10;
	
	$column = new GridBoundColumn();
	$column->DataField = "id";
	$column->ReadOnly = true;
	$column->Visible = false;
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "CRQ";
	$column->HeaderText = "CRQ";
	$column->ReadOnly = true;
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "station_name";
	$column->HeaderText = "Station Name";
	$column->ReadOnly = true;
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "phone_number";
	$column->HeaderText = "Phone Number";
	$column->ReadOnly = true;
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "coordinator";
	$column->HeaderText = "Coordinator";
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridTextAreaColumn();
	$column->DataField = "comments";
	$column->HeaderText = "Comments";
	$column->Width = "200px";
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "other_date";
	$column->HeaderText = "Date";
	$column->Width = "180px";
	$column->ReadOnly = true;
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "Status";
	$column->HeaderText = "Status";
	$column->AddItem("Open");
	$column->AddItem("Closed");
	$column->Sort = -1;
	$gridOther->MasterTable->AddColumn($column);
	
	$column = new GridEditDeleteColumn();
	$column->ShowDeleteButton = false;
	$column->Align = "center";
	$gridOther->MasterTable->AddColumn($column);
	
	$gridOther->MasterTable->EditSettings->Mode = "Inline";
	$gridOther->Process();
	
	if(isset($_POST["IgnorePaging"]))
	{
		$gridOther->ExportSettings->IgnorePaging = true;
	}
	
	if(isset($_POST["ExportToExcel"]))
	{
		ob_end_clean();
		$gridOther->GetInstanceMasterTable()->ExportToExcel();
	}
?>
		
			<script type="text/javascript">
			   setInterval(function(){
				   gridOther.refresh();
				   gridOther.commit();
			   }, 300000);
			</script>
			
<?php	
	$db_con = mysql_connect('localhost','r51945ztea_admin','zteparola1');
    mysql_select_db("r51945ztea_zte", $db_con);
    
	$ds= new MySQLDataSource($db_con);
	$ds->SelectCommand = "SELECT `id`, `CRQ`, `station_name`, `phone_number`, `comments`, `coordinator`, `abel_date`, `Status` FROM abel_bo ";
	$ds->UpdateCommand = "update abel_bo set comments='@comments', coordinator='@coordinator', Status='@Status' where id='@id'";
	
	$gridAbel = new KoolGrid("gridAbel");
	$gridAbel->scriptFolder = "KoolControls/KoolGrid";
	$gridAbel->styleFolder="sunset";
	
	
	$gridAbel->AjaxEnabled = true;
	$gridAbel->DataSource = $ds;
	$gridAbel->MasterTable->Pager = new GridPrevNextAndNumericPager();
	$gridAbel->Width = "1500px";
	$gridAbel->ColumnWrap = true;
	$gridAbel->AllowEditing = true;
	$gridAbel->RowAlternative = true;
	
	$gridAbel->MasterTable->Pager->PageSize = 10;
	
	$column = new GridBoundColumn();
	$column->DataField = "id";
	$column->ReadOnly = true;
	$column->Visible = false;
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "CRQ";
	$column->HeaderText = "CRQ";
	$column->ReadOnly = true;
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "station_name";
	$column->HeaderText = "Station Name";
	$column->ReadOnly = true;
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "phone_number";
	$column->HeaderText = "Phone Number";
	$column->ReadOnly = true;
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "coordinator";
	$column->HeaderText = "Coordinator";
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridTextAreaColumn();
	$column->DataField = "comments";
	$column->HeaderText = "Comments";
	$column->Width = "200px";
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridBoundColumn();
	$column->DataField = "abel_date";
	$column->HeaderText = "Date";
	$column->Width = "180px";
	$column->ReadOnly = true;
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridDropDownColumn();
	$column->DataField = "Status";
	$column->HeaderText = "Status";
	$column->AddItem("Open");
	$column->AddItem("Closed");
	$column->Sort = -1;
	$gridAbel->MasterTable->AddColumn($column);
	
	$column = new GridEditDeleteColumn();
	$column->ShowDeleteButton = false;
	$column->Align = "center";
	$gridAbel->MasterTable->AddColumn($column);
	
	$gridAbel->MasterTable->EditSettings->Mode = "Inline";
	$gridAbel->Process();
	
	if(isset($_POST["IgnorePaging"]))
	{
		$gridAbel->ExportSettings->IgnorePaging = true;
	}
	
	if(isset($_POST["ExportToExcel"]))
	{
		ob_end_clean();
		$gridAbel->GetInstanceMasterTable()->ExportToExcel();
	}
?>
			<script type="text/javascript">
			   setInterval(function(){
				   gridAbel.refresh();
				   gridAbel.commit();
			   }, 300000);
			</script>
 
<html>
    <head>
        <title></title>
        <?php echo $koolajax->Render();?>
		
			<style >
	body {
		background-color: #e3e3e3;
	}
	
	.container {
		background-color: #e3e3e3;
		width: 98%;
		height: 965px;
		margin: auto;
		display: block;
		position: relative;
	}
	.wrapper {
		padding: 0px 47px 12px 22px;
	}
	.tech {
		float: left;
	}
	.konfig {
		float: left;
	}
	.abelBo {
		float: left;
	}
	.otherBo {
		float: left;
	}
	
	.row {
	}
	
	h3 {
		text-align: center;
		padding-bottom: 10px;
	}
		
	</style>
	
    </head>
    <body>
	    <div id="container" class="container">
	    	<div class="row">
				<div class="wrapper tech" id="technician">
				<h3>Technician</h3>
				
					<form id="techGrid" method="post">
					    <?php echo $koolajax->Render();?>
                        	    <div style="margin-bottom:10px;padding:10px;width:635px;background:#e3e3e3;border:solid 1px #e3e3e3;">
                        		<input type="checkbox" id="IgnorePaging" name="IgnorePaging"/> <label for="IgnorePaging">Ignore Paging</label>
                        		<br/><br/>
                        		<input type="submit" name="ExportToExcel" value = "Export to Excel" />
                        	    </div>
						        <?php echo $gridTech->Render();?>
					</form>
				</div>
			</div>
			
	    	<div class="row">
				<div class="wrapper konfig" id="konfig">
					<h3>Konfig</h3>
					
					<form id="konfigGrid" method="post">
					    
					    <?php echo $gridKonfig->Render();?>
					</form>
				</div>
			</div>
			
			<div class="row">
				<div class="wrapper abelBo" id="abel">
				<h3>External BO (Nokia/Huawei/Abel..)</h3>
				
				
					<form id="abelBoGrid" method="post">
						
						
						<?php echo $gridAbel->Render();?>
					</form>
				</div>
			</div>
			
			<div class="row">
				<div class="wrapper otherBo" id="other">
					<h3>Other</h3>
					
					
						<form id="otherBoGrid" method="post">
						    
							<?php echo $gridOther->Render();?>
						</form> 
				</div>
	        </div>
		</div>
		
    </body>
</html>
Posted Jul 25, 2017 , edited Jul 25, 2017 Kool
ZTE Services Deutschland GmbH
For linux I changed the path like this and it works.
/library/PHPExcel/Classes/PHPExcel.php
/library/PHPExcel/Classes/PHPExcel/Cell.php
/library/PHPExcel/Classes/PHPExcel/IOFactory.php
Posted Jul 25, 2017 Kool
ZTE Services Deutschland GmbH
Now I have another problem. I have 4 data grid on the page and when I try to export to excel, it doesn't matter for what data grid I try to export, it works only for the first one!
Posted Jul 25, 2017 Kool
Anthony Amolochitis
That request may need a support ticket.
I tried to export the child grids in the past, but could not figure it out. I just built my own csv file and exported it myself.
I'm curious what you will find.
Posted Jul 26, 2017 Kool
Jayme
Hello,
I have made my own codo to export to Excel also.
The thread at https://www.koolphp.net/forum/threads/294.1/excel-exporting-generates-a-blank-page.html was not answered, and I was not using child grids but a simple one.
Kind regards.
Posted Aug 2, 2017 Kool
Nic Chapleau
Where exactly did you change the PHPExcel library path for it to work. I am having the same issue on PHP 7.1 CentOS 7.
Thanks,
Nic.
Posted Nov 28, 2017 Kool
Nic Chapleau
Using v8.9 too.
Posted Nov 28, 2017 , edited Nov 28, 2017 Kool
David
Hi Nic,
Thanks for your feedback! We've tested exporting to Excel using your file and it worked well. So the problem might be relating to including the correct path to PHPExcel.
In case your OS is case sensitive please make sure the following paths are correct case sensitively:
        require_once $_path . '/library/PHPExcel/Classes/PHPExcel.php';
        require_once $_path . '/library/PHPExcel/Classes/PHPExcel/Cell.php';
        require_once $_path . '/library/PHPExcel/Classes/PHPExcel/IOFactory.php';

The folder library should be in the folder KoolControls. Please try this and let us know the result. Thanks!
Posted Nov 30, 2017 Kool
Nic Chapleau
I am glad that you got everything working but still no go at my end. I have included
$KoolControlsFolder = "../libs/KoolPHPSuite/KoolControls";
require_once $KoolControlsFolder."/library/PHPExcel/Classes/PHPExcel.php";
require_once $KoolControlsFolder."/library/PHPExcel/Classes/PHPExcel/Cell.php";
require_once $KoolControlsFolder."/library/PHPExcel/Classes/PHPExcel/IOFactory.php";

at the beginning of my test file and I still get a blank XLS page. COuld it have anything to do with the Linux version or the PHP version?
Nic.
Posted Nov 30, 2017 Kool
Michael Scholl
I just tried on the sample page and got a blank page. csv and word exports worked OK
Posted Aug 5, 2019 Kool