Click here to get back home

Saving images in Excel report

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Saving images in Excel report Eddie 06-11-2008
Get Chitika Premium
Posted by Eddie on June 11, 2008, 11:42 am
Please log in for more thread options
Hi all,

I am displaying a number of reports, and giving the users an option to
display them on the web or download them to Excel. If they want the
Excel file, I just use the PHP header command to change the Content-
Type and Content-Disposition headers, and essentially print the same
report, and it's done. That works fine.

But in some reports on the web I need to show images. The web part is
fine, but I'm having a tough time figuring out how to actually display
the images in Excel. Since this is a 'take it with you' file, links
won't work. I assume I'll have to effectively store the entire real
image file within Excel in the report. Can anyone point me in the
right direction? Here's a code snippet:

if ( ( isset($_POST['xl'])&&($_POST['xl']=="1") ) ||
( isset($_GET['xl'])&&($_GET['xl']=="1") ) ) {
        header("Content-Type: application/xls");
        header("Content-Disposition: attachment; filename=MyReport.xls");
        header("Content-Type: application/force-download");
        header("Cache-Control: post-check=0, pre-check=0", false);
        $xl = 1;
}

...
...

if ($xl == 1) {
        print "<img border=0 src='../report/$file' height=20>";
}
else {
        print "<img border=0 src='../report/$file' height=20>";
}

Presently the image part doesn't work for Excel. Thanks in advance.

Eddie Andrews

Posted by C. (http://symcbean.blogspot.c on June 12, 2008, 8:11 am
Please log in for more thread options
> Hi all,
>
> I am displaying a number of reports, and giving the users an option to
> display them on the web or download them to Excel. If they want the
> Excel file, I just use the PHP header command to change the Content-
> Type and Content-Disposition headers, and essentially print the same
> report, and it's done. That works fine.
>
> But in some reports on the web I need to show images. The web part is
> fine, but I'm having a tough time figuring out how to actually display
> the images in Excel. Since this is a 'take it with you' file, links
> won't work. I assume I'll have to effectively store the entire real
> image file within Excel in the report. Can anyone point me in the
> right direction? Here's a code snippet:
>
> if ( ( isset($_POST['xl'])&&($_POST['xl']=="1") ) ||
> ( isset($_GET['xl'])&&($_GET['xl']=="1") ) ) {
> header("Content-Type: application/xls");
> header("Content-Disposition: attachment; filename=MyReport.xls");
> header("Content-Type: application/force-download");
> header("Cache-Control: post-check=0, pre-check=0", false);
> $xl = 1;
>
> }
>
> ...
> ...
>
> if ($xl == 1) {
> print "<img border=0 src='../report/$file' height=20>";}
>
> else {
> print "<img border=0 src='../report/$file' height=20>";
>
> }
>
> Presently the image part doesn't work for Excel. Thanks in advance.
>
> Eddie Andrews

What do you get if you manually create an Excel spreadsheet with
images, saving it as html, then viewing in a text editor?

C.

Posted by Michael Fesser on June 12, 2008, 3:45 pm
Please log in for more thread options
.oO(Eddie)

>You make a good suggestion. As a default, when saving Excel files as a
>web page, if it has an image, it stores the image in a folder and
>references the image in the HTML. But that isn't quite what I want to
>do. Isn't there a way to save the image within the Excel file itself,
>so the user can carry only the XLS file with him rather than HTML and
>images files and a directory structure.

Sure, but you'd have to create your document in a native Excel format.

Micha

Posted by Eddie on June 12, 2008, 4:20 pm
Please log in for more thread options
> .oO(Eddie)
>
> >You make a good suggestion. As a default, when saving Excel files as a
> >web page, if it has an image, it stores the image in a folder and
> >references the image in the HTML. But that isn't quite what I want to
> >do. Isn't there a way to save the image within the Excel file itself,
> >so the user can carry only the XLS file with him rather than HTML and
> >images files and a directory structure.
>
> Sure, but you'd have to create your document in a native Excel format.
>
> Micha

Yep. I think you're right. Thanks.

Posted by =?ISO-8859-1?Q?=22=C1lvaro_G=2 on June 12, 2008, 10:15 am
Please log in for more thread options
Eddie escribió:
> I am displaying a number of reports, and giving the users an option to
> display them on the web or download them to Excel. If they want the
> Excel file, I just use the PHP header command to change the Content-
> Type and Content-Disposition headers, and essentially print the same
> report, and it's done. That works fine.
>
> But in some reports on the web I need to show images. The web part is
> fine, but I'm having a tough time figuring out how to actually display
> the images in Excel. Since this is a 'take it with you' file, links
> won't work. I assume I'll have to effectively store the entire real
> image file within Excel in the report. Can anyone point me in the
> right direction? Here's a code snippet:
>
> if ( ( isset($_POST['xl'])&&($_POST['xl']=="1") ) ||
> ( isset($_GET['xl'])&&($_GET['xl']=="1") ) ) {
>         header("Content-Type: application/xls");
>         header("Content-Disposition: attachment; filename=MyReport.xls");
>         header("Content-Type: application/force-download");
>         header("Cache-Control: post-check=0, pre-check=0", false);
>         $xl = 1;
> }
>
> ...
> ...
>
> if ($xl == 1) {
>         print "<img border=0 src='../report/$file' height=20>";
> }
> else {
>         print "<img border=0 src='../report/$file' height=20>";
> }

Hmmm... What's the difference?

Obviously, you aren't generating Excel files at all. This is just good
old HTML that the browser allows you to open with Excel (because of the
forged file extension) and Excel happens to understand (because of its
built-in HTML capabilities).

As you know, you don't insert pictures inside HTML but you link an
external file. So Excel only gets the HTML, there aren't any pictures.
Even if they were, according to your code it'd be looking for them in a
"report" subdirectory in the client computer.

Perhaps if you publish the pictures in your web server and provide a
full URL so Excel can download them itself _may_ do the trick (I'm not
too familiar with Excel):

<img src="hptt://example.com/foo/picture.jpg">

If it doesn't, you'll need to generate a real Excel file. There're some
libraries out there.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Similar ThreadsPosted
Report PDF September 13, 2006, 10:11 pm
bug (maybe) report March 24, 2008, 10:54 pm
Print A4 Report July 13, 2004, 11:04 pm
PHP does not report errors! March 9, 2006, 4:06 pm
Crosstab Report May 30, 2007, 6:13 am
php mysql report month and ytd December 21, 2004, 7:01 am
Report Generation in PHP / MYSQL app February 26, 2005, 1:17 am
Stuck & Need Help with "Generate Report" February 25, 2006, 12:31 pm
How to reopen bug report: ImageTTFBBox October 14, 2007, 9:33 pm
Why PHP don't Report this SYNTAX ERROR ? September 25, 2008, 2:43 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap