#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Set variables in Javascript from Excel spreadsheet


    I have a Javascript that displays a timer on a screen and when the timer reaches a set value it changes the colour of the backround to 'Red'. I need to be able to dynamically change this variable, based on a set of circumstances. I was wondering is it possible to set the value of the Javascript variable from a cell in Excel. I have provided my code below, clock_limit is the variable I want to be able to set using a cell from an Excel spreadsheet.


    Code:
    <script type="text/javascript">
            var minutesLabel = document.getElementById("minutes");
            var secondsLabel = document.getElementById("seconds");
            var clock_limit = 828;
            var totalSeconds = 0;
            setInterval(setTime, 1000);
    
            function setTime()
            {
                ++totalSeconds;
                secondsLabel.innerHTML = pad(totalSeconds%60);
                minutesLabel.innerHTML = pad(parseInt(totalSeconds/60));
            
    if (totalSeconds> clock_limit)
            {
              document.body.style.backgroundColor = "red";
            }
            else
            {
              document.body.style.backgroundColor = "green";
            }
    
    }
    
            function pad(val)
            {
                var valString = val + "";
                if(valString.length < 2)
                {
                    return "0" + valString;
                }
                else
                {
                    return valString;
                }
            }
        </script>
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    Note: Java and JavaScript are very different programming languages.

    JavaScript that is executed on a web page cannot read or write files of any type.

    If the Excel file is on the server, you could use a helper language like PHP to read the Excel file and pass the value along to JavaScript. The workflow for this is not that complicated, but you'll need to use a third party library for parsing the Excel file. This can be done with other server side languages (other than PHP) too.

    If the Excel file is on the client, you will either need to upload it to the server, or use a client-side language that is able to elevate its privileges (like Flash or Java). The workflow for this is not particularly simple.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Thank you for a prompt reply.

    Originally Posted by E-Oreo
    Note: Java and JavaScript are very different programming languages.

    JavaScript that is executed on a web page cannot read or write files of any type.

    If the Excel file is on the server, you could use a helper language like PHP to read the Excel file and pass the value along to JavaScript. The workflow for this is not that complicated, but you'll need to use a third party library for parsing the Excel file. This can be done with other server side languages (other than PHP) too.

    If the Excel file is on the client, you will either need to upload it to the server, or use a client-side language that is able to elevate its privileges (like Flash or Java). The workflow for this is not particularly simple.

IMN logo majestic logo threadwatch logo seochat tools logo