473,549 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

gridview properties for excel export

Hi, I'm looking for information about gridview's cell properties...

I've the following case: one gridview with alternatirg row style and
normalrowstyle, 3 o 4 custom styles that are applied to cells in the
row_databound event, and now I nedd to do a excel export of the gridview
exactly as is showed in the browser, but al the examples and thigs I've
tried don't send the cell color to excel and now I think if I can read the
gridview properties in the prerender event to get them for each cell.

I will apreciate any help,

--
Greetings and so many thanks,
Sergio E.
Jul 24 '07 #1
6 6468
A few years back in one of the contracts we did something similar to this -
needed to export to excel a grid with formatting.
We had xsl stylesheet defined and then Transformed the incoming Dataset xml
into html. Then you change content type to "applicatio n/vnd.xls" and let
Excel open it.
I think starting from 97 version (I am not sure about prior ones) Excel will
correctly process html.
The html will have to be self contained - means no external references (css
files, for example) - you will have to define everything inside your
transformation.

"Sergio E." wrote:
Hi, I'm looking for information about gridview's cell properties...

I've the following case: one gridview with alternatirg row style and
normalrowstyle, 3 o 4 custom styles that are applied to cells in the
row_databound event, and now I nedd to do a excel export of the gridview
exactly as is showed in the browser, but al the examples and thigs I've
tried don't send the cell color to excel and now I think if I can read the
gridview properties in the prerender event to get them for each cell.

I will apreciate any help,

--
Greetings and so many thanks,
Sergio E.
Jul 25 '07 #2
thank's for answering me, i was trying and the big trouble is that there is
a css stylesheet that contains al de colors for the rows, alternate rows,
and special cells, and some cells are re-styled in the gridview_rowdat abound
event so i must use this styles and i must convert the gridview, not the
dataset... mi big trouble now is the fact that the color are in css
classes...and i don't know hot to access this information...

if i can do some like
me.getcssclass( me.gridview1.ro ws(0).cells(0). cssclass).backg roundcolor then
i have my problem solved!, but i can't find information about how to get the
specification of some class included in an attached file to an aspx with the
<link href="Styles/Normal.css" rel="stylesheet " type="text/css" />
directive.

there is the code i'm using... and i don't understand why the colors are not
rendered ... i supose that is because is the browser itself who paints the
colors in te last step:

public sub Excel()
Dim sb As StringBuilder = New StringBuilder()
Dim sw As StringWriter = New StringWriter(sb )
Dim hw As HtmlTextWriter = New HtmlTextWriter( sw)
Dim pag As Page = New Page()
Dim frm As HtmlForm = New HtmlForm()
Dim gv As GridView = Me.GVResultado

pag.EnableEvent Validation = False
gv.AllowPaging = False
gv.EnableViewSt ate = False
gv.DataBind()
If (Not (gv.HeaderRow) Is Nothing) Then
PrepareControlF orExport(gv.Hea derRow)
End If
For Each row As GridViewRow In gv.Rows
PrepareControlF orExport(row)
Next
If (Not (gv.FooterRow) Is Nothing) Then
PrepareControlF orExport(gv.Foo terRow)
End If

pag.DesignerIni tialize()
pag.Controls.Ad d(frm)
frm.Controls.Ad d(gv)
pag.RenderContr ol(hw)
Response.Clear( )
Response.Buffer = True
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-Disposition", "attachment;fil ename=data.xls" )
Response.Charse t = "UTF-8"
Response.Conten tEncoding = Encoding.Defaul t
Response.Write( sb.ToString())
gv.AllowPaging = True
gv.EnableViewSt ate = True
gv.DataBind()
Response.End()
end sub

--
thanks again,
Sergio E.
Jul 25 '07 #3
Sergio,

As far as I know you cannot do anything like
me.getcssclass( me.gridview1.ro ws(0).cells(0). cssclass).backg roundcolor
this is usually quite complex process performed (often differently) by
different browsers.
What I would suggest you to try would be to try reading the content of your
css file (provided it does not have @includes from other css files) and try
to stick it into the header of your output within <styletags - this way the
result html will become self-contained, and hopefully contain enough
information for Excel to correctly display your information.

Let me know how you go.
If you have any more questions, I would be more than happy to assist

"Sergio E." wrote:
thank's for answering me, i was trying and the big trouble is that there is
a css stylesheet that contains al de colors for the rows, alternate rows,
and special cells, and some cells are re-styled in the gridview_rowdat abound
event so i must use this styles and i must convert the gridview, not the
dataset... mi big trouble now is the fact that the color are in css
classes...and i don't know hot to access this information...

if i can do some like
me.getcssclass( me.gridview1.ro ws(0).cells(0). cssclass).backg roundcolor then
i have my problem solved!, but i can't find information about how to get the
specification of some class included in an attached file to an aspx with the
<link href="Styles/Normal.css" rel="stylesheet " type="text/css" />
directive.

there is the code i'm using... and i don't understand why the colors are not
rendered ... i supose that is because is the browser itself who paints the
colors in te last step:

public sub Excel()
Dim sb As StringBuilder = New StringBuilder()
Dim sw As StringWriter = New StringWriter(sb )
Dim hw As HtmlTextWriter = New HtmlTextWriter( sw)
Dim pag As Page = New Page()
Dim frm As HtmlForm = New HtmlForm()
Dim gv As GridView = Me.GVResultado

pag.EnableEvent Validation = False
gv.AllowPaging = False
gv.EnableViewSt ate = False
gv.DataBind()
If (Not (gv.HeaderRow) Is Nothing) Then
PrepareControlF orExport(gv.Hea derRow)
End If
For Each row As GridViewRow In gv.Rows
PrepareControlF orExport(row)
Next
If (Not (gv.FooterRow) Is Nothing) Then
PrepareControlF orExport(gv.Foo terRow)
End If

pag.DesignerIni tialize()
pag.Controls.Ad d(frm)
frm.Controls.Ad d(gv)
pag.RenderContr ol(hw)
Response.Clear( )
Response.Buffer = True
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-Disposition", "attachment;fil ename=data.xls" )
Response.Charse t = "UTF-8"
Response.Conten tEncoding = Encoding.Defaul t
Response.Write( sb.ToString())
gv.AllowPaging = True
gv.EnableViewSt ate = True
gv.DataBind()
Response.End()
end sub

--
thanks again,
Sergio E.
Jul 25 '07 #4
hi, thanks for this solution, i can read the css file, but i can'f find the
sintax to do the next part (the output to the header with the <styletags)
i have the full css file loaded into a stringbuilder exactly as appears in
the physical file...

Can you post an example of the output to the header?

Thank's again.

--
greetings
Sergio E.
Jul 25 '07 #5
hi, i finally solve the problem using this code:

Response.Write( "<HEAD><STY LE type=""text/css"">" +
ReadCss("~/Styles/Normal.css") + "<STYLE></HEAD>")

and then write the gridview...

where readcss is a private function wich reads a given css file and returns
it as simple string.

--
greetings,
Sergio E.

Jul 25 '07 #6
glad that you have it all worked out :-)

"Sergio E." wrote:
hi, i finally solve the problem using this code:

Response.Write( "<HEAD><STY LE type=""text/css"">" +
ReadCss("~/Styles/Normal.css") + "<STYLE></HEAD>")

and then write the gridview...

where readcss is a private function wich reads a given css file and returns
it as simple string.

--
greetings,
Sergio E.

Jul 26 '07 #7

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

Similar topics

0
1231
by: Peter | last post by:
I experienced a bug, "Control GridView1 of type GridView myst be placed inside a form tag with runat=server". But I did so. I do not why, please advise. my code as below. Thanks. Peter <%@ Page language="C#" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) {
4
2495
by: Tom | last post by:
I have a gridview on all of my web pages in my web app and they all export to excel. I have one page where the gridview is binding to a datatable that i created and only the first column is exporting to excel. How can I get the entire grid to export to excel?
3
10102
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type GridView must be placed inside form tag with runat = server". I understand that this is because my Masterpage has the formtag and not the eventslisting...
0
1688
by: johnlim20088 | last post by:
Hi, Hi, currently I have a code below on my Listcontact.aspx file to export my gridview data to excel:- It is work success, and export the 'Contacts.xls' to my folder. But have following problem-> 1) when i open with wordpad, it show html tag with the value. 2) when i open with excel, it look ok, BUT i don't want the colour and button...
1
3357
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The problem is, the image won't display unless I'm connected to the Internet or if I use a relative path and have the image stored relative to the excel...
2
3924
by: =?Utf-8?B?SkRSYXZlbg==?= | last post by:
I have searched all over and can not seem to find an effective way to simply copy the contents of a ASP:gridview column to the clipboard based on a button or similar HTML or ASP.NET control. ASP 2.0 web application with VB.NET code developing in Visual Studio 2005 Pro. Gridview has several columns, and users need the ability to copy one of...
1
3383
by: Yordan Georgiev | last post by:
I have a search form using master page , which is dynamically generated from the column names of the database - when the users have a search result it should be exported to Excel by clicking the button ... I get the following message : A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An...
0
1548
by: =?Utf-8?B?U2hhbQ==?= | last post by:
Hai all, In my application, I need to Export webpage things into hard drive. I am using gridview, and i export all things(with the help of some sites) into excel except images. Please, Can any one tell me how to export all contents of(Including Images) gridview into excel.
0
1907
by: hiranmaie | last post by:
Hi, I have a gridview with more than 10 rows of data. I want to export these gridview values into an excel sheet along with the header names of excel sheet. I am not using a database here. I need to open an excel application at the click of a button and save the gridview values into the excel sheet opened. Please help me out to solve...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7450
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.