lynnton
asked on
export dataset to excel file
Hi,
Kindly help me export the dataset to a excel file and a user can choose which location he want the file to be place.
Please help me make it work.
Thanks.
MyCommand = New SqlDataAdapter(strSQL, MyConnection)
MyCommand.SelectCommand.Co mmandTimeo ut=0
ds = new DataSet()
MyCommand.Fill(ds, "DataSetName")
MyDataGrid.DataSource=ds.T ables("Dat aSetName") .DefaultVi ew
MyDataGrid.DataBind()
Kindly help me export the dataset to a excel file and a user can choose which location he want the file to be place.
Please help me make it work.
Thanks.
MyCommand = New SqlDataAdapter(strSQL, MyConnection)
MyCommand.SelectCommand.Co
ds = new DataSet()
MyCommand.Fill(ds, "DataSetName")
MyDataGrid.DataSource=ds.T
MyDataGrid.DataBind()
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi lynnton , following my indicated approach an user can easily generate the excel file with the data contained in the dataset when he need it : he want the data in excel he clicks on a button and get the Excel
This is maybe more simple than looping ur datarows in ur datatabable and build the excel 'manually' by code...
it is an approach
This is maybe more simple than looping ur datarows in ur datatabable and build the excel 'manually' by code...
it is an approach
Programmatically you can format your excel spreadsheet as you see fit tho. I.e. colors, fonts, print areas etc etc.
ASKER
NetDeveloper,
My apology, I'm lost, a user will click to export the data to excel then choose the path. What is the datagrid for ?
is it possible not to use one ? (yeah I don't like looping too) :-)
Thanks.
My apology, I'm lost, a user will click to export the data to excel then choose the path. What is the datagrid for ?
is it possible not to use one ? (yeah I don't like looping too) :-)
Thanks.
Yes, as saleek says , lets suppose u have a datagrid with a specific color for alternate row <AlternatingItemStyle></Al ternatingI temStyle>
this style will be reflected in the generated .xls document too ...but this is true for about any format u apply to ur grid
this style will be reflected in the generated .xls document too ...but this is true for about any format u apply to ur grid
1. u bind the grid with ur data u indicated when page load (not pstaback)
2. in the event hand routine of a button insert that code
yourdatagrid is the ID of ur GRID
2. in the event hand routine of a button insert that code
yourdatagrid is the ID of ur GRID
ASKER
NetDeveloper,
This is to cool to be true !!! Amazing abc done. You're the best!
I've made the grid not visible this removes the primary problem.
-How can we change the filename to system dateTime ?
-what will happen if it excedd the excel row limit 65K?
-how can we test a textbox1 for a date value ? return an error if it's not a date value..
Thanks so much.
This is to cool to be true !!! Amazing abc done. You're the best!
I've made the grid not visible this removes the primary problem.
-How can we change the filename to system dateTime ?
-what will happen if it excedd the excel row limit 65K?
-how can we test a textbox1 for a date value ? return an error if it's not a date value..
Thanks so much.
Hi,
- DateTime.Parse(urvalue) convert a value from string to DateTime...provided the value passed can be a date
- why you don't trim the string at DB level using TRIML and TRIMR sql functions?
- use a js or a regex ---search the web for such a control
- DateTime.Parse(urvalue) convert a value from string to DateTime...provided the value passed can be a date
- why you don't trim the string at DB level using TRIML and TRIMR sql functions?
- use a js or a regex ---search the web for such a control
ASKER
NetDeveloper,
Instead of naming the report "reports.xls" can we change it to generate dateTime value.xls ?
oh, excel has a max limit of 65K rows per sheet, what will happen if we exceed this limit?
Got it i'll research for regex for detecting if the inputed value is date format.
by the way, i've added alternate backcolor, when i export to excel the back color goes beyond the table..
i.e.
the raw data has 8 columns, when i open the excel the alternatining back color is there but it's like 20 columns long...
how can we fit to the columns only?
<p align="center">
<asp:DataGrid id="Mydatagrid" runat="server" Font-Names="Arial">
<HeaderStyle font-bold="True" backcolor="NavajoWhite"></ HeaderStyl e>
<AlternatingItemStyle bordercolor="White" backcolor="LightSteelBlue" ></Alterna tingItemSt yle>
</asp:DataGrid>
</p>
<!-- Insert content here -->
Thanks.
Instead of naming the report "reports.xls" can we change it to generate dateTime value.xls ?
oh, excel has a max limit of 65K rows per sheet, what will happen if we exceed this limit?
Got it i'll research for regex for detecting if the inputed value is date format.
by the way, i've added alternate backcolor, when i export to excel the back color goes beyond the table..
i.e.
the raw data has 8 columns, when i open the excel the alternatining back color is there but it's like 20 columns long...
how can we fit to the columns only?
<p align="center">
<asp:DataGrid id="Mydatagrid" runat="server" Font-Names="Arial">
<HeaderStyle font-bold="True" backcolor="NavajoWhite"></
<AlternatingItemStyle bordercolor="White" backcolor="LightSteelBlue"
</asp:DataGrid>
</p>
<!-- Insert content here -->
Thanks.
>the raw data has 8 columns, when i open the excel the alternatining back color is there but it's like 20 columns long...
Hi, tnx for the points...it happens to me to ...this evening when finishing with office work will try to see if I find something
Regards
D-
Hi, tnx for the points...it happens to me to ...this evening when finishing with office work will try to see if I find something
Regards
D-
ASKER
Is this datagrid neccesary? since we need to export only..
Thanks.