Export Gridview to Excel without Colors

I'm using the following code to export the data from a gridview to excel.  The problem is that the rows in the gridview are formatted with alternating colors.  The resulting excel export has some rows that are white and some that are yellow.  I would like the export file to have no colors...just black text and a white background.  Is there a way that it can be accomplished?  I've tried using "Attributes.Add" without much luck.  I'm doing something wrong.  Thanks.

1    ' define a style
2            Dim strStyle As String = "<style> .text { mso-number-format:\@; } </style> "
4            ' clear the buffer
5            Response.ClearContent()
7            ' adds a header to the data stream
8            Response.AddHeader("content-disposition", "attachment; filename=Listing_Report.xls")
10           ' specify the content type
11           Response.ContentType = "application/excel"
13           ' declare a new StringWriter
14           Dim sw As StringWriter = New StringWriter()
16           ' declare a new HtmlTextWriter
17           Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
19           ' output server control content to the HtmlTextWriter object 
20           gvListing.RenderControl(htw)
22           ' Style is added dynamically
23           Response.Write(strStyle)
25           ' write the content of the GridView
26           Response.Write(sw.ToString())
28           ' write a timestamp on the botton of the speadsheet
29           Response.Write("Exported: " & Now)
31           ' close
32           Response.End()
7/14/2008 5:41:55 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 35


Similar Artilces:

export gridview to excel and save in web hosting(without showing the dialog box)
Hi All pro here,          i'm newbie for asp.net , may i ask how to export asp.net grid view to excel and save it directly to web hosting without showing the dialog box out?   hope any pro can answer my question.  thanks in Advance!!   :)  ThanksRegardswilliamPlease remember to click “Mark as Answer” on the post that helps you. Hi, As far as I know, the dialog would appear due to security reasons. May be you will have to use some script to save the file without the prompt.   However to convert gridvi...

In gridview export to excel how to get colors in excel sheet
 Hello All, I am struck with a small problem here.I am displaying a gridview with some colorful rows.But when I am exporting the gridview to excel these colors are not appearing.Please give me a solution.Below i am giving the class file i used to export gridview to excel. public void ExportGridToExcel(DataSet ds, HttpResponse response,string file_name)    {        //first let's clean up the response.object        response.Clear();        response.AddHeade...

change save as type from web page to excel for gridview exported to excel
Hi Everyone, I have a website set up with a button that exports gridviews on the pages to excel.  That works fine.  The users now have asked that when they then in excel go to save the excel (after viewing it), that the save as dialog box automatically uses the excel format, not web page format, and that is automatically switches to their "my documents" folder.  Can I do this?  Right now, the excel is fine, but when you click on File-Save As the file format (save as type) comes up as Web Page, and the name is in quotes.  If you just switch the format to ex...

Export data from web form to excel -- using client's excel app
I am currently trying to figure out if there is any way to export data to the client's excel app. I do not want to use the web server's excel application as it is cutting into the site's performance. Is there any way to use something similar to the what is included below (ExportComponent.vb), but to use the client's excel app? Imports System.Drawing.Color Public Class ExportComponent Inherits System.ComponentModel.Component Public Shared Sub DataToExcel(ByVal dgData As DataGrid, ByVal response As HttpResponse) response.Clear() response.Charse...

Exporting to Excel in Crystal Reports .NET
sir,   I want to export Crystal report to Excel and the following is the code i wrote in the button click.ReportDocument rptExcel = new ReportDocument() ;string strExportFile = "C:/Session_SessionID.xls" ;rptExcel = new RptJobOrderRecap();//report namerptExcel.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile ;rptExcel.ExportOptions.ExportFormatType = ExportFormatType.Excel;ExcelFormatOptions objExcelOptions = new ExcelFormatOptions();objExcelOptions.ExcelUseConstantColumnWidth = false ;rptExcel.ExportOptions.FormatOptions = objExcelOptions ;DiskFileDestinationOp...

export to excel in web form application
hi, there is possible to export datawindow to excel document in web form application? if there is possible, how?can you give a sample application. many thanks Hi, Deny I would recommend you to ask your question in the "webform" newsgroup. Before that it would be of big help to read the existing postings on the theme - search for messages containing some of the words "Excel", "XLS", "DW2XLS". Then if you have further questions, ask. Regards, Ivaylo "Deny Fernando" <half.lefthanded@gmail.com> wrote in message news:a19...

Export web form contents to Excel?
Is there much to exporting the contents of a web form to an Excel spreadsheet?  I've been doing some research and the vast majority of articles seem to pertain to exporting GridView and DataGrid controls.Thanks!  RobertF57:Is there much to exporting the contents of a web form to an Excel spreadsheet?  I've been doing some research and the vast majority of articles seem to pertain to exporting GridView and DataGrid controls.  Base on my experience, you can create Excel.Application to solve your problem, check out the following link: http://support.microsoft.c...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Export to excel without third party tools and without Excel on the Application Server.
I need to export a stored procedure in SQL Server to Excel. The stored procedure has two parameters. I need to Export to excel without third party tools and without Excel on the Application Server. Whats the easiest and best way?   p Unfortunately, this is again a link to another forum www.universalthread.com where this topic was discussed and several solutions provided. <B>Re: Create an Excel file (xls)</B> Thread #1304564 Message #1304876 I don't want to copy and paste code, you may want to check this yourself, but you have to become a member of the site in...

web form fields values export to excel
hii all,           i've a web page where some textboxes , buttons and dropdowns are there, i need to export whole form values to excel but without buttons, dropdown etc. means the selected value of dropdown should be there on excel but dropdown list should not be there.... can any1 help me??? Regards Anant Vijay Have a simple export to excel button that handles the click event to read all the textbox values and the dropdownlist values. Once, this is read, add it to an excel sheet with the following code. Protected Sub Butt...

Static fields in exporting .NET gridview to excel
Hi,I want to design a report that when it's exported to excel, there is a static signature field at the bottom, so when printed out, authorized persons can sign and fax it.Here is the code I have in my button click event:Response.Clear();        Response.AddHeader("content-disposition", "attachment;filename=ticketRpt.xls");        Response.Charset = "";        //         //Response.Cache.SetCacheability(HttpCacheability.NoCache);        Response.ContentType = ...

Exporting data from web form to excel file
I have a page with datgrid and one button called export into excel. I use this code to export data into excel sheet. If my excel file size become more then 50k then i am having error and i can not open or save the excel file. Here is the code:  Server.ScriptTimeout = 12000 Response.ContentType = "application/vnd.ms-excel" dvwdetail = GetSQLData(VSQL) grdapex.DataSource = dvwdetail.Tables(0) grdapex.DataBind() If i have less row means the excel file size is less then 50k then it works fine but if i have more data file size is more then 50k then it give me error m...

Reporting Services Export to Excel
I am using Report Manager as my report interface. I am exporting Reporting Services reports with multiple colors to MS Excel (which has a very limited color palate).When I export the reports to Excel, the system chooses the colors automatically, and I am not very happy with the colors selected. I would like to either control the colors in the export or make the exports black and white.Does anyone have an idea how to do this? Unfortunately, the format that you are using to generate the report is not a global parameter. So a report doesn't really know if it's PDF HTML or EXCEL. Try u...

Export gridview with paging to excel (VB.Net)
OK, I have a gridview I can export to excel, but when I set paging on, it only gets the first page. Below is the code I'm using. Can anyone tell me how to get all the data in the Gridview? VB.Net only please, thanks.  ASPX CODE<asp:SqlDataSource ID="SqlDataSource2" runat="server"         ConnectionString="<%$ ConnectionStrings:PPM %>"         SelectCommand="SELECT TOP 2000 CustomerID,LastName,FirstName,Gender        FROM Patients&q...

Web resources about - Export Gridview to Excel without Colors - asp.net.web-forms

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/12/2016 9:51:03 AM