Message Boards Message Boards

2
|
18870 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: Chad Knutson
POSTED BY: Seth Chandler

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 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

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

I'm not familiar with VBA, so I can't provide much guidance for you. I suspect that you could make it work -- using URLFetch with appropriate options in mathematica does return results from deployed FormFunctions.

There is support for VBA in EmbedCode, but so far only for APIFunctions. For example, this returns VB code:

EmbedCode[APIFunction[{"x" -> "Image"}, Blur[#x] &], "VisualBasic"]

I have not yet tested the resulting function (though I plan to do this soon) to ensure that I can send image files through VB.

POSTED BY: Chad Knutson

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

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

Nice question. Here is a simple implementation on Excel.

Let's create some Cloud API using Wolfram Cloud (the same can be done from desktop version 10):

CloudDeploy[APIFunction[{"x" -> "Integer"}, Prime[#x ] &],Permissions->"Public"]

Save your Cloud Link, something like: "https://www.wolframcloud.com/objects/fc7dae07-d9a0-454f-a8d6-ab12bdbab2b3", to use in your VBA code.

Open Excel, go to VBA (ALT+F11), then create a new Module in your current file.

enter image description here

Then select your module, and create a function to call the information from your brand new Cloud Object as:

Function wolframPrime(x)

    Dim strURL As String
    strURL = "https://www.wolframcloud.com/objects/YourCloudLinkHere"&"?x=" & CStr(x)
    Set http = CreateObject("MSXML2.XMLHTTP")
        http.Open "GET", strURL, False
        http.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" 'prevent cached data
        http.Send
        wolframPrime = 1 * http.responseText
    Set http = Nothing

End Function

Now you can test your new function in Excel:

enter image description here

And get:

enter image description here

Don't forget that each time you use this function, you are consuming your Cloud Credit.

Very cool no?

PS: Unfortunately, the Community do not accept attachments in XLSM format. I created a example file with the embed code. Maybe moderators can change that?

POSTED BY: Rodrigo Murta
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