locked
Merge SQL to Excel--Need .Net button to open on fly and have current SQL data! RRS feed

  • Question

  • User-97059558 posted

               Hello all,
    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!!

               Hello all,


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

    Thursday, August 12, 2010 2:52 PM

Answers

  • User-764728713 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 13, 2010 4:18 PM

All replies

  • User-764728713 posted

    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.

    Thursday, August 12, 2010 8:02 PM
  • User-97059558 posted

    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.

    Thanks again

    Friday, August 13, 2010 8:34 AM
  • User-764728713 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 13, 2010 4:18 PM
  • User-97059558 posted

    After searching high and low I found a good solution to solve my problem.. thanks

    Friday, August 13, 2010 4:24 PM