471,591 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,591 software developers and data experts.

Exporting Image and GridView to Word/Excel is Impossible!

Hello Fellow Developers,

I have a small problem that you might be able to help me with. The
method that I am trying to create is the ability to export a GridView
and a image to word or excel. I know that some people have already post
about this topic but could not find a reliable answer. To my knowledge,
I have the code down right. The GridView writes to the word document
perfectly just not the image. All I get is a red 'x' image notifying me
that word cannot find the path of the image.

Below is my code. Any help would be grateful.

Legend:

---------------------------------

partsGrid = GridView

pieImage = asp.net Image, which is dynamically created using GDI+

---------------------------------
intro = "<div align=center><font style=FONT-SIZE:'18pt'; COLOR:
'#8B0000'; FONT-FAMILY: 'Verdana'>" + rptlbltype.Text +
"</font></div><br>";
intro = intro + "<div align=center><font style=FONT-SIZE:'11pt'; COLOR:
'#8B0000'; FONT-FAMILY: 'Verdana'>Date From" + " " + sDate.Text + " " +
"to" + " " + eDate.Text + "</font></div><br>";

string temp = rptlbltype.Text + "-" + " " + sDate.Text + "to" +
eDate.Text;

Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=" +
rptlbltype.Text + ".doc");

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.No Cache);

Response.ContentType = "application/vnd.word";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);

StringWriter stringWrite2 = new StringWriter();

HtmlTextWriter htmlWrite2 = new HtmlTextWriter(stringWrite2);

partsGrid.RenderControl(htmlWrite);

pieImage.RenderControl(htmlWrite2);

string totalText = intro + stringWrite.ToString() + "<br/>" +
stringWrite2.ToString() ;

Response.Write(totalText);

Response.End();

Jul 11 '06 #1
2 3525
You need to make sure you're specifying the full path to the image, not a
relative path.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<ma**********@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hello Fellow Developers,

I have a small problem that you might be able to help me with. The
method that I am trying to create is the ability to export a GridView
and a image to word or excel. I know that some people have already post
about this topic but could not find a reliable answer. To my knowledge,
I have the code down right. The GridView writes to the word document
perfectly just not the image. All I get is a red 'x' image notifying me
that word cannot find the path of the image.

Below is my code. Any help would be grateful.

Legend:

---------------------------------

partsGrid = GridView

pieImage = asp.net Image, which is dynamically created using GDI+

---------------------------------
intro = "<div align=center><font style=FONT-SIZE:'18pt'; COLOR:
'#8B0000'; FONT-FAMILY: 'Verdana'>" + rptlbltype.Text +
"</font></div><br>";
intro = intro + "<div align=center><font style=FONT-SIZE:'11pt'; COLOR:
'#8B0000'; FONT-FAMILY: 'Verdana'>Date From" + " " + sDate.Text + " " +
"to" + " " + eDate.Text + "</font></div><br>";

string temp = rptlbltype.Text + "-" + " " + sDate.Text + "to" +
eDate.Text;

Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=" +
rptlbltype.Text + ".doc");

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.No Cache);

Response.ContentType = "application/vnd.word";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);

StringWriter stringWrite2 = new StringWriter();

HtmlTextWriter htmlWrite2 = new HtmlTextWriter(stringWrite2);

partsGrid.RenderControl(htmlWrite);

pieImage.RenderControl(htmlWrite2);

string totalText = intro + stringWrite.ToString() + "<br/>" +
stringWrite2.ToString() ;

Response.Write(totalText);

Response.End();

Jul 13 '06 #2
Hi Everyone,
I do also have the same problem....
I have also given the full path of image,but still it is not showing
the image in Word document...
The GridView writes to the word document
but not the image. All it show is a red 'x' image . but on clicking
the image on word document it display the image....
any help would be gratefull..
thanks
Pankaj

Steve C. Orr [MVP, MCSD] wrote:
You need to make sure you're specifying the full path to the image, not a
relative path.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
<ma**********@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hello Fellow Developers,

I have a small problem that you might be able to help me with. The
method that I am trying to create is the ability to export a GridView
and a image to word or excel. I know that some people have already post
about this topic but could not find a reliable answer. To my knowledge,
I have the code down right. The GridView writes to the word document
perfectly just not the image. All I get is a red 'x' image notifying me
that word cannot find the path of the image.

Below is my code. Any help would be grateful.

Legend:

---------------------------------

partsGrid = GridView

pieImage = asp.net Image, which is dynamically created using GDI+

---------------------------------
intro = "<div align=center><font style=FONT-SIZE:'18pt'; COLOR:
'#8B0000'; FONT-FAMILY: 'Verdana'>" + rptlbltype.Text +
"</font></div><br>";
intro = intro + "<div align=center><font style=FONT-SIZE:'11pt'; COLOR:
'#8B0000'; FONT-FAMILY: 'Verdana'>Date From" + " " + sDate.Text + " " +
"to" + " " + eDate.Text + "</font></div><br>";

string temp = rptlbltype.Text + "-" + " " + sDate.Text + "to" +
eDate.Text;

Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=" +
rptlbltype.Text + ".doc");

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.No Cache);

Response.ContentType = "application/vnd.word";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);

StringWriter stringWrite2 = new StringWriter();

HtmlTextWriter htmlWrite2 = new HtmlTextWriter(stringWrite2);

partsGrid.RenderControl(htmlWrite);

pieImage.RenderControl(htmlWrite2);

string totalText = intro + stringWrite.ToString() + "<br/>" +
stringWrite2.ToString() ;

Response.Write(totalText);

Response.End();
Jul 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Pranav | last post: by
1 post views Thread by Mustufa Baig | last post: by
2 posts views Thread by Yaseen D M | last post: by
2 posts views Thread by wubin_98 | last post: by
4 posts views Thread by Tom | last post: by
3 posts views Thread by aSoundMind | last post: by
reply views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.