Connecting Tech Pros Worldwide Forums | Help | Site Map

Saving images in Excel report

Eddie
Guest
 
Posts: n/a
#1: Jun 27 '08
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

C. (http://symcbean.blogspot.com/)
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Saving images in Excel report


On Jun 11, 4:42 pm, Eddie <eddieandr...@gmail.comwrote:
Quote:
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.
=?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Saving images in Excel report


Eddie escribió:
Quote:
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
--
Eddie
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Saving images in Excel report


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.

On Jun 12, 7:11 am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
Quote:
On Jun 11, 4:42 pm, Eddie <eddieandr...@gmail.comwrote:
>
>
>
Quote:
Hi all,
>
Quote:
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.
>
Quote:
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:
>
Quote:
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;
>
Quote:
}
>
Quote:
...
...
>
Quote:
if ($xl == 1) {
print "<img border=0 src='../report/$file' height=20>";}
>
Quote:
else {
print "<img border=0 src='../report/$file' height=20>";
>
Quote:
}
>
Quote:
Presently the image part doesn't work for Excel. Thanks in advance.
>
Quote:
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.
Eddie
Guest
 
Posts: n/a
#5: Jun 27 '08

re: Saving images in Excel report


On Jun 12, 9:15 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
Quote:
Eddie escribió:
>
>
>
Quote:
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.
>
Quote:
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:
>
Quote:
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;
}
>
Quote:
...
...
>
Quote:
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
--
That makes even better sense. I'll start looking for libs.
Michael Fesser
Guest
 
Posts: n/a
#6: Jun 27 '08

re: Saving images in Excel report


..oO(Eddie)
Quote:
>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
Eddie
Guest
 
Posts: n/a
#7: Jun 27 '08

re: Saving images in Excel report


On Jun 12, 2:45 pm, Michael Fesser <neti...@gmx.dewrote:
Quote:
.oO(Eddie)
>
Quote:
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.
Closed Thread