hey download the demo program from below link program name is ReadOfficeFilesOpenXML in this program i try to retirve data from word power point and excel file
just text only you can download this and just call the execl method to read text from cell and value from all sheets
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit
unstable behavior and/or deadlock when Office is run in this environment."
I tried to add "using Excel = Microsoft.Office.Interop.Excel;" in my code and ofcourse it did'nt like it.
Hi,
Anoth.r way is that maybe you can use ODBC to bind the Excel file to GridView or just ODBC's DataAdapter.Fill into a DataTable, and then you can fetch the cell's value.
for more about Connection string, you can refer to this:
NewToDotyNet
Member
3 Points
41 Posts
ASP.NET Excel
Dec 22, 2012 04:30 AM|LINK
Hi,
Is it possible to use an excel object to asp.net. I can't find a refernce to add.
I tried to add "using Excel = Microsoft.Office.Interop.Excel;" in my code and ofcourse it did'nt like it.
I was hoping to open an excel file and grab values from cells.
I may be able to use another file type that I can convert from the excel file.
Any ideas? Need insight as to which way to go for the best.
Thanks,
SohailShaikh
Contributor
6109 Points
1167 Posts
Re: ASP.NET Excel
Dec 22, 2012 05:32 AM|LINK
hey download the demo program from below link program name is ReadOfficeFilesOpenXML in this program i try to retirve data from word power point and excel file just text only you can download this and just call the execl method to read text from cell and value from all sheets
https://skydrive.live.com/#cid=2F22272220E37707&id=2F22272220E37707%21103
Sohail Shaikh
Madhu1234
Participant
1380 Points
287 Posts
Re: ASP.NET Excel
Dec 22, 2012 12:10 PM|LINK
Checks this links....
http://forums.asp.net/t/1750220.aspx/1
sarathi125
Star
13599 Points
2691 Posts
Re: ASP.NET Excel
Dec 22, 2012 01:01 PM|LINK
Hi,
you shouldn't use Office Interop on a web server:
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Use a third party tool instead, for example this free one:
http://excelpackage.codeplex.com/
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: ASP.NET Excel
Dec 23, 2012 12:59 AM|LINK
Hi,
Anoth.r way is that maybe you can use ODBC to bind the Excel file to GridView or just ODBC's DataAdapter.Fill into a DataTable, and then you can fetch the cell's value.
for more about Connection string, you can refer to this:
http://www.connectionstrings.com/
NewToDotyNet
Member
3 Points
41 Posts
Re: ASP.NET Excel
Dec 25, 2012 10:39 AM|LINK
Hi,
tried below -
private void readExcel()
{
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = @"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dsn=Excel Files;" + "Dbq="
+ Server.MapPath("~/");
conn.Open();
string consulta = "Select * from IOExcel";
OdbcDataAdapter adapter = new OdbcDataAdapter(consulta, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
conn.Close();
}
Also tried - string consulta = "Select * from IOExcel.xlsx"; as it is a xlsx.
Niether worked.
Not sure how I would get each cell value. Only need to collect a row at a time. i.e. A1,B1,C1.... then A2,B2,C2.........
Thanks,
SohailShaikh
Contributor
6109 Points
1167 Posts
Re: ASP.NET Excel
Dec 25, 2012 10:45 AM|LINK
download the demo program from below link in this program i'll try to show just upload the excel file and show data in grid
program name is =UploadExcel_Show_In_Grid
https://skydrive.live.com/?lc=1033#cid=2F22272220E37707&id=2F22272220E37707%21103
Sohail Shaikh
amitpatel.it
Star
7908 Points
1856 Posts
Re: ASP.NET Excel
Dec 25, 2012 10:54 AM|LINK
Below link will help you.
http://stackoverflow.com/questions/11771194/microsoft-office-interop-excel-dll-server-doesnot-have-excel-installed
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
NewToDotyNet
Member
3 Points
41 Posts
Re: ASP.NET Excel
Dec 25, 2012 11:12 PM|LINK
Hi,
I get "There is no row at position 0.". Code below.
protected void Upload_Excel() {
string connectionString ="";
string fileName = "IOExcel";
string fileExtension = ".xlsx";
string fileLocation = Server.MapPath("~/" + fileName);
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//Create OleDB Connection and OleDb Command
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName +"]";
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
con.Close();
GridView1.DataSource = dtExcelRecords;
GridView1.DataBind(); }
NewToDotyNet
Member
3 Points
41 Posts
Re: ASP.NET Excel
Dec 25, 2012 11:12 PM|LINK
Hi,
I get "There is no row at position 0.". Code below.
protected void Upload_Excel() {
string connectionString ="";
string fileName = "IOExcel";
string fileExtension = ".xlsx";
string fileLocation = Server.MapPath("~/" + fileName);
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
//Create OleDB Connection and OleDb Command
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName +"]";
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
con.Close();
GridView1.DataSource = dtExcelRecords;
GridView1.DataBind(); }