using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Web.UI.DataVisualization.Charting; using System.Data.OleDb; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // resolve the address to the Excel file string fileNameString = Server.MapPath(".") +@"\data\ExcelData.xls"; // Create connection object by using the preceding connection string. string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString + ";Extended Properties=\"Excel 8.0;HDR=YES\""; OleDbConnection myConnection = new OleDbConnection( sConn ); myConnection.Open(); // The code to follow uses a SQL SELECT command to display the data from the worksheet. // Create new OleDbCommand to return data from worksheet. OleDbCommand myCommand = new OleDbCommand( "Select * From [data1$A1:E25]", myConnection ); // create a database reader OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // Populate the chart with data in the file Chart1.DataBindTable(myReader, "HOUR"); // close the reader and the connection myReader.Close(); myConnection.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)