Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Export to Excel --but also Set Print Area

Thread Tools

Export to Excel --but also Set Print Area

Posts: n/a
I have a handy routine I tweaked from an example that Exports an Excel from a

It's almost perfect except for the fact that I'd also like to set the page
to fit as many columns wide to each page. - For example, I have some
gridviews that have data in 12 columns, but only 10 make it in the printout,
so I get the broken overflow into undesired pages.

So of course, the header will need to repeat in those other pages.

Is there a way to set this in the code below? Or do I need to break out an
Excel Object model for dot net?

Public Shared Sub ExcelExport(ByVal gv As GridView, ByVal strFileName As
'Exports an Excel spreadsheet of the named 'gv' gridview with the
named strFileName

'Requires this at the top of the module:
'Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
' empty, needed for export2Excel to work.
'End Sub

"attachment;filename=" & strFileName & ".xls")
HttpContext.Current.Response.Charset = ""

HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.NoCache)
HttpContext.Current.Response.ContentType = "application/vnd.xls"

Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New

stringWrite.Write("<html><head><meta http-equiv=""content-type""
content=""text/html; charset=utf-8""></head><body>")
'Temporariilly remove paging and sorting to allow for plain
formatting of
gv.AllowPaging = False
gv.AllowSorting = False


HttpContext.Current.Response.Write(stringWrite.ToS tring())

End Sub

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to Excel (Default File Type - Excel) =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?= ASP .Net 15 05-21-2009 12:01 PM
Export to excel in using excel template Grey ASP .Net 4 10-17-2007 08:08 AM
Re: UPDATE: They didn't only pledge allegiance to Mex flag: anchor babies in TX *also* shouted "RAZA! RAZA!" in US school also Digital Photography 9 10-21-2006 11:12 AM
using Microsoft Excel image for Export to Excel button =?Utf-8?B?U3JpZGhhcg==?= ASP .Net 0 12-09-2005 08:58 PM