473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exporting to Excel in a .NET application

Good afternoon,

I have an asp.net project wherein I am trying to export data into
excel. I have that working, however, I am typically dealing with a
large volume of data when I do this. Can anyone suggest a better
method for this job other than reading the data into a datagrid and
then rendering the datagrid as an excel spreadsheet?

Any and all help is greatly appreciated.

Thanks

Aug 24 '06 #1
5 2344

Hi Matt,

We used the OLEDB provider and SQL statements in the web server to export
data to Excel. Here is a sample.

' Opening connections to Excel file.
''connString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=C:\Book1 .xls;Extended Properties=""Ex cel 8.0;HDR=NO;"";"
cnn = New OleDbConnection (connString)
cnn.Open()

Dim cmd As New OleDbCommand
cmd.Connection = cnn

' Reading the number of rows that are present in the data tab
where the population will occur.
cmd.CommandText = QUERY_EXCEL_ROW _COUNT
Dim rdr As OleDbDataReader = cmd.ExecuteRead er
Dim rowCount As Integer = 1
While rdr.Read()
rowCount += 1
End While
rdr.Close()

' Reading fields values from Excel template.
cmd.CommandText = QUERY_EXCEL_TEM PLATE_FIELDS
rdr = cmd.ExecuteRead er
rdr.Read()
Dim index As Integer
For index = 0 To rdr.FieldCount - 1
fieldsNames.Add (rdr.GetString( index))
Next
rdr.Close()
Mike


"Matt Bailey" <ba*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Good afternoon,

I have an asp.net project wherein I am trying to export data into
excel. I have that working, however, I am typically dealing with a
large volume of data when I do this. Can anyone suggest a better
method for this job other than reading the data into a datagrid and
then rendering the datagrid as an excel spreadsheet?

Any and all help is greatly appreciated.

Thanks

Aug 24 '06 #2
This method would work for an existing file only though, right? If so,
I wonder if there is a way to have it create the file first?

Thanks

Aug 24 '06 #3
If you have ExcelXP... you can mimic "Save as Xml".

If you take a regular spreadsheet, and "save as xml" on the file menu. you
can then open it in notepad and look at the xml.

You could mimic this functionality ... by looping over a DataSet or
IDataReader.

Its not a "quick fix". It'll take probably a week to code it up.

You will lose all imbedded object also, as a side note.

If you don't have Excel XP...then you can use the Excel (com) object
library.

...

Lastly, you could use ActiveReports. and programmaticall y export to excel
your in memory report.


"Matt Bailey" <ba*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Good afternoon,

I have an asp.net project wherein I am trying to export data into
excel. I have that working, however, I am typically dealing with a
large volume of data when I do this. Can anyone suggest a better
method for this job other than reading the data into a datagrid and
then rendering the datagrid as an excel spreadsheet?

Any and all help is greatly appreciated.

Thanks

Aug 24 '06 #4
Hi Matt,

If you don't mind purchasing a commercial component I recommend
SpreadsheetGear (http://www.spreadsheetgear.com/). Its an excel
compatible control written entirely in .net. Its available as a visual
component or just a calculation engine. Most importantly its fast and
lets you save as an excel binary document rather than xml.

Cheers,
Pete
Matt Bailey wrote:
Good afternoon,

I have an asp.net project wherein I am trying to export data into
excel. I have that working, however, I am typically dealing with a
large volume of data when I do this. Can anyone suggest a better
method for this job other than reading the data into a datagrid and
then rendering the datagrid as an excel spreadsheet?

Any and all help is greatly appreciated.

Thanks
Aug 24 '06 #5
Thanks for your response. I'll check that out for sure

Aug 24 '06 #6

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

Similar topics

3
9248
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
2
1778
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 would be appreciated! Michael
4
6187
by: Hitesh | last post by:
Hi, I have three datagrid control on my aspx page and one export to excel button, i want to export all the 3 datagrids contents in one excel file. how can i achive that? -- Thanks Hitesh
2
2312
by: pmud | last post by:
Hi, I am exporting data from an EDITABLE DATA GRID EXCEL. But the 1st column in data grid is Edit Column. I want to display all columns in Excel except for the Edit column. The following code which I am using allows exporting only from text data from data grid & not from Edit columns which are link buttons. How to leave this column while displaying data from data grid in Excel?
1
2325
by: NancyA | last post by:
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) dg.RenderControl(hw) Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Response.AppendHeader("content-disposition", "attachment;filename=test.xls") Response.Write(txtWriter.ToString) Response.End()
2
6932
by: Mustufa Baig | last post by:
Hi everybody, I have an ASP.NET website where clients can view their monthly billings by selecting different options. One of the option is the way they want to see the report i.e. whether they want to see it in PDF or EXCEL etc etc..... What I am trying to acheive is depending on their choice of format, I want to send the stream of that particulae selected format to the browser. I have tried couple od solutions but I couldn't able to get...
1
3169
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream As System.IO.MemoryStream = 3 myReport.ExportToStream( ExportFormatType.PortableDocFormat) 4 Response.Clear() 5 Response.Buffer() = True
2
3185
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
5
4178
by: =?Utf-8?B?c2NobWlkdGU=?= | last post by:
Hi How can I Export an HTML Table to excel? My goal is a button, and when the user clicks this button a popup appears asking the user to 'open' or 'save' the generated Excel file. Actually I'm exporting by rendering my table to an htmlwriter and sending this to excel. This is working nearly perfect. There's a problem with Excel's auto-formatting of cells. Excel is changing the content of my cells. '1.23' is getting 'Jan 23',
7
12304
by: leninv | last post by:
Hi, I have the following code where 'recs' is a record set. For i=0 to recs.Fields.Count - 1 if i = 0 then pindnt = string(itmlvl*2," ") response.write pindnt & recs(i) else Response.write recs(i)
0
9474
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7485
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.