简体   繁体   中英

Reading xls or xlsx file using javascript

i am reading one xls file through java script.

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. Is it possible to dynamically fetch the excel file through one browse button <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM