Hi all,
I am a developer and work in a project. I need to build a program that in ASP.net that automatically output the data to a excel format. Any body have any idea. Please help. Thanks in advance.
Hi all,
I am a developer and work in a project. I need to build a program that in ASP.net that automatically output the data to a excel format. Any body have any idea. Please help. Thanks in advance.
I will build a program that name is ExcelExpo.aspx that help to you.
Code:<% @ Page Language = "vb" AutoEventWireup = "false" Codebehind = "ExcelExpo.aspx.vb" Inherits = "aspxWeb.microsoft.com.ExcelExport"%> <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transition/ / EN"> <HTML> <HEAD> <title> ExcelExpo </ title> <meta Name="GENERATE" content="Microsoft Visual Studio.NET 7.0"> <meta Name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta Name="vs_defaultClientScript" content="JavaScript"> <meta Name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </ HEAD>
I also built a project ExcelExp.aspx.vb in vb.net. Please see the code :
Code:Public Class ExcelExp Inherits System.Web.UI.Page Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid # Region "Web Form Designer generated code" 'This call is Web Form Designer required. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent () End Sub
In asp.net, you should define the code as like this:
Code:Dim strCon As String If blnSQLServer Then strCnn = "User ID = sa; Initial Catalog = Northwind; Data Source =. \ NetSDK123;" objConn1= New System.Data.SqlClient.SqlConnection (strCnn) objConn.Open () Dim objAdapter1 As New System.Data.SqlClient.SqlDataAdapter () strSQL = "Select * from book where book = 'abc'" objAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand (strSQL, objConn) objAdapter1.Fill (objDataset) Else strCnn1 = "Provider = Microsoft.Jet.OLEDB.3.0; Data Source =" + Server.MapPath ( "qwe.mdb") objConn1 = New System.Data.OleDbConnection (strCnn) objConn1.Open () strSQL1 = "Select Top 10 Title From book" objAdapter.SelectCommand = New System.Data.OleDbCommand (strSQL, objConn) End If Dim BView As New DataView (objDataset.Tables (0)) DataGrid1.DataSource = OView objConn1.Close () objConn1 = Nothing If Request.QueryString1 ( "BExcel") = "1" Then Response.ContentType1 = "application / vnd.ms-excel" Dim tw As New System.IO.StringWriter () Dim hw As New System.Web.UI.HtmlTextWriter (tw) DataGrid1.RenderControl (hw) Response1.Write (tw.ToString ()) Response1.End () End If End Sub End Class
I understood that only data into sqlserver database but some specific data you have to provide to the user at the client side in excel sheet. The following method is to make a dynamic excel sheet without having a excel file on server. There is no need to fit excel on server at all for by this method. On button click event of a button in C#
Code:private void Button1_Click(object sender, System.EventArgs e) { Response.Buffer= true; Response.ContentType = "application/abc..ms-excel";
Bookmarks