0

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

4
Contributors
9
Replies
10
Views
8 Years
Discussion Span
Last Post by gilesbradley
0

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

0

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();

    }
0

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?

0

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

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.