Click here to Skip to main content
13,191,877 members (65,672 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 8 Aug 2007

export sql server or other database query in to excel or word by using c# programming

, 8 Aug 2007
Rate this:
Please Sign up or sign in to vote.
export sql server or other database query in to excel or word by using c# programming


hi. i need a procedure for export a large data reported from sql server in excel document. by using my method we can do it. this method is vary high speed.


this code is use full for database query (large data). i assume that that data is text base and do not contain any image and binary data. if other, use must have some modification in this code.

Using the code

my idea is based on office 2003 feature for supporting a HTML data. you can make a HTML data and open with every office application. for generate excel document use can use a TABLE tag. each table cell is excel cell's too.

A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.

base of HTML generation is following code.

while (dr.Read())
       for (int i = 0; i < dr.FieldCount; i++)
          sbrHTML.Append("<TD>" + good_value(dr.GetValue(i).ToString()) + "</TD>");

after generation save a document by .xls .

the excel document was made (is it a simple?).

now in your application use following code...

clsExcel clsexcel = new clsExcel("sql text", "report header");;

note that. if your language is right to left. you must use this code before you HTML

اگر متن فارسي داريد بايد از اين كد استفاده نماييد

sbrHTML.Append("<meta http-equiv=\"Content-Type\" 
    <style>.text { mso-number-format:\\@; } </style><TABLE 
        class=\"text\" Border=1 ID=\"Table1\">");

if you can't run this code. mail to me.



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

jalal khodabandeh
Web Developer
Greece Greece
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralReinvent the wheel Pin
Mark Nischalke9-Aug-07 3:04
mvpMark Nischalke9-Aug-07 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171017.2 | Last Updated 9 Aug 2007
Article Copyright 2007 by jalal khodabandeh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid