是否可以从客户端读取excel表格(.xls)的数据而不将其上载到服务器 [英] Is it possible to read data of excel sheet(.xls) from client-side without uploading it onto server
问题描述
你好,
有可能吗??????????
需要从excel文件(.XLS)上传数据***.但我不想在服务器上上传该.xls文件,并从中读取数据.
我想读取驻留在客户端的文件,并在确认后想直接将xls文件中的值更新到数据库中,而无需从服务器上载该xls文件.
不需要从客户端到服务器的文件物理移动.
我认为这是可能的,但我不知道该怎么做,
我知道如何上传文件并从服务器读取文件.
请在这方面指导我....
我是代码项目开发人员和贡献者的忠实粉丝:-)
在此先感谢
英德拉吉·苏塔尔
.NET Web开发人员
indrajeet.sutar@gmail.com
inder2305@gmail.com
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
推荐答案
您可以尝试
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>
您也可以参考msdn链接
http://channel9.msdn.com /forums/TechOff/414414-Help-with-reading-from-an-excel-file-using-javascript/ [ ^ ]
Also you can refer to msdn link
http://channel9.msdn.com/forums/TechOff/414414-Help-with-reading-from-an-excel-file-using-javascript/[^]
我的答案有些冗长,但事实确实如此.它有优点也有缺点.
它假定一个名为 FieldsHere 的类,该类
映射excel列和DB列.当然需要
适应它.您还可以使用OleDbDataAdapter填充数据集.
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; }
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; }
这篇关于是否可以从客户端读取excel表格(.xls)的数据而不将其上载到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!