[英]Reading xls or xlsx file using javascript
i am reading one xls file through java script. 我正在通过Java脚本读取一个xls文件。
function upload1()
{
var ControlCn = new ActiveXObject("ADODB.Connection");
var Conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\\TEST.xls;Persist Security Info=False;Extended Properties=Excel 8.0;";
ControlCn.Open(Conn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "select * from [Sheet1$]";
rs.Open(SQL, ControlCn);
if(rs.bof)
{
document.write('No Data Avaliable');
}
if(!rs.bof)
{
rs.MoveFirst()
while(!rs.eof)
{
for(var i=0; i!= rs.fields.count; ++i)
{
document.write(rs.fields(i).value + ", ");
}
document.write("<br />");
rs.MoveNext()
}
}
rs.Close();
ControlCn.Close();
}
In the third line we are giving path of the xls file that we want to read. 在第三行中,我们提供了要读取的xls文件的路径。 Is it possible to dynamically fetch the excel file through one browse button
<input type="flie" ...
是否可以通过一个浏览按钮
<input type="flie" ...
动态获取Excel文件<input type="flie" ...
You can try the below: 您可以尝试以下方法:
<input type="file" id="myexcelfile"/>
once the user browses the file, then you can get the path as below: 用户浏览文件后,您将获得如下路径:
var filepath=document.getElementById("myexcelfile").value;
You can use the "filepath" variable in your code for passing the excel sheet name 您可以在代码中使用“ filepath”变量来传递excel工作表名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.