I do this all the time from PHP. Here are the functions that I use:
function sendHeader($FileName)
{
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
$DispositionHeader = "Content-Disposition: attachment;filename=" .
$FileName . ".xls";
header($DispositionHeader);
header("Content-Transfer-Encoding: binary");
}
function xlsBOF()
{
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF()
{
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value)
{
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value )
{
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
And here is how I would use these functions:
$FileName = "MyFileName";
sendHeader($FileName);
xlsBOF();
//xlsWriteLabel($Row, $Col, $Value );
xlsWriteLabel(0, 0, "Name");
xlsWriteLabel(0, 1, "Age");
$xlsRow = 1;
arsort($theArrayIWantToSend);
foreach ($theArrayIWantToSend as $key => $value)
{
//xlsWriteLabel($Row, $Col, $Value );
xlsWriteLabel($xlsRow, 0, trim($key));
//xlsWriteNumber($Row, $Col, $Value );
xlsWriteNumber($xlsRow, 1, $value);
$xlsRow++;
}
xlsEOF();
You use xlsWriteLabel to write a string and xlsWriteNumber to write a
number.
--- In [email protected], "aphexyuri" <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> Help will be greatly appreciated...
>
> I need to make a .xls file available for download with data from a
> datagrid.
>
> I'm using AMFPHP, as the datagrid info can be a lot, but i'm having
> trouble prompting the user for the download.
>
> The data gets to AMFPHP ok, then I build tab delimited string from an
> incomming array, and that is where I'm stuck...getting that string to
> a .xml file prompt for download, without saving the file to the
server.
>
> Any help please?
>