Calling a webservice URI from excel sheet cell - excel

I need to call a webservice URI from an Excel cell. I know this can be done using the in-built WEBSERVICE function. However, passing the parameters on the fly to the URI can be a bit tedious.
For.eg. my webservice URI is :
http://localhost/getEmployeeSalary?emloyeeName=MisterFoo&employeeId=101
The values MisterFoo and 101 are pulled from other cells in the sheet.
So what I am looking for is to call the service like an Excel function (SUM, AVG, etc.), which would look like
=getEmployeeSalary(A2,B4)
where A2 cell contains MisterFoo and B4 cell contains 101.
For now, I have tried looking for a solution but the only thing that comes up is using ribbons (Excel Add-in project in Visual Studio) that take parameters and store the value in a pre-defined cell. This is not what I am looking for though.
Any help or suggestion would be appreciated. Thanks in advance!

you could potentially use a user defined function?
https://support.office.com/en-sg/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f

You need to develop an add-in where you can run secondary threads calling web services because such operations can take a lot of time get results. See Walkthrough: Creating Your First Application-Level Add-in for Excel for more information.

I do this all the time using the Excel Concatenate function.
=WEBSERVICE(CONCATENATE("http://localhost/getEmployeeSalary?emloyeeName=",A2,"MisterFoo&employeeId=",B4))
You can use the Evaluate Formula option from the Formulas menu item to step through the function.

Hey guys I really appreciate your help. This is what I was looking for: http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/writing-user-defined-functions-for-excel-in-net.aspx

Related

Getting the excel displayed value

I've been scouring for days and I can't seem find what should be an easy answer. The displayed value is not necessarily the value that from cell.InnerText. I see post after post that requires you to look at the cell.StyleIndex property & cell.DataType.value to determine how to get the displayed value. And while I have plugged in some of this code and it works I hit another case I didnt handle where the cell StyleIndex is null which I can only assume the cell is formatted as "General". The on screen value "-39718.96" while the cell.InnerText returns "-39718.959999999999". I realize there is a easy fix to this by Double.Parse(value).ToString() but there seems to be an endless supply of formats https://stackoverflow.com/a/4655716/1713000 and that's a shortlist and dates are another problem. It seems we are left to handle each different style ourselves. Did Microsoft really not create a public api that returns the formatted displayed value and has no one really written a complete solution to handle this cluster of a mess?
Using Openxml for sheets is very difficult (much more so than using it for Word). If I were you I'd use the ClosedXMl nuget package as it simplifies Openxml for sheets.
Will use the ClosedXML lib instead

Excel Define Cell Name Using Office.JS

In Excel 365 app, how I can set the Name using excel 365 api at runtime ? In Dev.Office.com, they have provided read-only property to get the name.
Background:
Working on Excel Office 365 apps. We have a pre-define template and for every cell which we use in calculation have defined names for it.
I need to provide the functionality to add multiple cells based on user request(button click on task pane) and use these cells in calculation. I know how to add the field(cells) but stuck at defining the names. There is no way for us to evaluate the formula unless we use excel cell reference such as (B10, C24, etc) which we want to avoid.
Is there any other option to use like content control ?
Note : This is I wanted to do using excel 365 api.
Currently, the names (named ranges and any other constants) are in fact read-only. The good news is that we are in the process of implementing the named-range-addition/manipulation functionality. Unless we run into unexpected difficulties, we should have it available in the coming months (likely as part of ExcelApi 1.4 -- though again, no guarantees there, just an estimate if all goes to plan).

Most efficient way to place hundreds of array formulas?

I am new to VBA and advanced formulas for that matter and would deeply appreciate some guidance here.
I have a workbook that acts as a GUI for a database in another workbook. I use the following array formula to act as a search function:
{=IF(ISERROR(INDEX('Client Contact Database.xlsx'!Data.ContactsFull,SMALL(IF('Client Contact Database.xlsx'!Data.ContactClients=$L$1,ROW('Client Contact Database.xlsx'!Data.ContactClients)),ROW(1:1)),2)),"",INDEX('Client Contact Database.xlsx'!Data.ContactsFull,SMALL(IF('Client Contact Database.xlsx'!Data.ContactClients=$L$1,ROW('Client Contact Database.xlsx'!Data.ContactClients)-1),ROW(1:1)),1))}
Although very sloppy, this works fine. However, I now need to add option buttons to toggle between searching for two different things. This means I have to replace the array formula from A3:L104 through VBA. My question is twofold:
How can I shorten this formula to under 255 chars to use with .FormulaArray? I tried putting it in two halves but my understanding of syntax is not sufficient.
Even if I got that to work, I imagine it would be extremely slow and inefficient. Is there a better way to go about this task?
Any help is greatly appreciated, I'm in way over my head with this. Thanks in advance.
First off, swap out your IF(ISERROR(<formula>), "", <formula>) for something that uses the IFERROR function. This will effectively cut your formula in half as IFERROR takes care of error control and default value without duplicating the formula.
=iferror(INDEX('Client Contact Database.xlsx'!Data.ContactsFull,SMALL(IF('Client Contact Database.xlsx'!Data.ContactClients=$L$1,ROW('Client Contact Database.xlsx'!Data.ContactClients)-1),ROW(1:1)),1), "")
I did not build all of the external references and named ranges for a full build environment, but I believe I transcribed that correctly.

Building a URL using Visual Basic

My name is lee, and I'm new on here. I'm very experienced in Excel, and most aspects of Office, but not so much in VBA.
I have embedded a local map using an API in excel, and want to plot multiple postal codes. I have this working up to 23 postal codes using a Hyperlink and Concatenate in the same formula to build the URL. After 23 postal codes, the formula result exceeds 255 characters, so that's where I fail.
I need one solution - either a way to work around the limit (without using a 3rd party url shortener), or by building the entire URL in VBA. My button launches the formulated url from cell A1, but when it exceeds 255 characters, I assume I will need the button to run the url directly from within VBA?
Anyhow, I'm sure I've probably missed out some vital info, so please, if you think are able to help, ask me and I'll give as much extra detail as possible.
You can split the long string in lets say 2 variables and then use them in VBA to concatenate it with your formula.
An example of what you have would be better.

MD5 Hash function in excel without using VBA

I need a function that will take an entire cell value in Excel and convert the value into its MD5 hash equivalent in a new cell.
Is there a formula in excel that does that? I need a solution that doesn't use VBA. Is this possible?
Without VBA is possible to use webservice formula that invoke a webservice that return the md5sum.
Explanation
=WEBSERVICE(B4)
Result: 89374b6dda3bb0e16132b21fb9887f1d
=CONCAT("https://md5sum.herokuapp.com/?text=";ENCODEURL(B3))
Result: https://md5sum.herokuapp.com/?text=bruno%20tafarelo
B3 cells contains the text to be coded
Value: bruno tafarelo
This web service was developed by me as all the services on internet require a POST method and Excel is only able to perform GET request. It's hosted in a free service and I don't know for how long it will be available.
Web service source code: https://github.com/btafarelo/md5sum

Resources