DataGrid Export To Excel - Set Landscape

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?a2xhZnJhbWJvaXNl?=

    #1

    DataGrid Export To Excel - Set Landscape

    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.Respons e.Clear()
    Current.Respons e.Buffer = True
    Current.Respons e.AddHeader("co ntent-disposition",
    String.Format(" attachment; filename={0}", fileName))
    Current.Respons e.ContentType = "applicatio n/vnd.ms-excel"
    Current.Respons e.Write("<meta http-equiv=Content-Type
    content=""text/html; charset=utf-8"">" & vbNewLine)
    Current.Respons e.Write(GetExce lStyling())
    Current.Respons e.Write(sw.ToSt ring)
    Current.Respons e.Write("</body>")
    Current.Respons e.Write("</html>")
    Current.Respons e.End()

    Private Shared Function GetExcelStyling () As String
    Dim sb As New StringBuilder
    sb.AppendLine(" <html
    xmlns:x=""urn:s chemas-microsoft-com:office:exce l"">")
    sb.AppendLine(" <head>")
    sb.AppendLine(" <style>")
    sb.AppendLine(" @page{mso-page-orientation:lan dscape;")
    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
Working...