M
Marco Rispoli
I successfully opened an excel file, and displayed it into a datagrid.
This is the code:
string sConnectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("example.xls") + @";Extended Properties=Excel 8.0;";
OleDbConnection objConn=new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand oCmd=new OleDbCommand("SELECT * FROM DisplayView", objConn);
OleDbDataAdapter oAdapter=new OleDbDataAdapter();
oAdapter.SelectCommand = oCmd;
DataSet ds=new DataSet();
oAdapter.Fill(ds, "XLData");
ddgXls.DataSource=ds;
ddgXls.DataBind();
where I created the DisplayView in SELECT * FROM DisplayView by manually
following these steps:
*Highlight the rows and columns where the data resides
*On the Insert menu, point to Name, and then click Define.
*In the Names in workbook text box, type DisplayView, and then click OK.*
*On the File menu, click Save.
*On the File menu, click Exit.
I would like to access excel spreadsheets uploaded to a site and I don't
expect the users to follow these 5 steps to make my life easier.
I noticed that in the "define" menu there's already a name defined called
"Print_Area" that already encompasses the cells that I would like to select
from. I tried to write "SELECT * FROM Print_Area" but the code bombs
complaining that Print_Area doesn't exist.
Any idea how to get around this?
I would really like to select data from the excel spreadsheet without
forcing the users to define and assign a name to the area.
Please help ... I am not that strong with the office object model.
Thank you!
This is the code:
string sConnectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("example.xls") + @";Extended Properties=Excel 8.0;";
OleDbConnection objConn=new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand oCmd=new OleDbCommand("SELECT * FROM DisplayView", objConn);
OleDbDataAdapter oAdapter=new OleDbDataAdapter();
oAdapter.SelectCommand = oCmd;
DataSet ds=new DataSet();
oAdapter.Fill(ds, "XLData");
ddgXls.DataSource=ds;
ddgXls.DataBind();
where I created the DisplayView in SELECT * FROM DisplayView by manually
following these steps:
*Highlight the rows and columns where the data resides
*On the Insert menu, point to Name, and then click Define.
*In the Names in workbook text box, type DisplayView, and then click OK.*
*On the File menu, click Save.
*On the File menu, click Exit.
I would like to access excel spreadsheets uploaded to a site and I don't
expect the users to follow these 5 steps to make my life easier.
I noticed that in the "define" menu there's already a name defined called
"Print_Area" that already encompasses the cells that I would like to select
from. I tried to write "SELECT * FROM Print_Area" but the code bombs
complaining that Print_Area doesn't exist.
Any idea how to get around this?
I would really like to select data from the excel spreadsheet without
forcing the users to define and assign a name to the area.
Please help ... I am not that strong with the office object model.
Thank you!