473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export To Excel

Hello,

I would like to know of a fast way to export data source data into an Excel
sheet.

I found a way from C# Corner(Query Tool to Excel using C# and .NET) which is
a neat little way of exporting dataset data to an excel using the Excel COM
object.

This works fine but the problem is its pretty darn slow when exporting large
amounts of data(>5000).

I would like a faster alternative through .NET.

One other way I can think of is to create a VBA macro within excel that
executes an T-SQL stored procedure and this macro is called by a .NET
program. I have not tried this option yet because I would like to get your
input first.

Thanx in advance!

--
Jiro Hidaka
********
Programmer For
Medisca Pharmaceutique
Apr 21 '06 #1
4 15001
Another approach is to dump the data into a datagrid and do a response.write
taking care to change content type to vnd-excel.

--

_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Jiro Hidaka" <me*****@newsgr oups.nospam> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Hello,

I would like to know of a fast way to export data source data into an
Excel
sheet.

I found a way from C# Corner(Query Tool to Excel using C# and .NET) which
is
a neat little way of exporting dataset data to an excel using the Excel
COM
object.

This works fine but the problem is its pretty darn slow when exporting
large
amounts of data(>5000).

I would like a faster alternative through .NET.

One other way I can think of is to create a VBA macro within excel that
executes an T-SQL stored procedure and this macro is called by a .NET
program. I have not tried this option yet because I would like to get your
input first.

Thanx in advance!

--
Jiro Hidaka
********
Programmer For
Medisca Pharmaceutique

Apr 21 '06 #2

If you have XP Excel (guaranteed), you can export data to Excel.. in the xml
format.

This way you don't have to use or reference the excel object library.

You cannot do graphs, imbedded objects, but you can do raw data.

CHeck this blog:
http://spaces.msn.com/sholliday/ 9/22/2005
(that blog is for reading excel/xml data... its a little tricker to export
it to excel)


"Jiro Hidaka" <me*****@newsgr oups.nospam> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Hello,

I would like to know of a fast way to export data source data into an Excel sheet.

I found a way from C# Corner(Query Tool to Excel using C# and .NET) which is a neat little way of exporting dataset data to an excel using the Excel COM object.

This works fine but the problem is its pretty darn slow when exporting large amounts of data(>5000).

I would like a faster alternative through .NET.

One other way I can think of is to create a VBA macro within excel that
executes an T-SQL stored procedure and this macro is called by a .NET
program. I have not tried this option yet because I would like to get your
input first.

Thanx in advance!

--
Jiro Hidaka
********
Programmer For
Medisca Pharmaceutique

Apr 21 '06 #3
Hi thanx so much for your reply,

I am not using ASP.NET but in the future I will use this approach.

--
Jiro Hidaka
********
Programmer For
Medisca Pharmaceutique
"Alvin Bruney" wrote:
Another approach is to dump the data into a datagrid and do a response.write
taking care to change content type to vnd-excel.

--

_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Jiro Hidaka" <me*****@newsgr oups.nospam> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Hello,

I would like to know of a fast way to export data source data into an
Excel
sheet.

I found a way from C# Corner(Query Tool to Excel using C# and .NET) which
is
a neat little way of exporting dataset data to an excel using the Excel
COM
object.

This works fine but the problem is its pretty darn slow when exporting
large
amounts of data(>5000).

I would like a faster alternative through .NET.

One other way I can think of is to create a VBA macro within excel that
executes an T-SQL stored procedure and this macro is called by a .NET
program. I have not tried this option yet because I would like to get your
input first.

Thanx in advance!

--
Jiro Hidaka
********
Programmer For
Medisca Pharmaceutique


Apr 21 '06 #4
Hi,

I have never written data in excel , I have always read it.
I do use the oledb provider. I'm sure that to write should be the same
thing.
In any case here s the code I use

string srcConnString = @"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source="
+ sourceFile + @";Extended Properties=""Ex cel 8.0;HDR=YES;""" ;
string srcQuery = "Select * from [" + GetExcelSheetNa mes(
sourceFile)[0] + "]"; //read from the first sheet

OleDbConnection srcConn = new OleDbConnection ( srcConnString);
srcConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand( srcQuery, srcConn);

readerExcel = objCmdSelect.Ex ecuteReader(
CommandBehavior .CloseConnectio n);
while( readerExcel.Rea d() ){....}


static String[] GetExcelSheetNa mes(string excelFile)
{
OleDbConnection objConn = null;
System.Data.Dat aTable dt = null;

try
{
// Connection String. Change the excel file to the file you
// will search.
String connString = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + excelFile + ";Extended Properties=Exce l 8.0;";
// Create connection object by using the preceding connection string.
objConn = new OleDbConnection (connString);
// Open connection with the database.
objConn.Open();
// Get the data table containg the schema guid.
dt = objConn.GetOleD bSchemaTable(Ol eDbSchemaGuid.T ables, null);

if(dt == null)
{
return null;
}

String[] excelSheets = new String[dt.Rows.Count];
int i = 0;

// Add the sheet name to the string array.
foreach(DataRow row in dt.Rows)
{
excelSheets[i] = row["TABLE_NAME "].ToString();
i++;
}

return excelSheets;
}
catch(Exception ex)
{
return null;
}
finally
{
// Clean up.
if(objConn != null)
{
objConn.Close() ;
objConn.Dispose ();
}
if(dt != null)
{
dt.Dispose();
}
}
}


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jiro Hidaka" <me*****@newsgr oups.nospam> wrote in message
news:C2******** *************** ***********@mic rosoft.com...
Hello,

I would like to know of a fast way to export data source data into an
Excel
sheet.

I found a way from C# Corner(Query Tool to Excel using C# and .NET) which
is
a neat little way of exporting dataset data to an excel using the Excel
COM
object.

This works fine but the problem is its pretty darn slow when exporting
large
amounts of data(>5000).

I would like a faster alternative through .NET.

One other way I can think of is to create a VBA macro within excel that
executes an T-SQL stored procedure and this macro is called by a .NET
program. I have not tried this option yet because I would like to get your
input first.

Thanx in advance!

--
Jiro Hidaka
********
Programmer For
Medisca Pharmaceutique

Apr 24 '06 #5

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

Similar topics

1
5022
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table. Before I iterate through the recordset I instruct the browser that the content type is Excel using the following line: (Response.ContentType = "application/vnd.ms-excel") This works fine with Excel 2003 but with older versions (I tested Excel...
5
3761
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
2
3983
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.Charset = ""; this.EnableViewState = false;
6
4057
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and footer for the worksheet, not for the columns. Is this possible? If so, I really need the code immediately. Thank you, Elena
13
13198
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel" HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ABC.xls") HttpContext.Current.Response.Write(strHTML) HttpContext.Current.Response.End() However when the user tries to save it the Default File Type is Web Page(*.htm; *.html)
5
31906
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
9767
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm having I'd be most appreciative. The database is already constructed, I'm just wanting to export the data to an excel file. In short, I'm hoping to export two Tables (or queries...not sure which to use - they both seem to have the same data) in...
1
10480
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
3
7137
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this file but save it as an excel file. The data in this excel file will be imported into an Access database. The
2
6403
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the method.... it creates 6 sheets # region Namespaces using System;
0
7886
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
8381
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
8035
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6688
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3886
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1238
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.