473,396 Members | 1,748 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,396 software developers and data experts.

What methods can export excel file from stored procedure with parameters which input from web form?

What methods can export excel file from stored procedure with parameters
which input from web form?

Mar 28 '06 #1
3 2572
You're going to have to do a lot of this yourself - there's nothing
built into the Frawework to support this althought here are many third
party components that can help with creating Excel files

I've used the Microsoft.Office.Interop.Excel namespace inside
You'll need to download and install Office Primary Interop Assemblies.

I've used it in a Windows app to open Excel and write to cells.

The trouble is these aren't meant to be used as server side components.
Office 2006 contains Excel object model that is decoupled from the UI
and intended for server-side use.

Mar 28 '06 #2
one method to do it...

bring the parametrized data back into a datagrid and add a 'save to excel'
button on your form

the following code in your webform:
(you have to use your own datagrid's name in the top btnExportToExcel_Click,
the ClearControl method takes out troublesome controls from the datagrid (in
memory) and when it's done it calls the datagrid's RenderControl Method, a
File save as dialog is thrown up and you're there)

if your dataset is too large, this might not be an ideal method, but it
works fine for exporting datagrid data from a web page

private void btnExportToExcel_Click(object sender, System.EventArgs e)
//export to excel

Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new

this.ClearControls([enter your datagrid's name here]);
[Enter your datagrid's name here].RenderControl(oHtmlTextWriter);




private void ClearControls(Control control)
for (int i=control.Controls.Count -1; i>=0; i--)

if (!(control is TableCell))
if (control.GetType().GetProperty("SelectedItem") != null)
LiteralControl literal = new LiteralControl();
literal.Text =
(string)control.GetType().GetProperty("SelectedIte m").GetValue(control,null);
if (control.GetType().GetProperty("Text") != null)
LiteralControl literal = new LiteralControl();
literal.Text =
(string)control.GetType().GetProperty("Text").GetV alue(control,null);
good luck

Mar 28 '06 #3
There are a variety of ways to export data to Excel, most of which are
detailed here:

If you want a more automatic approach, you might try one of these

You could also consider Crystal Reports or the new VSTO:

I hope this helps,
Steve C. Orr, MCSD, MVP
"ABC" <ab*@abc.com> wrote in message
What methods can export excel file from stored procedure with parameters
which input from web form?

Mar 29 '06 #4

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

Similar topics

by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
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....
by: Mark Flippin | last post by:
This is for a reporting problem using: Access 2000 SQL Server 2000 Both at SP3 I've a stored procedure in SQL Server 2000 which builds a result set from a disparate set of tables, utilizing...
by: Bob | last post by:
I'm new to Access projects and SQL server and am not a veteran VB programmer. There's a cry for help! I'm attempting to print the current form on screen by using a command button which the user...
by: Johnny | last post by:
I have a stored procedure that takes three input parameters and returns a single record result set. The stored procedure is declare as follows: p_getTaxAmount (@ZipCodeDtlId uniqueidentifier,...
by: Bilbo | last post by:
I have a a headscratcher here: I have a form that when submitted should do 2 things when a user enters data and then clicks the Add button. Here goes: 1. Call a stored procedure called...
by: Vadim Vulfov | last post by:
My task was to create Crystal Report on ASP.NET page to display different date depending on to textboxes From Date and To Date. I created stored procedure in SQL with two parameters from_date and...
by: Jiro Hidaka | last post by:
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...
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
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...
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,...
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,...

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.