want to fransfer datas from sql server to excel
-
I am using asp.net+vb.net I want to export datas from sqlserver to excel.I wrote code for that.My it display in the internet explorer same page. I want to display in another page and want to set only print button for that page. The code i wrote is given below. ***************** Private Sub BindReport() If Session("Rep") Is Nothing Then Dim ConnInfo As New ConnectionInfo With ConnInfo .ServerName = "User1" .DatabaseName = "IMS" .UserID = "sa" .Password = "" End With Dim rep As New ReportDocument rep.Load(Server.MapPath("Crystalreport2.rpt")) Me.CrystalReportViewer1.ReportSource = rep Dim RepTbls As Tables = rep.Database.Tables For Each RepTbl As Table In RepTbls Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo RepTblLogonInfo.ConnectionInfo = ConnInfo RepTbl.ApplyLogOnInfo(RepTblLogonInfo) Next Session("Rep") = rep End If Me.CrystalReportViewer1.ReportSource = Session("Rep") Me.CrystalReportViewer1.DataBind() End Sub ************************** Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindReport() Me.CrystalReportViewer1.ShowFirstPage() End If end sub ****************************** Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click crReportDocument = New ReportDocument() crReportDocument.Load(Server.MapPath("crystalreport2.rpt")) Fname = "C:\exports\" & Session.SessionID.ToString & ".xls" crDiskFileDestinationOptions = New DiskFileDestinationOptions() crDiskFileDestinationOptions.DiskFileName = Fname crExportOptions = crReportDocument.ExportOptions With crExportOptions .DestinationOptions = crDiskFileDestinationOptions .ExportDestinationType = ExportDestinationType.DiskFile .ExportFormatType = ExportFormatType.PortableDocFormat End With crReportDocument.Export() Dim oStream As New MemoryStream oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) report.ExportToStream(CrystalDecisions.Shared.ExportFor
-
I am using asp.net+vb.net I want to export datas from sqlserver to excel.I wrote code for that.My it display in the internet explorer same page. I want to display in another page and want to set only print button for that page. The code i wrote is given below. ***************** Private Sub BindReport() If Session("Rep") Is Nothing Then Dim ConnInfo As New ConnectionInfo With ConnInfo .ServerName = "User1" .DatabaseName = "IMS" .UserID = "sa" .Password = "" End With Dim rep As New ReportDocument rep.Load(Server.MapPath("Crystalreport2.rpt")) Me.CrystalReportViewer1.ReportSource = rep Dim RepTbls As Tables = rep.Database.Tables For Each RepTbl As Table In RepTbls Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo RepTblLogonInfo.ConnectionInfo = ConnInfo RepTbl.ApplyLogOnInfo(RepTblLogonInfo) Next Session("Rep") = rep End If Me.CrystalReportViewer1.ReportSource = Session("Rep") Me.CrystalReportViewer1.DataBind() End Sub ************************** Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindReport() Me.CrystalReportViewer1.ShowFirstPage() End If end sub ****************************** Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click crReportDocument = New ReportDocument() crReportDocument.Load(Server.MapPath("crystalreport2.rpt")) Fname = "C:\exports\" & Session.SessionID.ToString & ".xls" crDiskFileDestinationOptions = New DiskFileDestinationOptions() crDiskFileDestinationOptions.DiskFileName = Fname crExportOptions = crReportDocument.ExportOptions With crExportOptions .DestinationOptions = crDiskFileDestinationOptions .ExportDestinationType = ExportDestinationType.DiskFile .ExportFormatType = ExportFormatType.PortableDocFormat End With crReportDocument.Export() Dim oStream As New MemoryStream oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) oStream = crReportDocument.ExportToStream(ExportFormatType.Excel) report.ExportToStream(CrystalDecisions.Shared.ExportFor
Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Clear() Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", "tmc.xls")) 'Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "kumaresh")) Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) 'Response.ContentType = "application/ms-excel" Response.ContentType = "application/" Dim stringWrite As New StringWriter() Dim htmlWrite As New HtmlTextWriter(stringWrite) GridView1.RenderBeginTag(htmlWrite) GridView1.RenderControl(htmlWrite) GridView1.RenderEndTag(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub
-
Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Clear() Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", "tmc.xls")) 'Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "kumaresh")) Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) 'Response.ContentType = "application/ms-excel" Response.ContentType = "application/" Dim stringWrite As New StringWriter() Dim htmlWrite As New HtmlTextWriter(stringWrite) GridView1.RenderBeginTag(htmlWrite) GridView1.RenderControl(htmlWrite) GridView1.RenderEndTag(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub
i am using crystal report in this code.My program working properly but i want to display only print button in toolbar not other toolbar buttons. I also want to export this crystal report details in word. How can i do this.Pls help