 |
|
 |
<myControl:ExportButton id="bExportToExcel" runat="server" Separator="TAB" Text="Export to Excel" FileNameToExport="Filename.xls" BackColor="#E0E0E0" />
This code seems inaccurate...
Separator="TAB" reminds me of exporting to CSV...is it also accurate for Excel... Can this library export to Excel? or only to CSV...I understand that it can, but I could be wrong...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
The difficulty I'm having with the library or any other code I write is that I need my code to act as a user control so that from the EXCEL button SEVERAL grids in .NET will be exported to Excel
I have code that works by exporting HTML to excel but I really do need Excel to open an excel document which is whY I chose this library...
Here's my code so far, but I get an error in this line: da.Fill(myDS, "myRecordsDataTable") Of course that makes perfect sense becasue this line is not the type of line that would work with several datagrids, or datatables, on the contrary, it seems to require a specific table...
Can you help me fix this? Does the rest of my code look okay, am I on the right track?
Imports System.Data
Partial Class common_code_ExportToExcel Inherits System.Web.UI.UserControl
Dim mGv As Control Dim mFilename As String = "Filename.xls" Dim mFilldataset As Control Dim mOpenOnly As Boolean = False
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet = GetRecords()
'Set Export button properties btnExcel.FileNameToExport = "Filename.xls" btnExcel.FileNameToExport = "ExcelExport" + System.DateTime.Now.Ticks.ToString() + ".xls" btnExcel.ExportType = PNayak.Web.UI.WebControls.ExportButton.ExportTypeEnum.Excel 'btnExcel.Separator = PNayak.Web.UI.WebControls.ExportButton.SeparatorTypeEnum.TAB
End Sub
Private Function GetRecords() As DataSet Dim myDS As New DataSet()
'Dim d As New db Dim d As New SqlClient.SqlConnection("Data Source=db") 'Using myConn As New db Using da As New SqlClient.SqlDataAdapter("SELECT * FROM MyTable", d) da.Fill(myDS, "myRecordsDataTable") End Using 'End Using
'da.DataSource = myDS.Tables(0) 'da.DataBind()
Return myDS End Function End Class
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Any method that returns a DataSet object For example GetRecords method like below
private DataSet Get Records() { DataSet myDS = new DataSet; SqlConnection myConn = SqlConnection (); SqlDataAdapter da = new SqlDataAdapter ("SELECT * FROM MyTable", myConn); da.Fill(ds, "myRecordsDataTable"); return myDS; }
or instead of writing a method, you could have all above code written on the Page_Load() and just replace 'myDS' with existing 'ds'.
hope this helps you.
Mr MC; The Only One
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you! I think I am very close to getting it to work... I had to change it to VB.NET
Private Function GetRecords() As DataSet Dim d As New db
Dim ds As New DataSet Dim da As New SqlDataAdapter("SELECT * FROM MyTable", d) da.Fill(ds, "myRecordsDataTable") Return ds End Function
I am getting an error at the SQLDataAdapter.... Can you help me, am I missing something?? This code will open EXCEL, I mean .xls not a .csv file right? That would be so wonderful...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I assume you problem might be in the the 'd' variable is not initialised or doesn't have the correct connection to the database. Look at the VB.Net below and modify it to match what you need.
Private Function GetRecords() As DataSet Dim myDS = new DataSet()
' Note: this needs to be a connection to your database and must be stored in the web.config file Dim ConnString = "Data Source=localhost\sqlexpress;Initial Catalog=TestDB;User ID=User;Password=pwd"
Dim myConn As New SqlConnection (ConnString) SqlDataAdapter da = new SqlDataAdapter ("SELECT * FROM MyTable", myConn) da.Fill(ds, "myRecordsDataTable") return myDS; End Function
According to the author, yes the import can be to an .xls file or .csv file, depending on the option you chose.
Hope this helps
Mr MC; The Only One
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for helping me...
I really want this to export to EXCEL (.xls)
However, I am using it from a usercontorl which is supposed to work for all the datagrid I have in several parts of my application...
I think that this is very hard for me to understand becasue I have to get it working as a user control
For instance, I keep wandering what myRecordsDataTable is... Because it keeps failing when I get there...
My full code is like this...
In the ascx part of the user contorl I have:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ExportToExcel.ascx.vb" Inherits="common_code_ExportToExcel" %>
<%@ Register TagPrefix="myControl" Assembly="PNayak.Web.UI.WebControls.ExportButton" Namespace="PNayak.Web.UI.WebControls" %>
<myControl:ExportButton id="btnExcel" runat="server" Separator="TAB" Text="Export to Excel" FileNameToExport="Filename.xls" BackColor="#E0E0E0" />
In the ascx.vb part, I have:
Imports System.Data
Partial Class common_code_ExportToExcel Inherits System.Web.UI.UserControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim ds As New DataSet() 'Dim d As New db 'Dim da As New SqlDataAdapter("SELECT * FROM MyTable", d) 'da.Fill(ds, "myRecordsDataTable")
''Return ds 'Dim ds As DataSet = ExportGridView() Dim ds As DataSet = GetRecords() 'da.DataSource = ds.Tables(0) 'da.DataBind()
'Set Export button properties btnExcel.FileNameToExport = "Filename.xls" btnExcel.FileNameToExport = "ExcelExport" + System.DateTime.Now.Ticks.ToString() + ".xls" btnExcel.ExportType = PNayak.Web.UI.WebControls.ExportButton.ExportTypeEnum.Excel 'btnExcel.Separator = PNayak.Web.UI.WebControls.ExportButton.SeparatorTypeEnum.TAB
End Sub
Private Function GetRecords() As DataSet Dim myDS As New DataSet()
'Dim d As New db Dim d As New SqlClient.SqlConnection("Data Source=db") 'Using myConn As New db Using da As New SqlClient.SqlDataAdapter("SELECT * FROM MyTable", d) da.Fill(myDS, "myRecordsDataTable") 'what is myRecordsDataTable? End Using 'End Using
'da.DataSource = myDS.Tables(0) 'da.DataBind()
Return myDS End Function End Class '*************************************** ALSO when I code: Dim d As New db db goes to the webconfig file and gets the connection for the application, and it works in every single case... I don't think I have a connection problem, I think I have a real hard time understanding how to turn this code into a user contorl that opens into Excel.... '****************************************
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
you already have a dataset in the Page_Load event handler; i.e Dim ds As DataSet = GetRecords() hence you only need to do the ff:
btnExcel.Dataview = ds.Tables("myRecordsDataTable").DefaultView think of 'MyRecordsDataTable' as a virtual table you are giving to your results so that you can reference it by name, for example ds.Tables("myRecordsDataTable").
Remember to change SELECT * FROM MyTable to select from your real database table.
You can also remove these lines
'Dim ds As New DataSet() 'Dim d As New db 'Dim da As New SqlDataAdapter("SELECT * FROM MyTable", d) 'da.Fill(ds, "myRecordsDataTable")
''Return ds
as they're supposed to to get populate the dataset for you, but it's already populated.
Hope this helps
Mr MC; The Only One
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
'this is my code, but I do not know how to implement this library with it... I added the library, but now I don't know how to use it...
'Dim mGv As GridView Dim mGv As Control Dim mFilename As String = "Filename.xls" Dim mOpenOnly As Boolean = False
Public Property OpenOnly() As Boolean Get Return mOpenOnly End Get Set(ByVal value As Boolean) mOpenOnly = value End Set End Property
Public Property Filename() As String Get Return mFilename End Get Set(ByVal value As String) mFilename = value End Set End Property
Public Property DataSource() As Control Get Return mGv End Get Set(ByVal value As Control) mGv = value
Dim c As Control = mGv
Dim up As UpdatePanel = controlType(c, New UpdatePanel)
If Not up Is Nothing Then If up.Triggers.Count = 0 Then Throw New Exception("Export To Excel Object appears to be in a Updatepanel. Please set <asp:PostBackTrigger ControlID='ExportGridViewToExcel1' /> in the updatepanel") Else
For lcv As Integer = 0 To up.Triggers.Count - 1 If Not up.Triggers.Item(lcv).ToString.Contains(Me.ID) Then Throw New Exception("Export To Excel Object appears to be in a Updatepanel. Please set <asp:PostBackTrigger ControlID='ExportGridViewToExcel1' /> in the updatepanel") End If Next End If
End If End Set End Property
Private Function controlType(ByVal c As Control, ByVal searchFor As Control) As Control Dim foundcontrol As Control = Nothing If c.GetType.Equals(searchFor.GetType) Then foundcontrol = c Else If Not TypeOf c.Parent Is Page Then foundcontrol = controlType(c.Parent, searchFor) End If End If
Return foundcontrol End Function
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi can u plz tell me hw can i transfer a text file from my web application(on button's click) in asp.net to my GPRS enabled mobile phn... plz help me out as soon as possible
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, I am trying to export the gridview data to excel 2003 through ASP .NET. I could see the data in excel 2003, the only problem is the format of generated excel is coming as the Gridview and not in the normal excel cells. i.e. i am not able to see the cell data. e.g. Cell B1 has data 120 but when i select this cell, this value does not appear in excel formula bar. So i could not use any formula to show the same data in another sheet etc.
The code is:
protected void ExportToExcel_Click(object sender, EventArgs e) { Response.Clear(); Response.Buffer = false; Response.ContentType = "application/vnd.ms-excel"; Response.Charset = ""; Page.EnableViewState = false; // If you want the option to open the Excel file without saving then // comment out the line below System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); DFTGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }
public override void VerifyRenderingInServerForm(Control control) { return; }
|
| Sign In·View Thread·PermaLink | 1.33/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Make sure the button/link are not inside of the update panel... Ajax does async call for the update panels and the response.write to the response object will result in an error. Otherwise, I'm very happy to have such a nice control to use and I thank the author...
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
If it has AsyncPostBackTrigger in the update panel then its throwing an exception system.webform.parsemanager exception
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Is this control flexible enough to let us format the Excel output before the end user sees it? I'm seeing all the columns squished together and some columns need to be right or left justified at times.
Thanks for firing me Darrell Eaker of Ringgold Telephone Company. I TRIPLED my salary and don't have to deal with douchebags like you. 
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Can i use this control in datagrid temlate column. I have list of file and user can select button n down load it. I did but not getting result.
|
| Sign In·View Thread·PermaLink | 1.50/5 (3 votes) |
|
|
|
 |
|
 |
When I open excel file, I get a message "File is not in recognizabe format." Yet when I click "OK" it opens fine.
Please help
andrey
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I also get this error. Any solutions yet?
Thanks for firing me Darrell Eaker of Ringgold Telephone Company. I TRIPLED my salary and don't have to deal with douchebags like you. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Just take a look at what is being exported. This is an HTML table, not an XLS file. See some of the alternative formats mentioned below. When you open the HTML table in Excel, it prompts you since the file is not really a workbook. This is just a hack. Real XLS would be nice so types could be specified as well as multiple worksheets specified for a workbook.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I created this button but it doesn't executes properly, and I can't pass dataset.
Protected Sub ExportButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExportButton1.Click Dim _dataPool As New DataPool Dim _ds As New DataSet Dim _myparams(1) As DataPool.StoredProcedureParams
'Gets data from a table
_myparams(0).sname = "@begin_date" _myparams(0).edirection = ParameterDirection.Input _myparams(0).vvalue = txtFrom.Text _myparams(1).sname = "@end_date" _myparams(1).edirection = ParameterDirection.Input _myparams(1).vvalue = txtTo.Text _dataPool.ConnectionServer = "Connection" 'Specifies Connection Server _ds = _dataPool.GetDataSet("sp_New_Items", _myparams) ExportButton1.Dataview = _ds.Tables(0).DefaultView ExportButton1.FileNameToExport = "NewItemsCataloged.xls" ExportButton1.ExportType = PNayak.Web.UI.WebControls.ExportButton.ExportTypeEnum.Excel ExportButton1.Separator = PNayak.Web.UI.WebControls.ExportButton.SeparatorTypeEnum.TAB
End Sub
It doesn't execute this code at all.
Please help
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
 |
hi all
can anybody help me how to create excel report using the data from oracle in asp.net
plz help me its very urgent for me thnkx in advance aman
|
| Sign In·View Thread·PermaLink | 1.40/5 (4 votes) |
|
|
|
 |