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-comffice: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
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-comffice: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