Problem in Exporting ASP page in word

P

Pankaj.3107

Hello Friends

When i export ASP page to ms word, the grid view table in word become
to large....
For a gridview table of 2 rows it take the whole page of ms-word....I
am finding very difficulty
in solving this problem...Please help me regarding this....
Here is my Code........

private void ExportToExcel(string filename)
{
Page.Response.Clear();
Page.Response.AddHeader("content-disposition", "attachment;
filename=" + filename);
Page.Response.ContentType = "application/vnd.ms-word";
Page.Response.Charset = String.Empty;
StringWriter textWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(textWriter);
GridView printGV = new GridView();
printGV.HeaderStyle.HorizontalAlign =
System.Web.UI.WebControls.HorizontalAlign.Center;
printGV.HeaderStyle.VerticalAlign =
System.Web.UI.WebControls.VerticalAlign.Middle;
printGV.HeaderStyle.BackColor = System.Drawing.Color.LightBlue;
printGV.RowStyle.HorizontalAlign =
System.Web.UI.WebControls.HorizontalAlign.Left;
printGV.RowStyle.VerticalAlign =
System.Web.UI.WebControls.VerticalAlign.Middle;
printGV.AlternatingRowStyle.BackColor =
System.Drawing.Color.FromArgb(239, 243, 251);
printGV.DataSource = gridView.DataSource;
printGV.RowDataBound += new
GridViewRowEventHandler(printGV_RowDataBound);
printGV.DataBind();
printGV.RenderControl(htmlWriter);
Page.Response.Write(textWriter.ToString());
Page.Response.End();
}

}

void printGV_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType != DataControlRowType.Pager)
{
foreach (int i in columnsToHide)
e.Row.Cells.Visible = false;
}
}
waiting for your reply
Thanks
Pankaj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top