 |

|
Great control - worked the first time !!!
|
|
|
|

|
I solved the unicode problem by doing adding this line to the customExport()
Dim Encoding As New System.Text.UnicodeEncoding
response.ContentEncoding = System.Text.Encoding.Unicode
response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble())
plz check it and let me know if its works for u too
|
|
|
|

|
hi Prashant,
Excellent code can you please guide me further ... thanks a lot....
when I click on export button broser shows me msg "Internet Explorer cannot display the webpage " ..plz help urgent !
|
|
|
|

|
I found the reason of above problem, but do not know the solution.
Actually my dataset is big (more than 6,000 rows). When I tired to pull one row it worked. Please suggest what can I do to make it work for large dataset ... thankyou.
|
|
|
|

|
HI did you manage to fix this problem?
|
|
|
|

|
After doing some research it turns out it has to do with caching been turned off, either on a server level or on the page. Turn caching back on and the error will go away
|
|
|
|

|
Hai,
I want the same code in c# .net.plz will you help me for this
|
|
|
|
|
|

|
Hi everyone. I have an issue using the export to csv button. I can't seem to pull any data. The code executes without error but my download csv file is always the empty dataset not a populated one. I can't seem to determine where to associate the dataset to the control correctly at design time. Here's a code snippet:
<asp:RoleGroup Roles="My Store";
<ContentTemplate>
<strong> Online Store
<br />Order Report</strong> <br />
<hr />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataSourceID="AccessDataSource1" PageSize="50">
<Columns>
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:BoundField DataField="OrderNumber" HeaderText="Order#"
SortExpression="OrderNumber" />
<asp:BoundField DataField="ItemNumber" HeaderText="Web Order #"
SortExpression="ItemNumber" />
<asp:BoundField DataField="DetailDate" HeaderText="Date"
SortExpression="DetailDate" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="ProductTotal" HeaderText="Product Total"
SortExpression="ProductTotal" />
<asp:BoundField DataField="Discount" HeaderText="Credit Due"
SortExpression="Discount" />
<asp:BoundField DataField="SKU" HeaderText="SKU" SortExpression="SKU" />
<asp:BoundField DataField="Product" HeaderText="Product Name"
SortExpression="Product" />
<asp:BoundField DataField="QuantityOrdered" HeaderText="Ordered"
SortExpression="QuantityOrdered" />
<asp:BoundField DataField="QuantityShipped" HeaderText="Shipped"
SortExpression="QuantityShipped" />
<asp:BoundField DataField="Backordered" HeaderText="Back Ordered"
SortExpression="Backordered" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="C:\StoneEdge\LifeTeen.mdb"
SelectCommand="SELECT Orders.Name, Orders.ProductTotal, Orders.Discount, [Order Details].OrderNumber, [Order Details].DetailDate, [Order Details].Product, [Order Details].SKU, [Order Details].ItemNumber, [Order Details].Status, [Order Details].QuantityOrdered, [Order Details].QuantityShipped, [Order Details].Backordered FROM (Orders INNER JOIN [Order Details] ON Orders.OrderNumber = [Order Details].OrderNumber)
">
</asp:AccessDataSource>
</ContentTemplate>
</asp:RoleGroup>
<pnwc:ExportButton ID="ExportButton1" runat="server" Text="Export Report" />
I always get an empty csv file. Please help. Thanks Chris
|
|
|
|

|
I found an error in display text when I open exported file in MS Excel
The Unicode character such as "Ô", "ư" (Vietnamese language)... cannot display correctly.
But When I open this file in Open Office 3.2. it's display correctly.
I dont know why. Could I solve this problem?
Thanks for demo. It's great!
DongMT
|
|
|
|

|
First of all Thank you very much for the Control.
Good Work!!!.
Just one small query
When I export I have in datatable one column values as "0405", "0302" etc. But When I export to Excel the data in the column becomes "405", "302".
HOw to format a specified column as Text using your Export button.
Please do Reply. Its urgent.
|
|
|
|

|
Im brand new to asp.net but im getting there quite quickly. I really need to use this contol for a project at work but i don't know where to start with it, this is what i've done so far:
Using Visual Web Developer Express I started a new project and opened default.aspx and default.aspx.vb, added an access datasource, added a gridvew and then added the export button which i had added to my toolbox.
Now i know i need to set the dataview for the button but i dont know how/where to do this.
lets say my datasource is called Data1 and the table im using is called Table1 and my datagrid is called Grid1
Someone please help me, i will be so very grateful.
P
|
|
|
|

|
every thing is working fine. but in stop execution
"response.End()"
an error occurs 'property evaluation failed.'
But file is generated successfully. how to fix it...
|
|
|
|

|
I had the same issue, but fixed it by adding my button to the list of "Triggers" for the update panel. Like this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="cmdExeclExport" />
</Triggers>
<ContentTemplate>
etc...
Hope this helps!
|
|
|
|

|
Use response.flush() and response.close() instead of response.end
|
|
|
|

|
<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...
|
|
|
|
|

|
Hi,
if you are looking a way to produce binary Excel files (XLS, XLSX) from Excel ASP.NET application, you should try this Excel .NET library.
Here is an Excel C# sample code how to export Excel files to browser:
var dataTable = (DataTable)dataGrid.DataSource;
var ef = new ExcelFile();
var ws = ef.Worksheets.Add(dataTable.TableName);
ws.InsertDataTable(dataTable, "A1", true);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls");
ef.SaveXls(Response.OutputStream);
Response.End();
|
|
|
|

|
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
|
|
|
|

|
What do I place instead of filldataset?
That's what I get stuck...
|
|
|
|

|
Any method that returns a DataSet object
For example
GetRecords method like below
private DataSet Get Records()
{
DataSet myDS = new DataSet;
SqlConnection myConn = SqlConnection (<Your connection to a database>);
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
|
|
|
|

|
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...
|
|
|
|

|
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()
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
|
|
|
|

|
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....
'****************************************
|
|
|
|

|
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
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
|
|
|
|

|
'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
|
|
|
|

|
Imports System.Data
Imports System.Data.SqlClient
Dim ExportExcel As New PNayak.Web.UI.WebControls.ExportLinkButton
ExportExcel.Text = "<img src=""images/excel.gif"" border=""0"" title=""send to excel"">"
Dim adapter As New SqlDataAdapter([YourSQLStatement],"server=[YourServer];database=[YourDatabase];uid=[YourUID];pwd=[YourPassword]")
Dim ds As New DataSet()
adapter.Fill(ds)
Dim dv As New DataView
dv = ds.Tables(0).DefaultView
ExportExcel.ExportType = PNayak.Web.UI.WebControls.ExportButton.ExportTypeEnum.CSV
ExportExcel.Separator = PNayak.Web.UI.WebControls.ExportButton.SeparatorTypeEnum.Comma
ExportExcel.Delimiter = """"
ExportExcel.FileNameToExport = [YourReportTitle] & ".csv"
ExportExcel.Dataview = dv
ExportExcel.DataBind()
|
|
|
|

|
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
|
|
|
|

|
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;
}
|
|
|
|

|
I can't get this to work either... Even the button does not show up...
Any ideas?
|
|
|
|

|
Yes, that happened to me also. I think the main cause of problems is Excel's converting from HTML to it's internal spreadsheet format. I guess those two formats are not fully interchangeable.
I solved the issue with generation of real Excel file and not HTML file.
I used GemBox.Spreadsheet excel component. And my report web page looked similar to this export Excel data sample page.
|
|
|
|

|
Are there any know issues using this control with SSL?
Andrew Woomer
|
|
|
|

|
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...
|
|
|
|

|
If it has AsyncPostBackTrigger in the update panel then its throwing an exception system.webform.parsemanager exception
|
|
|
|

|
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.
|
|
|
|

|
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.
|
|
|
|

|
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
|
|
|
|

|
I got the same problem. Any helps
|
|
|
|

|
I'm also getting the same problem, got any solutions???
|
|
|
|

|
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.
|
|
|
|

|
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.
|
|
|
|

|
After examining the code myself - it is not actually creating an Excel spreadsheet. It is basically just creating a CSV and renaming as XLS - tricking the user into thinking its a real Excel SS. That is also why you can't format it at all..
|
|
|
|

|
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
|
|
|
|

|
you need to bind the button .DataBind()
Here's completely working generic code:
Imports System.Data
Imports System.Data.SqlClient
Dim ExportExcel As New PNayak.Web.UI.WebControls.ExportLinkButton
ExportExcel.Text = "<img src=""images/excel.gif"" border=""0"" title=""send to excel"">"
Dim adapter As New SqlDataAdapter([YourSQLStatement],"server=[YourServer];database=[YourDatabase];uid=[YourUID];pwd=[YourPassword]")
Dim ds As New DataSet()
adapter.Fill(ds)
Dim dv As New DataView
dv = ds.Tables(0).DefaultView
ExportExcel.ExportType = PNayak.Web.UI.WebControls.ExportButton.ExportTypeEnum.CSV
ExportExcel.Separator = PNayak.Web.UI.WebControls.ExportButton.SeparatorTypeEnum.Comma
ExportExcel.Delimiter = """"
ExportExcel.FileNameToExport = [YourReportTitle] & ".csv"
ExportExcel.Dataview = dv
ExportExcel.DataBind()
modified on Thursday, July 16, 2009 1:46 PM
|
|
|
|

|
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
|
|
|
|
|
|
|

|
Up to you what you like to export...Here's the idea: private string GenerateFile() { //do something here yourself // //***a. create your simple csv file string: //e.g. //Name, Contact, Email //Pete, 1234555, Pete@email.com //Jan, 1234566, Jan@email.com //... // //***b. Or make your own pretty Excel format with your colour and font //Here is a sample TEMPLATE how to create EXCEL format XML //<xml version> // <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" // xmlns = "urn:schemas-microsoft-com:office:office" // xmlns:x = "urn:schemas-microsoft-com:office:excel" // xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> // <Styles> // <Style ss:ID="Default" ss:Name="Normal"> // <Alignment ss:Vertical="Bottom"/> // <Borders/> // <Font/> // <Interior/> // <NumberFormat/> // <Protection/> // </Style> // <Style ss:ID="BoldColumn"> // <Font x:Family="Swiss" ss:Bold="1"/> // </Style> // <Style ss:ID="s1"> // <NumberFormat ss:Format="@"/> // </Style> // <Style ss:ID="d1"> // <NumberFormat ss:Format="0.00"/> // </Style> // <Style ss:ID="i1"> // <NumberFormat ss:Format="0"/> // </Style> // <Style ss:ID="t1"> // <NumberFormat ss:Format="mm/dd/yyyy;@"/> // </Style> // </Styles> // <Worksheet ss:Name="Sheet1"> // </Worksheet> // </Workbook> }
|
|
|
|
 |