Message Boards Message Boards

2
|
19505 Views
|
9 Replies
|
13 Total Likes
View groups...
Share
Share this post:

EmbedCode examples and procedures for spreadsheets such as Excel and Google

So, it appears possible in Mathematica 10 to generate VisualBasic code and JavaScript code by using commands such as

 EmbedCode[APIFunction[{"x" -> "Real"}, #x^2 &], "JavaScript"]

But what isn't clear to me is what one does with the output. I would love it -- and it would be extremely useful to a LOT of people, I think -- if someone could either describe or make a video showing how one takes the Embeddable Code and stuffs it into an Excel spreadsheet or Google Spreadsheets and then calls the function from a cell within one of these spreadsheets.

POSTED BY: Seth Chandler
9 Replies
POSTED BY: Rodrigo Murta

Dear Rodrigo, macros are potentially dangerous and may cause harm to user computers. While we are sure your file is fine, we need to be generally cautious to protect Community members from potential harm. Officially we cannot support this format but you perhaps could offer a link to a Dropbox or a similar service.

POSTED BY: Moderation Team

Hi Chad, Thanks for the tip. It does bring be a step closer but the problem remains. The problem is that VBA code is quite different especially for the `POST´ command. Cheers, Wouter

Posted 10 years ago

and it would be extremely useful to a LOT of people,

Maybe, but disappointing to see that APIFunction requires the cloud. Does every update of my {desktop} spreadsheet consume cloud credits?

POSTED BY: Douglas Kubler

This happens to me too often, and on different computers: when posting some reply on this site, my answer ends up being substituted by someone else's post...

So, here I am with my second try:

What I wanted to say is that I would really love to see in the (near) future the capacity to call a LOCAL Wolfram Kernel from Excel, in an easy way.

I understand the potential of cloud calls, and that it covers a new market. But I really believe that the old market (local computations) has been kind of neglected for far too long... A huge percentage of the world engineering in done in Excel (even if we may all agree that some of it shouldn't), and this format is actually extremely powerful to do lots and lots of stuff. Linking with the cloud is fine for few calls, but paying for a processor far away, and waiting for the answer, when mine is at idle, is not optimum. Making thousands of calls to the cloud, when a spreadsheet is filled up with thousands of user defined functions, and the user is simply changing values, or editing it, is not realistic.

I really think that the Enterprise/Free Player vs Player Pro notion should be used here. Enterprise signed calls to the local free player kernel should be as easy as what is currently being presented for the cloud calls, and non Enterprise signed calls would be possible for the Player Pro kernel.

POSTED BY: Pedro Fonseca
POSTED BY: Seth Chandler

Dear All, Thank you very much for these pieces of code. They are very helpful! One extra question though: How do I upload a (text) file in VBA using the POST method for instance using the FormFunction as a cloud object.

I've tried a lot of stuff, the form works in my browser (ie it can upload a text file, But when I POST the file in VBA (excel) I get my original form back instead of some response the function should give.

Thanks very much in advance for any assistance!

PS: is it correct there is no support for VBA in the EmbedCode function?

Best regards,

Wouter

POSTED BY: Chad Knutson

Seth, thanks for following up on this. I agree that not being able to run EmbedCode results in google spreadsheets is a problem. I'll try to get the developers' plans for future development.

Just for fun, I set up some Javascript code to create a function in google spreadsheet. I know almost nothing about Javascript, so perhaps this could be done better. First, I create and deploy an APIFunction in Mathematica.

CloudDeploy[APIFunction["x"->"Number", #x^2 &], Permissions->"Public"]

Now I go to google spreadsheet tools/script editor and create a function to call this API. Note that I have copied and pasted the url from the deployed api and specified the variable's name ("x").

function myapi(x) { 
    var url = "http://www.wolframcloud.com/objects/ed9022d0-e195-4265-96c4-1d7b0d0f68b8";
    var args = {"method" : "POST",
                "payload" : {"x" : x}};
    var response = UrlFetchApp.fetch(url,args).getContentText("UTF-8");
   return response
}

Then in my spreadsheet, I just call the function in a cell with =myapi(-input-), where input can be a number or a cell reference.

Granted, this is a trivial case, since there is a single input variable and the output is just a string. But it does work! I expect that extending to multiple input variables or different types of output would not be too hard.

POSTED BY: Chad Knutson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract