Call out to web service from Excel 2010 - c#

Starting an innovation week at work here. Good ol' Excel project! So here's what we want. We want to be able to create user defined functions in Excel, just like Excel has the SUM, etc. we want to make our own.
These UDF's would take Excel data in, and they would then pass that data to a Web Service which would do what it needs to do and then return the data back. I know how the Web Services will act, but what I need some guidance on is preparing the data in Excel, setting up the UDF's, and dealing with the sending/receiving of the data in Excel. I've never done any Excel programming before.
At first glance, it seems I might not need to do any VBA work, and that I could almost create a plugin for Excel (generate a .xll file from C#), and then go about it this way, but I'm not really sure how this all works.
Am I approaching this right? Are there any other things I should keep in mind? Is there anything I should read up on (any good links)?
Thanks.

There are good articles like below on MSDN.
Article 1
Article 2
Videos on Youtube and other
Video 1
Video 2

You can call a WCF service from Excel with VSTO or with VBA

You will want to use VSTO to create an add-on for Excel. Using Visual Studio create a new project. Select Office and then Excel 2007 Add-on or Excel 2010 Add-on. Check out this great resource for examples on how to get started http://www.packtpub.com/article/microsoft-office-excel-programming-using-vsto it pretty much has everything you are asking for (except calling a web service).
It may be possible to do all of this in VBA but it won't be as easy and you'll have to deal with the security issues that come with it.

You could take a look at XLLoop. This is a framework for developing Excel UDFs on a remote server. It has server implementations in a range of languages and is open source with a liberal license.
(Full disclosure: I work on this project).

Related

Generating an Excel File Example for Visual Studio 2010 and ASP.net and C#

I've come across ExcelPackage and I found a couple of examples of using it, but none seem to work, they've all got some aspect, component missing or are for a different version of Visual Studio. I simply need to generate a .xls or .xlsx or even a .csv file, but as I am using a 3rd party server I can't use the Office .com objects. I have used SpreadsheetGear in the past which is expensive and as I am retired, I can't afford this sort of product.
If anyone has a working example of ExcelPackage or any other freeware offering, or can point me in the direction of one that has everything I need, it would be appreciated. A regular Web App rather than MVC would be preferred.
Take a look at Simplexcel by Michael Stum. It is designed around simplicity, is fully supported under ASP.net and should allow you to make simple, but extremely usable Excel cheats. You have an simple example available here.
Check out the Open XML SDK. This gives you the ability to generate and manipulate Office documents without using Office itself or the interop, and as such makes it a suitable approach from the server-side.

Visualise map data in Excel

I have postcode level data in an Excel workbook and ideally I would like to have a map on another sheet of the area that I am interested in. The postcodes in my dataset should be highlighted within that map. I am using Excel 2010 and have no prior experience with GIS but plenty of experience with C#, Java. Any ideas of how I can achieve this? I looked for open source add-ins and didn't find an awful lot. Is there another way I can achieve what I want?
I use Topo.ly. You can just copy all your post codes from Excel and paste them in Topo.ly, and it will plot them on Google Maps. It also hosts your maps, so you can save it and come back to it later, or share it with others.
You can take a look to that solution for non-gis-users:
http://www.esri.com/software/esri-maps-for-office
It requires Office 2010 (that's no problem in your case) and it is based on a privative GIS software (no FLOSS). On the videos section there are some examples.
This can be a good starting point. You will need some knowledge of WPF
Bing Maps Windows Presentation Foundation (WPF) Control, Version 1.0
Then using VSTO you can integrate it into Excel
Using WPF Controls in Office Solutions
Sample WPF application is # Integrating Bing Maps With WPF
Edit :
Didnt find much on non WPF solution but you can give this a try
Integrating Virtual Earth Maps and Excel 2007 Using Visual Studio 2005 Tools for Office Second Edition
Download here http://archive.msdn.microsoft.com/VSTOVirtualEarthXL
For future reference or someone who has similar porblem, you can use an Excel add-in called Funfun to create data map in Excel 2016. I made two examples here.
As you could see, there is some code in the middle section of the screenshot. That is because Funfun allows you to write and run JavaScript code directly in Excel, also, the JavaScript code could use the data stored in the sheet. The capability of using JavaScript means that you could use 3rd party libraries like HighCharts.js or D3.js to plot charts like data map. In those two examples, I actually used highmaps which is part of the HighCharts.js library. The highmaps.js already has different templates from world map to specific map of different countries. I believe you could find the map you need.
Funfun also has an online editor in which you could test your JavaScript code with you data. You could check the detailed code of the examples above on the link below.
https://www.funfun.io/1/#/edit/5a5c9a50404f66229bda3ae0
https://www.funfun.io/1/#/edit/5925036104ce702ccfb22b0e
If you are satisfied with the result you achieved in the online editor, you could easily load the result into you Excel using the URL above. Of couse first you need to insert the Funfun add-in from Insert - My add-ins. Here are some screenshots showing how you could do this.
Disclosure: I'm a developer of Funfun

Reading/Writing Excel sheet real time in C#

Is there any free or purchased library or any API which allows me to update excel sheet while it is opened also.
I'm not certain of the nature of your project, but perhaps you could create an Office Add-In? I've had some very good experiences with Add-In-Express: http://www.add-in-express.com/add-in-net/index.php
If just creating an add-in isn't going to work for your application, consider writing a plugin that your application can communicate with to do the work for you behind the scenes.
If you want your Excel spreadsheet to be updated in real time, you have to develop an RTD which can be queried by Excel itself. Please refers to Microsoft documentation for that. Add-In express provides you excellent simplified API to develop that, we are using them and we are very happy with that.
There is no tool that can do that since the file is locked by the operating system.
With COM you should be able to drive a workbook that has been opened by the user.

Writing to Excel using Microsoft.Jet.OLEDB.4.0 + Editing at the same time

I used the code described here to update an excel sheet using c#.
The problem is that the file gets locked and cannot be edited manually while it is being updated (unlike the example code, i am doing constant updates, realtime data feed)
Since it is a trading application, operators need to be able to add excel formulas while other cells are being updated.
I am new to this and open to switch to any other technology/architecture making this possible.
I am receiving a data feed and I just want to put in an excel file and update it in realtime while making it possible for sheets to be edited manually. I guess if the dll or add-in is called from within excel rather than oledb I would not have such a lock issue. So if there is any way to call my code from excel and not the other way round (not too painstaking if possible) I welcome any suggestion
EDIT : Solution
I finally opted for RTD Technology for Excel which is exactly what I was looking for.
MS Reference is 10 years old and VBA oriented but it gives the big guidelines and things did not change much since. I think I would not have made it through without Kenny Kerr's Artcile on the subject. Many thanks to him.
You will need to integrate into Excel itself... Excel offers an interface to achieve exactly what you describe... it is based on COM and called RTD (Realtime Data-Server) and gets called from Excel.
You have to build a COM component which adheres to the official spec...
Some usfeul links to get you started:
http://msdn.microsoft.com/en-us/library/aa140059%28v=office.10%29.aspx
http://msdn.microsoft.com/de-de/library/microsoft.office.interop.excel.rtd%28v=office.11%29.aspx
http://exceldna.codeplex.com/workitem/5902 (free library to ease the development)
http://www.add-in-express.com/docs/net-excel-rtd-servers.php (commercial library to ease the development)

Reading a Excel 2007 Spreadsheet in C#

I've done some googling and there seems to be a plethora of tools for reading excel 2007 spreadsheets using c#. I'd like to know which one performs best and is easy to use.
Frankly, it depends on if you have Excel installed on the machine.
If you have Excel installed, using Microsofts Office APIs is as quick and ( for the price ) painless as you are going to get. That said, if you don't have Excel installed, the question gets much trickier.
Also, note, if you are installing to a web server that is available to the world, using Microsoft's Office APIs often isn't actually legal, as the end user needs to have an office license for you to be legal. If this is the case, and you are developing for redistribution or internet deployment, make sure that the library you are considering has no dependencies on the Office APIs, as their redistribution isn't actually legal either. If you need to, for example, provide a viewer for people that don't have Excel installed, you can't legally use the Office APIs, nor can you use 3rd Parties that depend on that layer. Compliant libraries will make it clear in their description that they don't depend on Excel.
It depends what you're trying to do with the spreadsheet.
If you want to read tabular data, OleDB is the best option.
If you want to read formatting or specific cells, you should use a third-party component. (I can't recommend a specific vendor)
You should avoid using Excel's COM object model unless you want to interact with an open window or print a spreadsheet.
I've had pretty good results with Koogra.
Check the Open XML SDK. It includes a "Productivity Tool" that lets you walk through the structure of a document to help write your code as well.
I looked into the Open XML Format SDK about a year ago and it seemed like a good alternative that does not require Office installed.
I have used GemBox and the Microsoft Office APIs to read in spreadsheets. I have had success with both options but I tend to like GemBox a bit more. It is fast and simple to implement but comes with a price tag.

Categories

Resources