sree palaparthi

sree palaparthi

  • NA
  • 1
  • 2.2k

display excel sheet in asp.net

Mar 31 2011 3:53 PM
Hello All,

I am beginner in .net programming, I am trying to display the Excel sheet into the aspx page. i copy the code in my local machine and as a test..... i copied the excel in my local machine and see if i can display from my local drive location into the aspx page.

Below is the code:

protected
{


void btnLoadData_Click(object sender, EventArgs e)//Establish a connection



OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.8.0;Data Source=C:\\Test1.xlsx;Extended Properties='Excel 8.0;HDR=YES'");//OleDbConnection connExcel = new OleDbConnection(Con);

cmdExcel.Connection = con;


OleDbCommand cmdExcel = new OleDbCommand();//Accessing sheetscon.Open();


dtExcelSchema = con.GetOleDbSchemaTable(




DataTable dtExcelSchema;OleDbSchemaGuid.Tables, null);DataTable dt = new DataTable();//string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();

da.SelectCommand = cmdExcel;
da.Fill(dt);


OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);//DataView view = new DataView(ds, "[Botanical name] <> ''", "", DataViewRowState.CurrentRows );

//DataGrid1.DataSource = view;

//DataGrid1.DataBind(); con.Close();
}
I defined the btnLoadData_Click in the .aspx file and below is the server side code: (DSAM RF Levels is the tab name that I want to display the excel sheet)
<
asp:TabPanel ID="DSAMTab" runat="server" HeaderText="TabPanel3" OnLoad = "btnLoadData_Click">

<HeaderTemplate>DSAM RF Levels</HeaderTemplate>

<ContentTemplate>

<br />

<br />

and soon.......

Please suggest your valauble advice

Thanks in advance