View Full Version : How do I exprot data in a grid to an Excel file?

02-09-2009, 03:55 PM
I Created a link (ToExcelLink) on my page (outside the grid) to export the data in the Grid to an excel file. Part of the export works because the excel file is created with the controls of my page. But the grid with the data is missing. What am I missing? :o

The link's Default value is "Export to Excel"
The href source is "Score_Card_Show_All.ccp" (My page's name)
The link parameter name is "export"
The link parameter source type is "Expression"
The link parameter source is "1"

The code in my grid's BeforeSelect event:

function EditableGrid1_BeforeSelect(& $sender)
$EditableGrid1_BeforeSelect = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $EditableGrid1; //Compatibility

if (CCGetFromGet("export") == "1") {
//Show up to 10,000 records
$EditableGrid1->PageSize = 10000;
$EditableGrid1->ds->PageSize = 10000;
//Hide the Navigator
$EditableGrid1->Navigator->Visible = false;

return $EditableGrid1_BeforeSelect;

The code in my page's OnInitializeView event:

function Page_OnInitializeView(& $sender)
$Page_OnInitializeView = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $Score_Card_Show_All; //Compatibility

global $ToExcelLink;
global $Header;
global $Link1;

$ExportFileName = "Report.xls";
if (CCGetFromGet("export") == "1") {
//Hide the ToExcelLink Link
$ToExcelLink->Visible = false;
$Link1->Visible = false;
$Header->Visible = false;

//Set Content type to Excel
header("Content-Type: application/vnd.ms-excel");
//Fix IE 5.0-5.5 bug with Content-Disposition=attachment
if (strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 5.5;") ||
strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 5.0;")) {
header("Content-Disposition: filename=" . $ExportFileName);
} else {
header("Content-Disposition: attachment; filename=" . $ExportFileName);

return $Page_OnInitializeView;

02-09-2009, 05:36 PM
$ToExcelLink->Visible = false;
$Link1->Visible = false;
$Header->Visible = false;

I think you are confusing PHP with a client-side language (Javascript, etc). PHP is on the server side of things.

02-10-2009, 07:56 AM
Oops, sorry! New to this site. Will try to figure out how to move this thread to the correct forum.

02-10-2009, 03:46 PM
No problem, I'll move this.
What is this, json? It looks like PHP code, but it appears to have event handlers, so I'm not sure...
One of the client mods can always move it back :D

02-16-2009, 01:34 PM
I solved my issue my changing the link's preserve paramemters to 'GET and POST'. Used to be 'None'.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum