473,569 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export to Excel issue (C#)

Hello,

how to ask saveas dialog before writing the data to the excel file?
right now im able to save in c drive or any other specified location only.

any solution will be a great help!

System.Text.Str ingBuilder sbrHTML=new System.Text.Str ingBuilder("");

//StringBuilder sbrHTML = new StringBuilder() ;
SqlConnection cn = new
SqlConnection(S ystem.Configura tion.Configurat ionSettings.App Settings["connectionStri ng"]);

SqlCommand dc = new SqlCommand("Sel ect * From wc_ingredient", cn);

SqlDataReader dr ;

int i=0;

cn.Open();

dr = dc.ExecuteReade r();

//Making HTML

sbrHTML.Append( "<TABLE Border=1 ID='Table1'>");

sbrHTML.Append( "<TR><TD ColSpan=35><Fon t Size=5>Report</Font></TD><TR>");

sbrHTML.Append( "<TR><TH>Id </TH><TH>Ingredie nt
Name</TH><TH>measure</TH><TH>Cost</TH><TH>Onhand Qty</TH><TH>Supplier
Code</TH><TH>Supplier Name</TH><TH>Supplier purchase unit</TH><TH>Supplier
Factor</TH><TH>Onhand Factor</TH><TH>Supplier Brand</TH><TH>Supplier
Case</TH><TH>Supplier Purchase unit</TH><TH>Supplier use
unit</TH><TH>Supplier cost unit</TH></TR>");

while(dr.Read() )

{

i++;

sbrHTML.Append( "<TR><TD>" + dr.GetValue(0). ToString() + "</TD><TD>"

+ dr.GetValue(1). ToString() + "</TD><TD>"

+ dr.GetValue(2). ToString() + "</TD><TD>"

+ dr.GetValue(3). ToString() + "</TD><TD>"

+ "</TR>" );

}

sbrHTML.Append( "</TABLE>");

sbrHTML.Append( "<BR><BR><B>Tot al Number of Ingredients are " + i.ToString()
+ "</B>");

string path="c:\\Ingre dient_Report.xl s";

StreamWriter swXLS =new StreamWriter("c :\\Report.xls") ;

swXLS.Write(sbr HTML.ToString() );
swXLS.Close();

--
--
Thanks,

Arvind
Jan 24 '06 #1
2 6534
Arvind,

I have an example on my website about how to output a datagrid as an excel
spreadsheet. It's very similar to what you're doing here. You may want to
take a look at the code: http://www.aboutfortunate.com?page=codelibrary.
It's the second example in the datagrid.

Also, if you want to force the save as dialog check out this article:
http://aspdot.net/articles/forcedialogandcompression/

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Arvind R" <arvind r@erivasystems. com> wrote in message
news:uo******** ******@TK2MSFTN GP14.phx.gbl...
Hello,

how to ask saveas dialog before writing the data to the excel file?
right now im able to save in c drive or any other specified location only.

any solution will be a great help!

System.Text.Str ingBuilder sbrHTML=new System.Text.Str ingBuilder("");

//StringBuilder sbrHTML = new StringBuilder() ;
SqlConnection cn = new
SqlConnection(S ystem.Configura tion.Configurat ionSettings.App Settings["connectionStri ng"]);

SqlCommand dc = new SqlCommand("Sel ect * From wc_ingredient", cn);

SqlDataReader dr ;

int i=0;

cn.Open();

dr = dc.ExecuteReade r();

//Making HTML

sbrHTML.Append( "<TABLE Border=1 ID='Table1'>");

sbrHTML.Append( "<TR><TD ColSpan=35><Fon t Size=5>Report</Font></TD><TR>");

sbrHTML.Append( "<TR><TH>Id </TH><TH>Ingredie nt
Name</TH><TH>measure</TH><TH>Cost</TH><TH>Onhand Qty</TH><TH>Supplier
Code</TH><TH>Supplier Name</TH><TH>Supplier purchase unit</TH><TH>Supplier
Factor</TH><TH>Onhand Factor</TH><TH>Supplier Brand</TH><TH>Supplier
Case</TH><TH>Supplier Purchase unit</TH><TH>Supplier use
unit</TH><TH>Supplier cost unit</TH></TR>");

while(dr.Read() )

{

i++;

sbrHTML.Append( "<TR><TD>" + dr.GetValue(0). ToString() + "</TD><TD>"

+ dr.GetValue(1). ToString() + "</TD><TD>"

+ dr.GetValue(2). ToString() + "</TD><TD>"

+ dr.GetValue(3). ToString() + "</TD><TD>"

+ "</TR>" );

}

sbrHTML.Append( "</TABLE>");

sbrHTML.Append( "<BR><BR><B>Tot al Number of Ingredients are " +
i.ToString() + "</B>");

string path="c:\\Ingre dient_Report.xl s";

StreamWriter swXLS =new StreamWriter("c :\\Report.xls") ;

swXLS.Write(sbr HTML.ToString() );
swXLS.Close();

--
--
Thanks,

Arvind

Jan 24 '06 #2
I see a lot of the same code out there to export data from an ASP.NET
DataGrid to Excel. All the solutions are pretty similar. One thing I have
noticed with the solution(s) provided is that if a user opens the file,
rather than saving it, the Excel file will open in the user's browser window
and disable the Back button. How can you allow a user to open the Excel file
and be able to use the Back button to get back to the site?

Thanks!

Brian
"S. Justin Gengo [MCP]" wrote:
Arvind,

I have an example on my website about how to output a datagrid as an excel
spreadsheet. It's very similar to what you're doing here. You may want to
take a look at the code: http://www.aboutfortunate.com?page=codelibrary.
It's the second example in the datagrid.

Also, if you want to force the save as dialog check out this article:
http://aspdot.net/articles/forcedialogandcompression/

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Arvind R" <arvind r@erivasystems. com> wrote in message
news:uo******** ******@TK2MSFTN GP14.phx.gbl...
Hello,

how to ask saveas dialog before writing the data to the excel file?
right now im able to save in c drive or any other specified location only.

any solution will be a great help!

System.Text.Str ingBuilder sbrHTML=new System.Text.Str ingBuilder("");

//StringBuilder sbrHTML = new StringBuilder() ;
SqlConnection cn = new
SqlConnection(S ystem.Configura tion.Configurat ionSettings.App Settings["connectionStri ng"]);

SqlCommand dc = new SqlCommand("Sel ect * From wc_ingredient", cn);

SqlDataReader dr ;

int i=0;

cn.Open();

dr = dc.ExecuteReade r();

//Making HTML

sbrHTML.Append( "<TABLE Border=1 ID='Table1'>");

sbrHTML.Append( "<TR><TD ColSpan=35><Fon t Size=5>Report</Font></TD><TR>");

sbrHTML.Append( "<TR><TH>Id </TH><TH>Ingredie nt
Name</TH><TH>measure</TH><TH>Cost</TH><TH>Onhand Qty</TH><TH>Supplier
Code</TH><TH>Supplier Name</TH><TH>Supplier purchase unit</TH><TH>Supplier
Factor</TH><TH>Onhand Factor</TH><TH>Supplier Brand</TH><TH>Supplier
Case</TH><TH>Supplier Purchase unit</TH><TH>Supplier use
unit</TH><TH>Supplier cost unit</TH></TR>");

while(dr.Read() )

{

i++;

sbrHTML.Append( "<TR><TD>" + dr.GetValue(0). ToString() + "</TD><TD>"

+ dr.GetValue(1). ToString() + "</TD><TD>"

+ dr.GetValue(2). ToString() + "</TD><TD>"

+ dr.GetValue(3). ToString() + "</TD><TD>"

+ "</TR>" );

}

sbrHTML.Append( "</TABLE>");

sbrHTML.Append( "<BR><BR><B>Tot al Number of Ingredients are " +
i.ToString() + "</B>");

string path="c:\\Ingre dient_Report.xl s";

StreamWriter swXLS =new StreamWriter("c :\\Report.xls") ;

swXLS.Write(sbr HTML.ToString() );
swXLS.Close();

--
--
Thanks,

Arvind


Feb 24 '06 #3

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

Similar topics

3
5235
by: Saur | last post by:
Hi, I am using an export to excel functionality from my ASP page. I have set the content type as Response.ContentType = "application/vnd.ms-excel" The data i am exporting has values like 1-2, 2-5 Now when they get exported to excel, these values get exported as 1-02-2003,2-05-2003.
4
3113
by: Gary Wright | last post by:
I have an Access 2K database split into front and back. Quite often the users want to do some data analysis that I have not created a report for so they want to export some subset of the data into and Excel spreadsheet. Since the data often comes from many different tables, I have decided to create a temporary Access table, put all the data...
6
13116
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel spreadsheet. I'm having trouble with my code at the point at which it hits ".ReadRecords" -- the module just runs and runs without generating anything. I've...
4
2896
by: Prasad Dannani | last post by:
Hi, We have to export our data in sql server table to any excel sheet. We have a template to export, using oledb we are inserting rows to this template and generating the excel output. The problem here is we are getting a single quote extra in front of each cell. can anyone help us in clearing this kind of an issue. we tried sending...
3
2008
by: Marja Ribbers-de Vroed | last post by:
Hi, One of my clients has a strange problem with my webapplication which I think may be related to some firewall setting on his computer. On several screens in the application, it is possible to click on an icon to start an export of data to Excel. The click on the icon triggers a form submit (a post, not a get) to a blank page, thereby...
13
13193
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...
5
2811
by: karthick | last post by:
Hi, I am exporting a Gridview to Excel and it works fine without any issues. But as one of the field holds values such as "71646E100" it gets converted to: "7.16E+104" (like a formula) in Excel. How can I prevent this from happening ?. I need to value to be in Excel as it is displayed in the Gridview (on the web page).
1
9762
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...
2
1764
by: leena13 | last post by:
Hi, The number of rows in the datagrid on my page are approx. around 14130. When I click on the button that exports the records to excel sheet, the page goes blank (I observed that none of the events are firing). To confirm this is happening because of the no. of rows, I modified the SP to retrieve around only 100 records. I could export...
19
11215
by: cj2 | last post by:
#1 Is there a quick way to export a datatable to an excel file? Or delimited file? #2 Where is the appropriate Microsoft monitored group to ask about writing reports in SQL Reporting services or SQL Server Business Intelligence Development Studio or whatever it's called?
0
7703
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
7618
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
7926
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. ...
0
8138
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...
0
7983
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...
1
5514
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
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
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
0
946
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...

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.