سؤال

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top