By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

Saving images in Excel report

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Jun 11, 4:42 pm, Eddie <eddieandr...@gmail.comwrote:
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.
Jun 27 '08 #2

P: n/a
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
--
Jun 27 '08 #3

P: n/a
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:
On Jun 11, 4:42 pm, Eddie <eddieandr...@gmail.comwrote:
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.
Jun 27 '08 #4

P: n/a
On Jun 12, 9:15 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
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
--
That makes even better sense. I'll start looking for libs.
Jun 27 '08 #5

P: n/a
..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
Jun 27 '08 #6

P: n/a
On Jun 12, 2:45 pm, Michael Fesser <neti...@gmx.dewrote:
.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.
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.