Last post Aug 13, 2010 04:24 PM by mxstar45
Aug 12, 2010 02:52 PM|mxstar45|LINK
I do not know if this is the proper place to ask this, but my question is...
I have a SQL DB and I want to convert it to Excel Sheet (I did this using the wizard)!
In my aspx page I have a button. So when I press this button I want the Excel sheet to open! But I need the Excel sheet to show me the up to date information that is in the SQL DB.
I just don't know how to get the Excel sheet to up date itself...?? I guess that is what I want...
Any help would be greatly appreciated!
Thank you so much!!
Aug 12, 2010 08:02 PM|Prof_Teancum|LINK
It sounds like you are doing things the long and tedious way. You can use databound controls (like the gridview) to display the latest database information. If you add a SQLDataSource to the page in Visual Studio, you can use the wizard to choose what data
is displayed from the database. Then you just need to hook the gridview up to the SQL datasource.
If you want to output the information as a spreadsheet for people to download, you can put a button for that on the form and then render the gridview's HTML into a file with extension .xls and excel will interpret it correctly.
Aug 13, 2010 08:34 AM|mxstar45|LINK
Hey thank you your quick reply.
I need it to open an Excel sheet not in a grid.
This is only the first step I need to do..
After I get this working. I need to open Word and do a Mail Merge with the Word template and data that is in the Excel sheet.
Which I have never performed any of these operations, so it's a new experience.
Also I have seen a few links that are.."How to automate Microsoft Excel from Microsoft visual C#.Net"
Would these be helpful? I tried them but a ton of errors.
Aug 13, 2010 04:18 PM|Prof_Teancum|LINK
If I understand correctly, you want the button to open the spreadsheet from the browser, NOT display the contents of the spreadsheet in the browser? In that case, you can just do a Response.Redirect() and pass the path to the where the excel file is stored
on your computer. Then the person can download it and look at it in their browser.
The easiest way to turn sql data into a spreadsheet is just to use a StringBuilder and manually create an HTML table, row by row, with data from an sql query. You could then write the stringbuilder's contents to a file with extension .xls and send a Response.Redirect.
Aug 13, 2010 04:24 PM|mxstar45|LINK
After searching high and low I found a good solution to solve my problem.. thanks