www.webdeveloper.com
Results 1 to 7 of 7

Thread: Get text from excel using Javascript

  1. #1
    Join Date
    Mar 2013
    Posts
    7

    Question Get text from excel using Javascript

    Hallo all users from Webdeveloper.com,

    I am new with Javascript and i am stock with this code:

    Code:
    <script language=javascript>
    function GetData(cell,row){
    var excel = new ActiveXObject("Excel.Application");
    var excel_file = excel.Workbooks.Open(data/data.xls);
    var excel_sheet = excel.Worksheets("Sheet1");
    var data = excel_sheet.Cells(cell,row).Value;
    document.getElementById('Data').innerText =data;
    }
    
    </script>
    
    <center>
    
    <div id="Data">Information</div>
    
    <input type="button" value="cell(1),row(1)" onClick="GetData(1,1);" />
    <input type="button" value="cell(1),row(2)" onClick="GetData(1,2);" />
    <input type="button" value="cell(2),row(1)" onClick="GetData(2,1);" />
    <input type="button" value="cell(2),row(2)" onClick="GetData(2,2);" />
    
    </center>
    Is there someone who knows this code, and know what I'm doing wrong.
    The path would be wrong, or I miss the link to the excel doc.

    Advance many thanks.

  2. #2
    Join Date
    Mar 2013
    Posts
    7
    My web site is www.graficmedia.nl

  3. #3
    Join Date
    Dec 2012
    Location
    NSW Australia
    Posts
    73
    What you have there is a typical ActiveX bit of JavaScript that works in IE only. Yes IE allowed that sort of behaviour to be allowed in their browser??

    The way you have written the JavaScript (or copy and paste from elsewhere) requires a local copy of an excel file... THAT MEANS on the computer that opens the web page... not on any server or any computer in a foreign country.

    Assuming you know all that and you are trying to get it to work on your computer ONLY and using Microsoft’s browser IE then it can be fixed.

    What you are doing wrong is not giving the open command a valid path to your excel file.
    *Open(data/data.xls)*

    YOU need an absolute reference to your excel file which would look sumpin like this
    "C:\\amitdata.xls" -- If you use your system drive as indicated BUT better to use a non system drive.

    Remember you are using a Microsoft system so adhere to their lashes.

  4. #4
    Join Date
    Mar 2013
    Posts
    7
    Tanks Grumpyoleman,

    Is there a different kind of way to achieve this with javascript. dit moet wel met een csv, xls bestand.

    Advance many thanks.

  5. #5
    Join Date
    Mar 2013
    Posts
    7
    *dit moet wel met een csv, xls bestand.*

    this should be a csv, xls file

  6. #6
    Join Date
    Dec 2012
    Location
    NSW Australia
    Posts
    73
    Based on your original request the answer is no.
    If you are willing to start over then yes...

    Using technologies that includes JavaScript you would have a html page that uses AJAX to send requests to a server that has PHP (or similar) installed and then the PHP will open/extract/return the requested data from the excel/csv/xml file for AJAX to display into your html page.......

    Alternately you can send a request to a server with PHP installed to open/extract/return the requested data in a html file.....no JavaScript involved.

    If you are trying to do this without the help of a server then the answer is again NO.

  7. #7
    Join Date
    Mar 2013
    Posts
    7
    Super,

    I wil work on te php and Ajax thing, and comunicate with the server.

    Thanks for the Quick Reply grumpyoleman.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles