473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Assembling data for an .xls download file

Claus Mygind
571 512MB
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
Expand|Select|Wrap|Line Numbers
  1.                     $cData[] =  $c["MRMRS"].chr(9).
  2.                                 $c["FIRST"].chr(9).
  3.                                 $c["LAST"].chr(9).
  4.                                 $c["name"].chr(9).
  5.                                 $c["addr1"].chr(9).
  6.                                 $c["addr2"].chr(9).
  7.                                 $c["city"].chr(9).
  8.                                 $c["st"].chr(9).
  9.                                 $c["zip"].chr(9).
  10.                                 $c["GIFTCOUNT"].chr(13).chr(10);
  11.  
Using the chr(9) to insert a tab between columns. Then I read the array with the fputcsv into a temp file like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. fputcsv($fh, $cData);
  3.  
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.
Expand|Select|Wrap|Line Numbers
  1.                 header('Pragma: public');
  2.                 header('Expires: 0');
  3.                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  4.                 header('Cache-Control: public');
  5.                 header('Content-Description: File Transfer');
  6.                 //header('Content-Type: plain/text');
  7.                 header("Content-Type: $ctype"); 
  8.                 header('Content-Disposition: attachment; filename='.$outputFileName);
  9.                 header('Content-Transfer-Encoding: ascii');
  10.                 header('Content-Length: ' . filesize($fullOutputName));
  11.  
  12.                 @readfile($fullOutputName);
  13.  
where $fullOutputname is a reference to the csv file I created. Note that "$ctype" = "application/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.
Apr 9 '12 #1

✓ answered by Claus Mygind

It appears the real solution is to download and install phpExcel

Then it is easy to create a completed and formatted excel spread sheet.

2 1947
Dormilich
8,658 Expert Mod 8TB
hm, isn’t the comma CSV’s row delimiter (like in Comma Separated Values)?

though you can pass any delimiter you like with fputcsv() … (as long as you pass a valid delimiter)
Apr 10 '12 #2
Claus Mygind
571 512MB
It appears the real solution is to download and install phpExcel

Then it is easy to create a completed and formatted excel spread sheet.
Apr 13 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: js | last post by:
Hi, how to do this: the page is to be able to allow a user to enter a password so as to download documents. It does not meant for any users to download. It is for some specific users. What I want...
0
by: Ilia Makarenko | last post by:
Hi everyone! I've got a problem with IIS 6.0 when downloading files with size > 4 Mb. So I am trying to download file in chunks, but it doesn't work. Only pert of the file is downloaded (~6.5 of...
4
by: mphanke | last post by:
Hi, how can I connect to a restricted directory on a server and download a file, if there is a newer version, than the one on the local file system? Something like ...
1
by: user2008 | last post by:
Hi all, I want to track how many times visitor download file from my website, for example, when visitor click on a download link, a ASPX page will be requested, after that it will redirect to a...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
8
by: BiT | last post by:
Hello, I'm working right now on project in vb.net 2005 for my company, i need the project to download file from the company web site. In order to get the file i have to give the site address...
3
by: cypherkro | last post by:
Hi I have a requirement to automatically download a file using a WebBrowser control without having the "Download File" pop up windows display. I cannot use Webclient!! I am using VS2005, .net2...
5
by: vinodkus | last post by:
dear sir/madam I have to write a code for download file using asp. please help me thanks in advance
1
by: vikassawant | last post by:
Hi, I m facing some critical problem for downloading 5mb file from server. Does anyone know? How to reduce the time to download file from server using HTTP connection?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.