This walkthrough illustrates how to create a simple Web Site with the capability to export data to Excel.
To set the web.config file, perform following steps:
- Inside Solution Explorer select the web.config file and double-click it. Web.config
file will open.
- Locate the connectionStrings section and replace it with following
- Locate the compilation section and replace it with following
- Save and close the web.config file.
Here we'll demonstrate how you can add the capability to export data to Excel 2007 by a few actions and adding two lines of code.
Inside the Solution Explorer double-click the default.aspx page.
- To the default.aspx pagge add a new Button
- Verify that its ID property is "Button2"
- Set the "Text" property of the button to "Export to Excel 2007"
- Double click Button2.The Code Editor will open.
Inside the Button2_click sub, insert following text
- Save All
- Press Ctrl-F5 to run the web site.The web application will run and Internet Explorer will show following window:
- Press the "Export to Excel 2007" Button. Next window will popup:
- Press "Open" to open the Excel sheet and following Excel 2007 (xlsx) sheet will display: