473,320 Members | 1,719 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.

Exporting datagrid to Excel Pivot Table

Does anyone have an example of how to export a datagrid to an Excel pivot
table? The code below exports the grid contents to Excel using the Response
object. I'd like to expand it to show the data in a pivot table. Avoiding a
3rd party control is preferable.
Thanks,
Tim

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""

Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

'First write the dgResults grid column names to the datatable
For i = 0 To (Session("dvGrid").Table.Columns.Count - 1)
sOutput = Session("dtResults").Columns(i).columnname() 'get the
column name
dtCounts.Columns.Add(New DataColumn(sOutput, GetType(String)))
Next

'Now write the grid contents to the datatable
For i2 = 0 To Session("dvGrid").Table.Rows.Count - 1
drRow1 = dtCounts.NewRow
For i = 0 To (Session("dvGrid").Table.Columns.Count - 1)
drRow1(i) = Session("dvGrid").Table.Rows(i2).item(i)
Next 'get next cell (column value) in grid line
dtCounts.Rows.Add(drRow1)
Next

With dgCounts
.DataSource = New DataView(dtCounts)
.DataBind()
End With

' Get the HTML for the control.
dgCounts.RenderControl(hw)

' Write the HTML back to the browser.
Response.Write(tw.ToString())
Response.End()

Nov 19 '05 #1
0 1699

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

Similar topics

3
by: John | last post by:
Is there a way to code the button that's available in the query window--microsoft excel icon that exports to excel. I know transferspreadsheet will do this---but I want the query, which is in a...
2
by: Michael | last post by:
I need to be able to export data from a web form into MS Excel. I know you can do it with a VB.net windows application, but how can you do it with an asp.net application using vb.net? Any help...
3
by: Grey | last post by:
My requirement is The user has input data in the asp.net application and the data has been stored in MSDE. After the user click the save data in MSDE, the web application will start the client's...
1
by: Grey | last post by:
How to export a dataset to excel file. I need the exported data should be named with variable in excel as I need to do pivot table in the excel. So do I need to created pivot table before and only...
3
by: | last post by:
Hello, I have a routine in my Windows application that exports the contents of a datagrid to Excel. It is modeled closely after the HowTo example on MSDN: http://tinyurl.com/5g2jm. Depending...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
8
by: Jerome Ranch | last post by:
Okay So I've got pivot tables setup in Access 2003. Only about 30K records in the current 2005 databases...the pivots summarize the info in a number of nice ways. I need to get the pivot tables...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name to the excel file as "temp.xls" inside the code....
2
by: Gary Dunne | last post by:
Hi All, I'm struggling to find the correct syntax for creating a Pivot table in an excel file via VB . Net 2005 The Excel help file is not particularly helpful where parameters are concerned...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.