Page 1 of 1

Custom File Export to Excel

Posted: Tue Jul 04, 2017 12:12 am
by andyrav

Hi
Can anyone help me to create a button in a Custom file to export a query into Excel?
so i have ..
$sql = "Query";
echo $db->ExecuteHtml($sql, array( "fieldcaption" => TRUE, "tablename" => array("status")));
Displays the result
then i would like a button to click on to export it into excel.

many thanks in advanced


Re: Custom File Export to Excel

Posted: Tue Jul 04, 2017 11:20 am
by arbei

You need to refer to the function "ExportData" in the generated files and write your own script to handle the export.

If you need export feature, you better create a view for the table instead of using Custom File.


Re: Custom File Export to Excel

Posted: Tue Jul 04, 2017 4:17 pm
by andyrav

Thanks, can you help i have no idea how to do this?
Just need a button to click on the download the export.

cheers


Re: Custom File Export to Excel

Posted: Thu Jul 06, 2017 9:52 am
by arbei
  1. Create a button with the link that has a parameter to tell the custom page you need to export.
    e.g. <Custom Page>.php?export=excel

  2. In the custom page, you need to check the parameter and handle the export.
    e.g.

if (@$_GET["export"] == "excel") {
//code to perform the export.
}

You can refer to the function "ExportData" in the generated files and write your own script to handle the export.

As said:
If you need export feature, you better create a view for the table instead of using Custom File.


Re: Custom File Export to Excel

Posted: Tue Nov 07, 2017 12:32 am
by andyrav

Hi
Can anyone help with a example on who to use the ExportData function from within a custom page?
many thanks


Re: Custom File Export to Excel

Posted: Wed Nov 08, 2017 11:13 am
by mobhar

arbei wrote:
You can refer to the function "ExportData" in the generated files and write your
own script to handle the export.

See and learn the code from "ExportData" function in the generated *list and/or *view.php files.