473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.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:office: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
Sep 21 '08 #1
0 1404

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eric | last post by:
Dear All, I want to export datagrid content to a Excel file, the code just like below: Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim...
2
by: Bidarkota | last post by:
Hi, I have a DataGrid in which there are some images and Data are displayed and in the webform.asp page i am using some stylesheets. when i export the datagrid all the images are also exported...
3
by: Bidarkota | last post by:
When i export DataGrid to Excel all the HTML contents are also exporting to excel. i am using stylesheets in the ASPX Page and i am getting an alert message that stylesheets are missing. i need to...
3
by: mattdaddym | last post by:
Hi all, I have been using the following code to export my datagrids to excel for quite some time. Very simple and very effective. <code> Sub btnExcelExport_Click ( s As Object, e As...
0
by: kieran | last post by:
Hi, I have an 'export to excel' button on my Datagrid. All works well except that on my Datagrid, I have sub total rows. The subtotal rows use colspan so that the subtotals are given above...
6
by: Sridhar | last post by:
Hi, I have to export data inside the datagrid into an excel worksheet. I have to do this on button click event. I am trying to do like this. First get the DataTable from the datagrid and...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
4
by: dinoo | last post by:
I would appreciate if some one could help me out with this problem. I am trying to export the datagrid to an excel file in ASP.NET. The functionality works fine. But I would like to setup the...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.