473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving images in Excel report

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=MyRepo rt.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
6 8054
On Jun 11, 4:42 pm, Eddie <eddieandr...@g mail.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=MyRepo rt.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
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=MyRepo rt.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
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.blogsp ot.com/)"
<colin.mckin... @gmail.comwrote :
On Jun 11, 4:42 pm, Eddie <eddieandr...@g mail.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=MyRepo rt.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
On Jun 12, 9:15 am, "Álvaro G. Vicario"
<alvaroNOSPAMTH A...@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=MyRepo rt.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
..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
On Jun 12, 2:45 pm, Michael Fesser <neti...@gmx.de wrote:
.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3275
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent...
0
1794
by: Pranav | last post by:
I've a web page that displays report data in a data grid an a chart ( I'm using Chart Fx for .Net which creates .PNG files on Server) I've a requirement to export the datagrid and chart both to Excel/Word When I stream the above ASPX page with Content Type set to Excel or Wor I get the Grid data exported Just fine, but I get empty image,...
4
3330
by: somanyusernamesaretakenal | last post by:
What I am trying to achieve: Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data) What I did was I imported the existing report into Excel (Tools – Office Links – Analyze It with MS Excel). Then I linked the report to the Excel file. (File – Get...
2
3083
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
1
3357
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The problem is, the image won't display unless I'm connected to the Internet or if I use a relative path and have the image stored relative to the excel...
1
3028
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet report. I always get when trying to test it " 500 Internal Server Error - The server encountered an internal error or misconfiguration and was unable...
4
2724
by: pkj7461 | last post by:
Hi, I was using Docmd.Transferspreadsheet to to populate query data in Excel. My code so far Dim xlApp As Excel.Application Dim xlWb As Excel.workbook Dim xlWs As Excel.Worksheet Set x1App = New Excel.Application xlApp.Visible = True Set xlWb = xlApp.Workbooks.Open("C:\Daily Open Report Template.xls")
6
3353
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to a user without saving it to the disk first. Obviously saving the file first and streaming it afterwards is fairly easy to do, but it relies on...
0
1102
by: veer | last post by:
hello expert i am facing a probleum of saving the out put in excel sheet actually i have two buttons on my vb form i,e merge entery and merge verify and when i execute my program one by one means execute "merge entery" procedure first and check the report on excel file and save in another file and then execute "merger entery" it works fine...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5341
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.