Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. GirdView with Image in Header, Export to Excel

GirdView with Image in Header, Export to Excel

Scheduled Pinned Locked Moved ASP.NET
csshelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saini arun
    wrote on last edited by
    #1

    Hello, I have a gridview which have an image in the header. When I export this image into Excel, it shows the header image in Excel document without any problem. But when I transfer the exported excel file to some other system, the header image disappears. I think, this is because the image in excel document reference to the path in my system where it physically exists, i.e. Images folder under my website folder. When I transfer the file on other system, it tries to find the image at the same path, resulting a red cross icon at the place of image. Is there any way I can insert image in excel so that it does not reference the path from where the image was originally inserted....? Following is the code I am using to export grid view to excel...

    Response.Clear();

    Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

    Response.Charset = "";

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

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

    HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);

    gvToExport.RenderControl(HtmlTextWriter);

    Response.Write(StringWriter.ToString());

    Response.End();

    P 1 Reply Last reply
    0
    • S saini arun

      Hello, I have a gridview which have an image in the header. When I export this image into Excel, it shows the header image in Excel document without any problem. But when I transfer the exported excel file to some other system, the header image disappears. I think, this is because the image in excel document reference to the path in my system where it physically exists, i.e. Images folder under my website folder. When I transfer the file on other system, it tries to find the image at the same path, resulting a red cross icon at the place of image. Is there any way I can insert image in excel so that it does not reference the path from where the image was originally inserted....? Following is the code I am using to export grid view to excel...

      Response.Clear();

      Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

      Response.Charset = "";

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

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

      HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);

      gvToExport.RenderControl(HtmlTextWriter);

      Response.Write(StringWriter.ToString());

      Response.End();

      P Offline
      P Offline
      puviyarasan j
      wrote on last edited by
      #2

      No Problem in this code. May be your Image path is unknown in other system. you can try ~/images/imagename.jpg

      S 1 Reply Last reply
      0
      • P puviyarasan j

        No Problem in this code. May be your Image path is unknown in other system. you can try ~/images/imagename.jpg

        S Offline
        S Offline
        saini arun
        wrote on last edited by
        #3

        Hello, Thanks for the reply. As I wrote in the query, the exported excel file looks for the path from where it was inserted. And when it is downloaded by client, excel fails to find referenced path for the image. I was thinking about, somehow embed the image itself in the excel so that it refer the image internally.

        S 1 Reply Last reply
        0
        • S saini arun

          Hello, Thanks for the reply. As I wrote in the query, the exported excel file looks for the path from where it was inserted. And when it is downloaded by client, excel fails to find referenced path for the image. I was thinking about, somehow embed the image itself in the excel so that it refer the image internally.

          S Offline
          S Offline
          saini arun
          wrote on last edited by
          #4

          I solved the issue by using a template excel document.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups