Hi There,

I am trying to export an image to Excel file from Asp.Net C# page. My code is working fine, and I can merge let say 6 columns in excel file and put the image on these cells.

What I would like to know is how to Center this image in the middle of these merged cells?

I've already tried every possible solution came to my mind, Like I could have a table,add a <td colspan=6> and then try to center the image, not working,

second solution was to add a dynamically created div and add style to center the image, not working,

after searching for a long time,I could not find any proper answer,

any Ideas?

Thanks

Could you please post the code where you are exporting image to excel?
It would help us to help you.

here is the code:
//////////////////////////////

protected void btnExportExcel_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ClearHeaders();
        Response.ClearContent();

        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=file.xls");

        Response.ContentType = "application/vnd.ms-excel";
       
                String imagepath = "<img src='http://localhost:56705/WebSite12/images/logo.jpg' width='70' height='80'/>";

        
            Response.Output.Write("\n<body>\n<html>");
        
            Response.Output.Write("<table width='800' align='center' style='text-align:center'");
            Response.Output.Write("<tr><td colspan='10' align='center'><div align='center' style='text-align:center'>" + imagepath + "</div></td></tr>");

         
            Response.Output.Write("</table>");
            Response.Output.Write("\n</body>\n</html>");
        



        Response.Flush();
        Response.End();

    }

hi why you want to merge cell and put the image in center of it?
you can have your image say in 5th column with only 2 cell merged:

Response.Output.Write("<tr><td></td><td></td><td></td><td></td><td colspan='2' align='center'><div align='center' style='text-align:center'>" + imagepath + "</div></td></tr>");

do you want this?

hi why you want to merge cell and put the image in center of it?
you can have your image say in 5th column with only 2 cell merged:

Response.Output.Write("<tr><td></td><td></td><td></td><td></td><td colspan='2' align='center'><div align='center' style='text-align:center'>" + imagepath + "</div></td></tr>");

do you want this?

Thanks for your Reply,
I have other cells too on top,As a result I have to merge cells,I've tried all possible scenarios,there is no way to center the image,

Thanks

did you try putting table inside table cell ?

did you try putting table inside table cell ?

Yes I did, it is now working?

Any ideas?it is so stanger thet nobody has any ansewer for this,one of microsoft bugs?

Thanks

Can you post your working code?

Any ideas?it is so stanger thet nobody has any ansewer for this,one of microsoft bugs?

I don't think its a bug, may be there are some other way to do so and we are not aware of it. Or may be there is another explanation for the problem you are facing.
One thing you would have noticed, once you export the excel, image is not inside any cell, basically its floating above excel sheet. so it seems its an object floating over sheet.

Brilliant - thanks. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.