Experts ! Please help me achieve my task.
I need to renter and display spreadsheet in browser using php and shouldn't open the pop up window "Save As" asking user to open/save.It should open the xl sheet in the brower with out tool bar of xl .
the following code works fine and doesn't open pop up window in IE 7.0.
It shows pop up window in IE 6.0 .Even if i click open ., it opens in the xl not in the brower.Please help me fix this issue.

<?php

header("Content-type: application/x-msexcel");
header("Content-type: application/octet-stream");
header('Content-Disposition: inline; filename="'.basename($export_file).'"');
readfile($export_file);

?>

    Try setting Content-type to application/vnd.ms-excel

      And note that there's no point in having this:

      header("Content-type: application/x-msexcel");

      in the code you posted, since you replace the value of Content-Type on the next line.

        thanks for the response.But I did make changes as you mentioned above , But, it still opens the spreadsheet in Microsoft Excel and it doesn't open spreadsheet in the browser in IE 7.0.The same code renders the spreadsheet and opens in the browser in IE 6.0 not in 7.0.
        Please help me fix this issue.

        <?php

        $export_file = "test.xls";
        //ob_end_clean();

        // ini_set('zlib.output_compression','Off');

        header('Pragma: public');
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                  // Date in the past
        header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
        header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
        header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
        header ("Pragma: no-cache");
        header("Expires: 0");
        header('Content-Transfer-Encoding: none');
        header('Content-Type: application/vnd.ms-excel');                 // This should work for IE & Opera
          header("Content-type: application/octet-stream");
        header('Content-Disposition: inline; filename="'.basename($export_file).'"');
        readfile($export_file);

        ?>

          thanks for the response.But I did make changes as you mentioned above , But, it still opens the spreadsheet in Microsoft Excel and it doesn't open spreadsheet in the browser in IE 7.0.The same code renders the spreadsheet and opens in the browser in IE 6.0 not in 7.0.
          Please help me fix this issue.

          <?php

          $export_file = "test.xls";
          //ob_end_clean();

          // ini_set('zlib.output_compression','Off');

          header('Pragma: public');
          header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                  // Date in the past
          header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
          header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
          header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
          header ("Pragma: no-cache");
          header("Expires: 0");
          header('Content-Transfer-Encoding: none');
          header('Content-Type: application/vnd.ms-excel');                 // This should work for IE & Opera
            header("Content-type: application/octet-stream");
          header('Content-Disposition: inline; filename="'.basename($export_file).'"');
          readfile($export_file);

          ?>

            The code you are using is to force a file download of your excel document.
            Which is the opposite of what you are looking to accomplish correct?
            In short answer, PHP cannot force a viewer to see xls files online. If you have a program like microsoft office or "OpenOffice.org" then these programs give extensions for browsers to be able to view xls files seemingly online. Reaslistically, the file still downloads and opens up locally.
            Meaning if people dont have such programs they simply cannot read xls files and there is nothing you can do about that.

            The LONG answer is obviously a software that can read and mimic xls files online such as google aps.
            But such programs took a team of people probably quite a while of developing and trial and error to come up with.

            So realistsically, if your user cannot read xls files at all, php nor js will help them.

              thanks for the reply.As i had menionted in my post. , the same code
              1)I.E 6.0 Observation:
              The code opens the spreadsheet directly in browser with out "save as " pop up to "open/save" the spreadsheet.
              2)IE 7.0 Observation:
              The code opens the spreadsheet in windows excel enviorment and it doesn't open directly in the browser for IE 7.0

              thanks

                yes, that will happen because not everybody is set up to view that file type, or if so, that file type in a browser.

                It is not a good approach to develop a file delivery that only a fraction of your visitors will be able to view.
                You can "fake" a excel file online if you do alot of programming, but you cannot force people to view them online without installing some form of excel file reader like microsoft excel, openoffice, or something similar

                  14 days later

                  Thakns for the message.I am facing an issue while accessing the excel in the frameset that calls the php code that has a funtionality to show the excel sheet.
                  Here is the Scenario
                  1)When i directly access the URL of the PHP script that has a logic with inline command to open the excel on browser, it opens the excel in browser or it shows the "save as" dialog based on the "xls file setting" in explorer
                  2)When i call the PHP script in a frameset to open the spreadsheet on frame , it doesn't open the "save as" dialog box at all and show empty web page.

                  Why doesn't the excel open in a frameset with php call ?

                  Expert help me pls!
                  <HTML>
                  <HEAD>
                  <TITLE>Frames</TITLE>
                  </HEAD>

                  <FRAMESET ROWS="5%, 93%" BORDER="0" FRAMESPACING="0" MARGINHEIGHT="0" MARGINWIDTH="0" >
                  <FRAME SRC="content.html" BORDER="0" FRAMESPACING="0" MARGINHEIGHT="0" MARGINWIDTH="0" FRAMEBORDER="0" SCROLLING="no">
                  <FRAME SRC="xls.php" BORDER="0" FRAMESPACING="0" MARGINHEIGHT="0" MARGINWIDTH="0" FRAMEBORDER="0" SCROLLING="no">
                  <NOFRAMES>
                  <P>Here is the <A href="main-noframes.html">
                  non-frame based version of the document.</A>
                  </NOFRAMES>

                  </FRAMESET>

                  </HTML>

                    a year later

                    I was trying to do something similar, but could find no way to display excel files inline without plugins.

                    However if you convert it to a CSV file then there are all kinds of options in PHP.

                    http://www.homeandlearn.co.uk/php/php10p6.html

                    It helped me anyway.

                    _Marticus

                      Write a Reply...