how to embed an excel file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maeve
Forum Newbie
Posts: 4
Joined: Mon Nov 06, 2006 10:16 am

how to embed an excel file

Post by maeve »

Hey guys!

is there anyone here who could help me how to embed an excel file in php or even in html?
i've used iframe but i didn't get the right result i wanted..

could you please enlighten me?

im waiting for your suggestions!

thanks! :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Embedding would require a browser level plugin that will handle the request to display it, if you want the real Excel functionality and so forth. If you simple want a static grid, <table> tags work wonders. There are dynamic grids out there too, powered by Javascript.
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Post by jimthunderbird »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


some hints, hope it helps

Code: Select all

//beginning of the report string
      $report_str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
      
      <head>
      	<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
        <style id="Classeur1_16681_Styles">
        </style>
      </head>
      
      <body>
      
      <div id="Classeur1_16681" align=center x:publishsource="Excel">
      
      <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
      ';
      
      
      //now, the report header
      $report_str .= "<tr>";
      foreach($reportheader as $header){
        $report_str .= "<td><b>$header</b></td>";
      }
      $report_str .= "</tr>";
      
      //now, the report data
      foreach($reportdata as $data){
       $report_str .= "<tr>";
       foreach($data as $datacell){
         $report_str .= "<td>$datacell</td>";
       }
       $report_str .= "</tr>";
      }
      
      
      //end of the report string
      $report_str .= '
      </table>
      </div>
      </body>
      </html>
      ';

      header("Content-type: application/vnd.ms-excel");
      header("Content-Disposition: attachment; filename=myreport.xls");
      print $report_str;

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply