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