3 Replies - 810 Views - Last Post: 15 January 2013 - 05:04 PM

#1 bramwell2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-March 09

javascript variables from excel data?

Posted 14 January 2013 - 01:25 PM

Is there a way to read in and excel file and store a cell as a javascript variable?

I'm able to read in the excel and store files as Razor variables, but don't know how to convert Razor variables to JS variables.

Any help greatly appreciated.
Is This A Good Question/Topic? 0
  • +

Replies To: javascript variables from excel data?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

Re: javascript variables from excel data?

Posted 14 January 2013 - 01:30 PM

Razor is the .NET templating engine, right? Isn't this, then, just a matter of creating a JS variable in your template, and putting the Razor variable there?

Something like:
<script>
var myJsVar = @myRazorVar;
</script>


Was This Post Helpful? 0
  • +
  • -

#3 rbflowers  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 10-February 12

Re: javascript variables from excel data?

Posted 15 January 2013 - 04:45 PM

the problem is I need to call it in a JS file since it needs to be accessed across multiple files.

I can't use razor syntax in .js files
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3710
  • View blog
  • Posts: 5,958
  • Joined: 08-June 10

Re: javascript variables from excel data?

Posted 15 January 2013 - 05:04 PM

And why not? I don't know much about Razor, or .NET web development for that matter, but the basic principles of server-side generating the client-side code must still apply?

In PHP we've been known to do things like this:
<script type="text/javascript" src="my-script.js.php"></script>


Which will then trigger a PHP file that acts like a Javascript file.
<?php
header("Content-type: application/javascript; charset=UTF-8");
?>

var valueFromPHP = "<?php echo "Hello, Javascript!"; ?>";

function someJsFunction() {
    // Do some important Javascript coding here!
}



In this instance, then, the Javascript file is actually generated by PHP, and the "valueFromPHP" variable will contain whatever value the server-side code needs it to contain.

There is nothing that says the server-side language is limited to only generating HTML.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1