I want to assemble data in a format which I can return as a downloadable .xls file.
I can create .csv files with no problem using "fputcsv", but the problem in using that construct for an .xls file is each row is terminated by comma.
I store a variable number of rows in an array like this
Using the chr(9) to insert a tab between columns. Then I read the array with the fputcsv into a temp file like this
where $fh is my file handle to my temporary file which I then download.
The output I get is
"Mr. ......","Mr. .....","Mr. .....
Then I force the download like this.
where $fullOutputname is a reference to the csv file I created. Note that "$ctype" = "applicatio n/vnd.ms-excel"
Of course the "fputcsv" is the problem. How can I properly assemble the data other than using fputcsv? To eliminate the comma between rows.
I can create .csv files with no problem using "fputcsv", but the problem in using that construct for an .xls file is each row is terminated by comma.
I store a variable number of rows in an array like this
Code:
$cData[] = $c["MRMRS"].chr(9). $c["FIRST"].chr(9). $c["LAST"].chr(9). $c["name"].chr(9). $c["addr1"].chr(9). $c["addr2"].chr(9). $c["city"].chr(9). $c["st"].chr(9). $c["zip"].chr(9). $c["GIFTCOUNT"].chr(13).chr(10);
Code:
fputcsv($fh, $cData);
The output I get is
"Mr. ......","Mr. .....","Mr. .....
Then I force the download like this.
Code:
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public');
header('Content-Description: File Transfer');
//header('Content-Type: plain/text');
header("Content-Type: $ctype");
header('Content-Disposition: attachment; filename='.$outputFileName);
header('Content-Transfer-Encoding: ascii');
header('Content-Length: ' . filesize($fullOutputName));
@readfile($fullOutputName);
Of course the "fputcsv" is the problem. How can I properly assemble the data other than using fputcsv? To eliminate the comma between rows.
Comment