Re: export data to a ms excel file using php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2008-10-23 at 13:05 +0530, gopi krishnan wrote:
> Hi,
> 
> Could any one explain better. I need just the grid lines for the excel
> sheet. I already tried that <table border=1> but it shows the linings only
> to the valued cells. But i need to show the grid as in MS Excel. I tried
> TEXT/XML
> but i get the following error
> 
> ---------------------------
> 
> The XML page cannot be displayed
> 
> Cannot view XML input using XSL style sheet. Please correct the error and
> then click the Refresh <javascript:location.reload()> button, or try again
> later.
> ------------------------------
> 
> A string literal was expected, but no opening quote character was found.
> Error processing resource 'http://localhost/dbtoxl...
> 
> <table border="1"><tr> <td width=100>25 </td><td width=100> jana
> </td><td  width=100&...
> 
> 
> ---------------------------
> 
> thanks in advance....
> 
> 
> On Thu, Oct 23, 2008 at 3:21 AM, Nitsan Bin-Nun <nitsan@xxxxxxxxxxxx> wrote:
> 
> > And what about users who use office version < 2003 (which do NOT support
> > .xml charts)
> > You can google a bit, I'm pretty sure I have already encountered a class
> > for this case at Manuel's site (phpclasses).
> >
> > Nitsan
> >
> > On Wed, Oct 22, 2008 at 9:00 PM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx
> > > wrote:
> >
> >> On Wed, 2008-10-22 at 11:20 -0700, Jim Lucas wrote:
> >> > www.gopi.com@xxxxxxxxx wrote:
> >> > > Hi,
> >> > >
> >> > > I have tried your MS-Excel MIME type in PHP. But am facing a small
> >> problem. I can't get the grid lines as look like in normal Excel file.
> >> > >
> >> > > Am using windows XP, Internet explorer 6.0, MS Excel 2003
> >> > >
> >> > > Thanks in advance.-- Jim Lucas wrote :
> >> > > abderrazzak nejeoui wrote:
> >> > >> can you help me to export data to a ms excel file using php. i tried
> >> to
> >> > >> export them to an html format and change the extension to .xls that's
> >> work
> >> > >> but i have lost the formatting
> >> > >>
> >> > >> excel and the navigator doesn't interpret my code in the same why
> >> (celles
> >> > >> are not in the same size)
> >> > >>
> >> > >
> >> > > Ok, so with the examples of others here, here is the shortest example
> >> that I came up with that
> >> > > should get you going.
> >> > >
> >> > > <?php
> >> > >
> >> > > header("Content-Type:  application/vnd.ms-excel");
> >> > > header("Expires: 0");
> >> > > header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> >> > >
> >> > > $x = $y = range(0, 12);
> >> > >
> >> > > echo '<table>';
> >> > >
> >> > > echo '<tr><td> </td><td>' . join('</td><td>', $x) . '</td></tr>';
> >> > >
> >> > > foreach ( $x AS $xx ) {
> >> > >     echo "<tr><td>{$xx}</td>";
> >> > >     foreach ( $y AS $yy ) {
> >> > >             echo
> >> "<td>=sum(".(chr(ord('b')+$yy))."1*a".($xx+2).")</td>";
> >> > >     }
> >> > >     echo "</tr>";
> >> > > }
> >> > > echo '</table>';
> >> > >
> >> > > ?>
> >> > >
> >> > > This will output a 14x14 table.  It will calculate the totals for each
> >> cell in the actual
> >> > > spreadsheet once excel loads it.
> >> > >
> >> > > If you have any questions, ask away.
> >> > >
> >> >
> >> > You could change this line
> >> >
> >> > echo '<table>';
> >> >
> >> > to this
> >> >
> >> > echo '<table border="1">';
> >> >
> >> > This will give you borders around your content at least.
> >> >
> >> > Example:
> >> >
> >> http://www.cmsws.com/examples/php/testscripts/www.gopi.com@xxxxxxxxx/0001.php
> >> >
> >> > I would checkout phpexcel also
> >> >
> >> > --
> >> > Jim Lucas
> >> >
> >> >    "Some men are born to greatness, some achieve greatness,
> >> >        and some have greatness thrust upon them."
> >> >
> >> > Twelfth Night, Act II, Scene V
> >> >     by William Shakespeare
> >> >
> >> >
> >> I think you really need to save the file as an XML file, with the
> >> text/xml mime-type. Then, save an Excel file in the M$ Office 2003 XML
> >> file-type (not the 2007 xlsx!) and look at the code it produces and try
> >> to mimic that output as closely as possible. All you're doing is
> >> creating an HTML table and hoping Excel knows what to do with it, which
> >> is a bit like creating an image, sending it to the browser with a PDF
> >> mime and hoping it will open up in Adobe Reader; just not gonna work
> >> that way!
> >>
> >> Your best bet by far though, is to use a pre-built Excel export class.
> >> Take a look at PEAR of PHPLib, as these both have classes that do what
> >> you need.
> >>
> >>
> >> Ash
> >> www.ashleysheridan.co.uk
> >>
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
the problem here is that you don't seem to understand the difference
between xml, html and the binary excel format. Pick one, find out how it
works and go with it. You seem to think that if you send down html to a
browser, but give it a mime-type of application/excel it will suddenly
become an excel document. not gonna happen, ever, period.

my suggestion about using the text/xml header will only work _if you
write the file as xml_ which you aren't. try using a class, or pay
someone to do it if you can't.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux