Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting data from Excel using Javascript

    How can I use javascript to read in data from an Excel worksheet? I'm working on an easily-updateable web page in which link data is to be read in upon page load from an excel worksheet. I've attempted to use the GetObject() and ActiveXObject() functions and have been unsuccessful. Any Suggestions?

    -- thanks in advance

  • #2
    TNO
    TNO is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    213
    Thanks
    2
    Thanked 1 Time in 1 Post
    Where is this spreadsheet located? on a server or the client computer?

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The speadsheet is located on the server...in the same directory location as the web page.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so, what's your code, then?
    *keep it simple (TM)

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's some code of what I'm trying to do. I've interchanged GetObject(..) with ActiveXObject(..) while trying to get it to work. According to what I've read about the two..I think GetObject is what I'm wanting to use here because the file already exists. Theres also a potential issue, which I haven't addressed yet, of getting the value given to variable "data" to show up within the html.


    <SCRIPT LANGUAGE="JavaScript1.2">
    <!--

    function Get_My_Data() {
    var data;

    var excel = GetObject("C:\\ESE.xls", "Excel.Application");
    var workbook = excel.Workbooks("Sheet1");
    data = workbook.Cells(1,1).Value;

    // Now I want to be able to use the variable "data" in the HTML

    }

    //-->
    </SCRIPT

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ranbo
    Code:
    var excel = GetObject("C:\\ESE.xls", "Excel.Application");
    wherein is your issue - it's looking on your hard drive, not that of the server.
    *keep it simple (TM)

  • #7
    New Coder
    Join Date
    May 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    right now my hard-drive is acting as the server. I'm developing the web-page on my hard-drive. My assumption is that as long as my web page and the excel file are in the same directory that the path info put into the GetObject() function should be the same. I've tried leaving off the C:\\ and just putting "ESE.xls" as the path and it still doesn't work. For testing purposes I've tried to simply open the file when the web page opens and that doesn't work.

  • #8
    New Coder
    Join Date
    May 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    never-mind. I got it working. Apparently the "Open(..)" function associated with a file is used to set a variable to control the file...not to open the file. Heres the bit of code that takes an excel file and reads in the text from a cell.

    <SCRIPT Language="Javascript">

    var excel = new ActiveXObject("Excel.Application");
    var excel_file = excel.Workbooks.Open("C:\\ESE.xls");
    var excel_sheet = excel.Worksheets("Sheet1");
    var data = excel_sheet.Cells(1,1).Value;

    </SCRIPT>


    thanks for your help jbot.

  • #9
    gph
    gph is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    161
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ranbo
    According to what I've read about the two..I think GetObject is what I'm wanting to use here because the file already exists.
    I think you're misunderstanding the function.

    GetObject(..) grabs an instance of an app that's already running.

    ActiveXObject(..) creates a new instance of an app.

    if you use GetObject(..) and an instance isn't running you'll get an error, you can try GetObject(..) like this:

    Code:
    function get_app(app){
    try{return GetObject('',app+'.Application')}
    catch(e){return start_app(app)}
    }
    
    function start_app(app){
    return new ActiveXObject(app+'.Application')
    }
    
    var XL=get_app('Excel');
    Having said that you'd probably be happier using ADO. I've tested ADO verses XL in different environments and found ADO to be 4 times faster simply because you don't need to start and/or direct XL

  • #10
    New to the CF scene
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use OWC (Office Web Components). This allows you to use Excel embedded in your page. From there, JavaScript can talk to all of Excel's methods and excel has the ability to do asyncronous calls back to the server to load data.

    ///TITAN///


  •  

    Posting Permissions

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