Chaining formula parts in Excel - excel

I want to chain in one Excel formula webservice and filterxml, but fail on something... The goal is to read out certain information with XPath from an API answer page, which is XML.
I'm doing so:
=DUMP(FILTERXML(WEBSERVICE(https://example.com/api);"response/answer/result";"position"))
But i get in this no meaningful error and don't know, what to adjust :( I'm using Office 365, so filterxml and webservice should work, as far i know.
UP:
After adding quotes to url, like =DUMP(FILTERXML(WEBSERVICE("https://example.com/api");"response/answer/result";"position")) got a further error too much arguments.
Shortening the XPath to =DUMP(FILTERXML(WEBSERVICE("https://example.com/api");"response/answer/result/#position")) did the work successfully.

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: How does the =FILTERXML function work?

I'm trying to get FX rate from ECB in an Excel Spreadsheet. First of all I get the XML:
=WEBSERVICE("https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?lastNObservations=1")
Then I try to get the exchange with the FILTERXML function:
=FILTERXML(cell_with_XML,"//message:genericdata/message:dataset/generic:series/generic:obs/generic:obsvalue/#value")
However, I always get a #VALUE error. Can anybody explain me what I'm doing wrong?
You have to deal with xml namespaces. Remove them with SUBSTITUTE, then write your XPath expression to get the data from the attribute, not the node.
Working example :
=FILTERXML(SUBSTITUTE(WEBSERVICE("https://sdw-wsrest.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A?lastNObservations=1"),":",""),"//genericObsValue/#value")
Output :

Microsoft Excel 2013 - WEBSERVICE and FILTERXML formulas

Trying to pull the Manufacturing cost index from an XML pull. The XML comes from https://api.eve-industry.org/system-cost-index.xml?name=Osmon
I successfully used the WEBSERVICE function in excel to create and pull the data;
P28 = =CONCATENATE("http://api.eve-industry.org/system-cost-index.xml?name=",Q28)
=WEBSERVICE(P28)
My question is, how do I used FILTERXML to pull just the Manufacturing data?
So far I have
=FILTERXML(P29,"//Manufacturing")
But it only returns a #VALUE! error. I have also tried a bunch of other ways.
I'm pretty new to this also, but it seems you want to pull out the attribute of the activity whose name is Manufacturing
So the xpath expression would be //activity[#name="Manufacturing"]
or maybe
//solarsystem/activity[#name='Manufacturing'] depending on how specific you need to be.
Both work fine on your link.

Error using concatenate

I try to merge text with date in a single cell. I looked online and I found the following options:
=G5&TEXT(F5;"DD/MM/YYYY")
And
=CONCATENATE("ZIMMERMANN U-4600 ";TEXT(F5;"DD/MM/YYYY")).
Unfortunatelly , nothing works, although in the other forums everybody was happy with the result. I get a #VALUE! - error.
I played around with the formatting and the languages of windows while giving in the code but nothing helped.
The code has ; instead of , due to the fact that it is a european office-package (and it doesn't work with "," either).
I suspect the #VALUE! error is coming from the TEXT(F5;"DD/MM/YYYY") part. Do trying it alone in a cell as =TEXT(F5;"DD/MM/YYYY"). If this also is resulting in #VALUE! error, then this is the case.
Unfortunately the pattern "DD/MM/YYYY" in TEXT function must be according to the locale settings of the Excel and the system the Excel is running on. In German Excel it must be
=TEXT(F5;"TT/MM/JJJJ") for example.
Have a look at Control Panel - Region what pattern is used for dates there. Then do using the same in TEXT function.
See TEXT function -> Other format codes that are available for another method getting possible format codes directly from the Excel.
This is a big disadvantage of the TEXT function if the Excel file shall be exchanged between different users from different locales.
Better approach then would be:
=TEXT(DAY(F5);"00")&"/"&TEXT(MONTH(F5);"00")&"/"&TEXT(YEAR(F5);"0000")
since the pattern 0 is locale independent.

Calling a webservice URI from excel sheet cell

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

Resources