I am trying to find a proper way to migrate a VB project within an Excel Sheet to C#. Migration will not change most of the code apart from the DB calls because it will use a new DB Structure.
Basically the Project makes several DB calls, performs some calculations and fills some pre-created Excel templates with the data retrieved/handled.
I guess ,the quick way to keep sleeping at night and use these Excel Sheets in the new aplication is to change the VB queries only and update the Excel files to a new version.
However, we want to find a way to migrate the project to C# and perhaps use it in the future in Online Excel Sheets. Here is where I get lost. It seems a way to do it could be with Visual Studio Tools for Office (VSTO ) but we have a Community version and they are included in the professional or Ultimate ones, is that correct? Are there any other ways to migrate such a project?
Thanks and regards
Related
I'm currently busy with a task that involves both manipulating data in an excising excel document as well as the sheet itself.
In the past I've always used OleDbConnection and OleDbCommand to work with excel, but I've been reading about something called a Workbook and I'm not sure which way I should go about this.
Some examples of what I need to do include-
Inserting a new column
Deleting old columns
Setting a cell a certain colour depending on it's contents
Looking for duplicates and deleting them.
In your option which way would be the most efficient way to go about this.
Thanks
Best way would be to go with excel interop if you don't want to use any third party library.
Interop works and any action can be performed which you have mentioned in your question.
Refer this link for more info: http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm
PS: above link is for c# and for interop to work ms excel must be installed on the system, this can be implemented in vb.net as well.
Hope this helps.
I have used Visual Studio Tools for Office, you will have workbooks, worksheets, columns, ranges, etc. Easy to manipulate using C#.
https://msdn.microsoft.com/en-us/library/bb608603.aspx
Install this package into your project Further no need to install Excel also this is fast mothod https://www.nuget.org/packages/ExcelDataReader/
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.
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)
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).
If Im using SqlBulkCopy in .net 4.0 on a sql 2008 R2 database to upload excel data to the database, do I actually need Excel on the box hosting the site for this to work?
The reason I ask is I have a site up and running with this, and the hosting box has excel. The customer wants the site moved to a new box, this one doesnt have Excel and that bulk copy doesnt work. Other than the lack of excel there is no other difference.
thanks
If you are using the Microsoft Excel Object Library (COM Interop) to interface with Excel from .Net 4, then yes you need Excel installed as that is interfacing with the Excel object library.
What are your project references in C#?
Anything link to office automatiion would need taht part of office that is being automated. Also, if .Net 4 that objects may be referenced with the dynamic keyword.
Hard to tell exactly without knowing the project, references, and relevant code.
However, there are several third party libraries that allow interaction with Excel without having Excel installed. So, if you need to work without Excel, investigate using those.