DataGrid Export To Excel - Set Landscape

K

klaframboise

I've been searching for an answer to this for a few hours and I've found lots
of people with the same issue, but no solution. I'm exporting a datagrid to
excel which works fine, and I'm able to set the margins fine also, but for
some reason the page layout won't change to landscape. I'm using .Net 2.0
and Office 2003.

Here is the code:

Current.Response.Clear()
Current.Response.Buffer = True
Current.Response.AddHeader("content-disposition",
String.Format("attachment; filename={0}", fileName))
Current.Response.ContentType = "application/vnd.ms-excel"
Current.Response.Write("<meta http-equiv=Content-Type
content=""text/html; charset=utf-8"">" & vbNewLine)
Current.Response.Write(GetExcelStyling())
Current.Response.Write(sw.ToString)
Current.Response.Write("</body>")
Current.Response.Write("</html>")
Current.Response.End()

Private Shared Function GetExcelStyling() As String
Dim sb As New StringBuilder
sb.AppendLine("<html
xmlns:x=""urn:schemas-microsoft-com:eek:ffice:excel"">")
sb.AppendLine("<head>")
sb.AppendLine("<style>")
sb.AppendLine("@page{mso-page-orientation:landscape;")
sb.AppendLine("margin:.5in .5in .5in .5in;")
sb.AppendLine("mso-header-margin:.5in;")
sb.AppendLine("mso-footer-margin:.5in}")
sb.AppendLine("</style>")
sb.AppendLine("</head>")
sb.AppendLine("<body>")
Return sb.ToString()
End Function

Thanks Kevin
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top