Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
4.25/5 (3 votes)
See more:
Hello,

Is it possible ??????????

There is a requirement of upload data*** from excel file(.XLS). But i don't want to upload that .xls file on the server, and read data from it.

I want to read that file which resides on client-side and after confirmation, i want to directly update the values from that xls file into database without uploading that xls file from server.


no physical movement of file is required from client-to server.

I think this is possible, but i don't know how to do this,

I know how to upload file and read it from server.

Please guide me in this regard....


I am a gold fan :-) of codeproject developers and contributors


Thanks in advance

Indrajeet Sutar

.NET Web Developer

indrajeet.sutar@gmail.com
inder2305@gmail.com
Posted
Updated 22-Dec-09 19:07pm
v3

you can try the

 <script language="javascript">
  function readFromExcel()
  {
  var excel = new ActiveXObject("Excel.Application");
  var excel_file = excel.Workbooks.Open("C:\\Book2.xls");
  var excel_sheet = excel_file.Worksheets("Sheet1");
  return data;
  }
  </script>
<body>
  <input type="button" onclick=readFromExcel() value="read"/>
</body>


Also you can refer to msdn link
http://channel9.msdn.com/forums/TechOff/414414-Help-with-reading-from-an-excel-file-using-javascript/[^]
 
Share this answer
 
My answer is a little more lenghty but here it is. It has it's advantages along with disadvantages.
It assumes a class named FieldsHere that
maps the excel columns, and the DB columns as well. Of course you need
to adapt it. You could also use an OleDbDataAdapter to fill a DataSet.

string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
               "Data Source=" + FileNameHere + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\";";

           OleDbConnection con = new OleDbConnection(connString);

           OleDbCommand cmd = new OleDbCommand();
           cmd.Connection = con;
           cmd.CommandText = "SELECT Field1Here,Field2Here,Field3Here "+
               "FROM [sheetNameHere$] ORDER BY Field1Here ASC";
           OleDbDataReader dr = null;

           try
           {
               con.Open();
               dr = cmd.ExecuteReader();

               while (dr.Read())
               {
                   c = new FieldsHerre();
                   c.Field1Here= dr.IsDBNull(0) ? "Empty" : dr.GetString(0);
                    c.Field2Here= dr.IsDBNull(1) ? "Empty" : dr.GetString(1);
                    c.Field3Here= dr.IsDBNull(2) ? "Empty" : dr.GetString(2);

                    datas.Add(c);
                   //datas is a List<FieldsHere>
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
           finally
           {
               if (!dr.IsClosed)
               {
                   dr.Close();
               }
               dr.Dispose();
               if (con.State != ConnectionState.Closed)
               {
                   con.Close();
               }
               con.Dispose();
               con = null;
           }
           return datas;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900