Get KoolPHP UI with 30% OFF!

Exporting data from Grid to EXCEL does not work

Gerd Huber
Hallo,
After clicking on the Button "Export to Excel" nothing happend, i don't get the File-dialog to Open EXCEL.
What is wrong?
Regards
Gerd
Posted Aug 7, 2015 Kool
David
Hi Gerd,
There might be some problem with the path to the PHPExcel library if you are on a linux machine (case-sensitive). Please check if the following case-sensitive paths exist in your KoolControls directory:
/library/PHPExcel/Classes/PHPExcel.php
/library/PHPExcel/Classes/PHPExcel/Cell.php
/library/PHPExcel/Classes/PHPExcel/IOFactory.php
Rgds,
Posted Aug 11, 2015 Kool
David
Hi Gerd,
If there're too many wrong case-sensitive paths in PHPExcel directory, I suggest you go to:
https://phpexcel.codeplex.com/
download the package there and extract it into the directory KoolControls/library to fix the path problem.
Rgds,
Posted Aug 11, 2015 Kool
Gerd Huber
Hallo David,
i have changed the path, but the result is the same.
Posted Aug 11, 2015 Kool
Abraham
Hi there Gerd. you may need to post your code.. there is mybe a problem when getting the id of the excel button from $_POST???
Posted Aug 11, 2015 Kool
Gerd Huber
Hallo Abraham,
here is my code, thanks.
Gerd
----------------------
$ds = new MySQLiDataSource($db);//This $db_con link has been created inside KoolPHPSuite/Resources/runexample.php

#$ds->DeleteCommand = "delete from `hhc_bilder02` WHERE `hhc_bilder02`.`ID_HHC_Bilder02`=@ID_HHC_Bilder02;";
$ds->SelectCommand = "SELECT
`hhc_titel`.`id_titel` ,
0 as auswahl,
`hhc_titel`.`dt_titel_bez`,
`hhc_titel`.`fk_titel_audio`,
CONCAT(`hhc_komponist`.`dt_komponist_name` ,', ', `hhc_komponist`.`dt_komponist_vorname` ) as komponist,
CONCAT(`hhc_bearbeiter`.`dt_bearbeiter_name` ,', ', `hhc_bearbeiter`.`dt_bearbeiter_vorname` ) as bearbeiter,
`hhc_verlag`.`dt_verlag_name`,
`hhc_stufe`.`dt_stufe_lbez`,
DATE_FORMAT(`hhc_titel`.`dt_titel_dauer`, '%i:%s') as dt_titel_dauer,
`hhc_bilder04`.`DT_Ordner_Stuecke` ,
case when(fk_titel_audio = 1)
then CONCAT('viewhhcSibelius.php?pn_nr=',`hhc_titel`.`id_titel`)
else CONCAT(`hhc_titel`.`dt_titel_bez`) end as link
,`dt_musikart_text`
, dt_titel_fuer_wertung
FROM
`hhc_titel`
LEFT OUTER JOIN `hhc_komponist` ON (`hhc_titel`.`fk_titel_komponist` = `hhc_komponist`.`id_komponist`)
LEFT OUTER JOIN `hhc_bearbeiter` ON (`hhc_titel`.`fk_titel_bearbeiter` = `hhc_bearbeiter`.`id_bearbeiter`)
LEFT OUTER JOIN `hhc_stufe` ON (`hhc_titel`.`fk_titel_stufe` = `hhc_stufe`.`id_stufe`)
LEFT OUTER JOIN `hhc_verlag` ON (`hhc_titel`.`fk_titel_verlag_erschienen` = `hhc_verlag`.`id_verlag`)
INNER JOIN `hhc_titel_detail` ON (`hhc_titel`.`id_titel` = `hhc_titel_detail`.`fk_id_titel`)
INNER JOIN `hhc_bilder04` ON (`hhc_titel_detail`.`fk_id_hhc_bilder04` = `hhc_bilder04`.`ID_HHC_Bilder04`)
INNER JOIN `hhc_musikart` ON (`hhc_titel`.fk_titel_musikart = `hhc_musikart`.id_musikart)
WHERE
(`hhc_titel`.`fk_titel_verlag` = 1) AND
(`hhc_titel`.`dt_titel_fuer_webpage` = -1) and
`hhc_titel_detail`.`fk_id_hhc_bilder04` = ". $_REQUEST["oart"] ."
ORDER BY
`hhc_titel`.`dt_titel_bez` ASC";
/*-------------------------*/
/* Grid-Definitionen */
/*-------------------------*/
$grid = new KoolGrid("grid");
$grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
$grid->AjaxLoadingImage = $KoolControlsFolder."/KoolAjax/loading/5.gif";
$grid->styleFolder = "sunset";
$grid->DataSource = $ds;
$grid->AjaxEnabled = true;
$grid->ExportSettings->FileName = "KoolGridExport_g";
$grid->AllowScrolling = true;
$grid->RowAlternative = true;
$grid->AllowDeleting = false;
$grid->Width = "1000px";
$grid->CharSet = "UTF-8" ;
$grid->AutoGenerateColumns = false;
$grid->MasterTable->Height = "500px";
# $grid->MasterTable->ColumnWidth = "150px";
$perpage = CON_anzahlzeilen;
$grid->PageSize = $perpage;
$grid->AllowSorting = true;
$grid->AllowHovering = true;
$grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
$grid->MasterTable->Pager->Position = "top+bottom";
$grid->Localization->Load($KoolControlsFolder."/KoolGrid/localization/de.xml");
// Link erzeugen
$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Titel";
$col->DataField = "dt_titel_bez";
$col->AllowFiltering = true;
$col->AllowSorting = true;
$col->Width = "150px";
$col->ItemTemplate = "<a href='{link}'>{dt_titel_bez}</a>";
$grid->MasterTable->AddColumn($col);

$col = new GridRowSelectColumn();
$col->HeaderText = "ID1";
$grid->MasterTable->AddColumn($col);
$col = new GridBooleanColumn();
$col->ReadOnly = true;
$col->HeaderText = "Auswahl";
$col->DataField = "auswahl";
$col->AllowFiltering = true;
$col->AllowSorting = true;
$col->UseCheckBox = true;
$col->Width = "50px";
$col->ItemTemplate = "{auswahl}";
$grid->MasterTable->AddColumn($col);

$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Komponist";
$col->DataField = "komponist";
$col->AllowFiltering = false;
$col->AllowSorting = true;
$col->Width = "110px";
$col->ItemTemplate = "{komponist}";
$grid->MasterTable->AddColumn($col);

$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Bearbeiter";
$col->DataField = "bearbeiter";
$col->AllowFiltering = false;
$col->AllowSorting = true;
$col->Width = "110px";
$col->ItemTemplate = "{bearbeiter}";
$grid->MasterTable->AddColumn($col);

$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Dauer";
$col->DataField = "dt_titel_dauer";
$col->AllowFiltering = false;
$col->Width = "40px";
$col->ItemTemplate = "{dt_titel_dauer}";
$grid->MasterTable->AddColumn($col);
$grid->Process();

$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Stufe";
$col->DataField = "dt_stufe_lbez";
$col->AllowFiltering = true;
$col->Width = "100px";
$col->ItemTemplate = "{dt_stufe_lbez}";
$grid->MasterTable->AddColumn($col);
$grid->Process();

$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Verlag";
$col->DataField = "dt_verlag_name";
$col->AllowFiltering = false;
$col->Width = "120px";
$col->ItemTemplate = "{dt_verlag_name}";
$grid->MasterTable->AddColumn($col);
$grid->Process();

$col = new GridCustomColumn();
$col->ReadOnly = true;
$col->HeaderText = "Musikart";
$col->DataField = "dt_musikart_text";
$col->AllowFiltering = true;
$col->Width = "100px";
$col->ItemTemplate = "{dt_musikart_text}";
$grid->MasterTable->AddColumn($col);


$grid->Process();

if(isset($_POST["IgnorePaging"]))
{
$grid->ExportSettings->IgnorePaging = true;
}

if(isset($_POST["ExportToExcel"]))
{
ob_end_clean();
$grid->GetInstanceMasterTable()->ExportToExcel();
}
if(isset($_POST["ExportToWord"]))
{
ob_end_clean();
$grid->GetInstanceMasterTable()->ExportToWord();
}
if(isset($_POST["ExportToCSV"]))
{
ob_end_clean();
$grid->GetInstanceMasterTable()->ExportToCSV();
}
if(isset($_POST["ExportToPDF"]))
{
ob_end_clean();
$grid->GetInstanceMasterTable()->ExportToPDF();
}


$Form_name = "Suche Noten";
echo ebene(1)."<FORM name=\"".$Form_name."\" class=\"decoration\" id=\"myform\" method=\"post\" accept-charset=\"".$charset_utf8."\" >\n";
?>
<?php echo $koolajax->Render();?>
<div style="margin-bottom:10px;padding:10px;width:635px;background:#DFF3FF;border:solid 1px #C6E1F2;">
<input type="checkbox" id="IgnorePaging" name="IgnorePaging"/> <label for="IgnorePaging">Ignore Paging</label>
<br/><br/>
<input type="submit" name="ExportToCSV" value = "Export to CSV" />
<input type="submit" name="ExportToExcel" value = "Export to Excel" />
<input type="submit" name="ExportToWord" value = "Export to Word" />
<input type="submit" name="ExportToPDF" value = "Export to PDF" />
</div>
<?php echo $grid->Render();?>
Posted Aug 13, 2015 Kool
Abraham
Hi there Gred.
Im afraid I find nothing unusual on your code..
but when I saw the line.. $grid->ExportSettings->FileName = "KoolGridExport_g"; it pops on my mind "there is mybe a problem with this".. soo have u tryed to remove this line and see whats happen?
also.. I prefer my ds->selectcommand to be cleaner. like having al the qry on mysql zide with a view, unless the qry is dynamic.
also when i find a problem where there seems not to be an actual problem I try a less complex and small code to test what i need to do.
please try to make small qry and grid and setup just an excel export button.. see what happen.
if this works.. then u can be like adding stuf to your test untill you find the actual problem.. like adding a bigger qry, adding more options to the grid.. etc..
mybe this is not soving your problem but I hope this points u to the right direction..
Remember you can always reinstall Koolphp ui.. to make shure its last and stable version.
good luck.
Just noticed... have u tryed to set the buttons inside the FormTag ??
see you are building a form from php echo and not in actual html tags.. try to set the buttons inside the form and see ig it works..
Posted Aug 13, 2015 Kool