Csv File Generate

How to generate dynamically row wise print in Excel(CSV) file from PHP?
atulmodiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
forethoughtCommented:
If you're wanting to be able to offer a link to dynamically generate a CSV file for download, here's what I do:

<?php
 /*
  * if you're using sessions, you'll need this in order for it to work with Internet Explorer
  */
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
	session_cache_limiter('public');
  }
  session_start();

   /*
    * grab your dynamic content here, be it from a file or from a database
    */
   $content = /* whatever, but when querying from a database I always have it return as an array so I can loop it */;
   if (count($content) > 0) {
     /*
      * since we're sending header information, this needs to precede any output
      */
     header('Content-type: text/comma-separated-values');
     header('Content-disposition: attachment; filename="YOUR_CSV_FILENAME.csv"');
     $csv = '"Header1", "Header2", "Header3"\015\012';
     foreach ($content as $row) {
       $csv .= '"' . $row['col1'] . '", '"' . $row['col2'] . '", "' . $row['col3'] . '"\015\012';
     }
     echo $csv;
   }
?>

Open in new window


Hope that helps.
0
atulmodiAuthor Commented:
It is Not Fully Satisfactory Result but i got some Idea from this.
0
atulmodiAuthor Commented:
It's Partially Helpful to me i got some idea from the link you provide.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.