Help with sending data to Excel

Posted on 2007-10-01
Last Modified: 2008-03-04

I have a script that runs a query and places the result in excel query.  This work fine.  I need to take this a step further.  When displaying this data directly on to a web page I parse the data so that it only displays part of the information.

Here is the code I have to generate the excel file:

export = mysql_query($query_rs_ssip_ongoing);
$fields = mysql_num_fields($export);

for ($i = 0; $i < $fields; $i++) {
    $header .= mysql_field_name($export, $i) . "\t";

while($row = mysql_fetch_row($export)) {
    $line = '';
    foreach($row as $value) {                                            
        if ((!isset($value)) OR ($value == "")) {
            $value = "\t";
        } else {
            $value = str_replace('"', '""', $value);
            $value = '"' . $value . '"' . "\t";
        $line .= $value;
    $data .= trim($line)."\n";
$data = str_replace("\r","",$data);

if ($data == "") {
    $data = "\n(0) Records Found!\n";                        

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";


and here is the code that I use which parses the infromation when displayed on the webpage:

                        $text1 = $row_rs_ssip_ongoing['Subject'];
                        $start1 = strpos( $text1, ">" );
                        $ends1 = strpos( $text1, "#" );
                        $eng = substr( $text1, $start1+1, ($ends1-$start1-1) );
                        echo $eng;

What I need to do is merge these two so that the excel output is the same as the information displayed on the website.

Any help appreciated.
Question by:andyw27
    LVL 34

    Accepted Solution

    I'm confused.

    When you're displaying the spreadsheet you can't see the webpage because Excel is open in the browser so you can't see both.

    Secondly, since you are apparently running exactly the same query the results should be identical. In what way do they differ?

    Author Comment


    The spreadsheet downloads to the users machine.

    They differ because the Excel query returns everything whereas the web page breaks down the content.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now