Message Boards Message Boards

Stock allocation spreadsheet using EmbedCode

Posted 10 years ago
POSTED BY: Chad Knutson
5 Replies

I'm very glad that method for googledocs worked for you, Pieter.

As you have learned, the VisualBasic option is not directly useable by Excel. I think that an EmbedCode option for Excel is being planned, but I have no idea when it would be available.

Another user (Rodrigo Murta) created a basic function for Excel that might work for you. See his reply in this thread. I haven't tested it personally, so I don't know if modifications are needed for multiple inputs.

POSTED BY: Chad Knutson

This can be made to work with some specifications on our functions and a minor tweek to the results from EmbedCode

First, the WolframCloud APIFunction must be made to work with a list of companies rather than a single company.

co = CloudDeploy[APIFunction["comp" -> DelimitedSequence["Company", ","], FinancialData /@ #comp &, "JSON"], Permissions -> "Public"]

Note that DelimitedSequence tells the function to expect multiple values. Also, the output format is now specified as JSON, which works nicely with google spreadsheet.

Now create the embedded code as before

EmbedCode[co, "GoogleDocs", ExternalFunctionName -> "WCFinance",  ExternalTypeSignature -> {{"String"}, "Array"}]

I have named the function WCFinance. The javascript types for the input and output for my api are now specified.

I assume that we'll want to call our function using reference cells (e.g., =WCFinance(A2:A8)). Since my APIFunction is expecting a string for input, I need to modify the embedded code to convert the cell inputs to a string. This trivial to do. Just call join() on the input variable "comp". The modified line of code look like this:

_payload["comp"] = comp.join();

Now I can call the function with multiple inputs, and the output is automatically written to the correct cells. enter image description here

POSTED BY: Chad Knutson

Hello Chad, nice example thanks, In the Mathematica help "GoogleDocs" is not mentioned yet. Only when I use $EmbedCodeEnvironments it is mentioned.

One of the things I am searching for is how make just one cloud function call, get a list of lists returned and then show every value in its own cell.

The questions is how to show a matrix type result in each in its own spreadsheet cell. This would speed up the results since the communication overhead per cloud call is quite high.

Do you know how to do this in a Google spreadsheet or in a XL spreadsheet.

Hi Pieter,

I'm sure this can be done, but right now I don't know how. I'll post a solution when I have it.

Returning values in across multiple cells can be done in a google spreadsheet using arrayformula (e.g., =arrayformula(a1:a2) will return the values of cells a1 and a2 in 2 different cells). Surely excel has something similar.

Now to tie this all together....

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