Update VSTO Excel workbook without interfering with the Data itself - excel

I built an Add-in for Excel using VSTO, and deployed it over...
now i have an updated version (where there are some new Toolbar Controls, a new column, and some bugs fixed in the behaviours).
my problem is that my client was working with the previous version, was filling his Data inside the sheet.
How can I Update the VSTO Add-in, and Migrate the Data ?
thanks for your help

Well it depends on how you created the add-in. An add-in is NOT coupled with any workbook (which is different to document level customization) unless you make it so.
Basically you just change your code, deploy a new version and your client will install it. When Excel is launched the new version will be used so if you have a button on Ribbon, the button now will use the new version.
If you, for any reason, make the add-in tightly coupled with a specific workbook (format) you'll have to deal with it.
So for example, if the new version is now expecting a new layout of data you'll either ask clients to change it manually or write a function that will do that for them.
Example: We have a VSTO Word add-in that does a lot of stuff, the add-in is using a template which has a version like (1, 2, 3, 4 ...) when we change the template (e.g. adding styles, addin shapes, removing shapes, etc.) we also maintain a recursive update method that is triggered on opening a document.
The method is checking the version of the template with the version hardcoded in the code, comparing and if the template version is older will trigger the update functionality (step by step, so from v1 to v2 then v2 to v3 and so on till it reach the latest version)
Hope that helps

Related

Can I provide multiple copies of a VSTO document-level Excel app without publishing each one separately?

I have created an Excel document-level customization in Visual Studio 2017 using Windows 7. The document provides a set of tools for charting and analyzing data that are contained in several worksheets within the document.
I would like to provide the end user multiple versions of this document without publishing each one separately. Each version differs only in the data that will be contained. All the code, classes, subs, and functions would be identical for each version. I was hoping they could
rely on the same assembly.
I tested this by publishing a document (named DocumentA) on a test PC (Windows10) and then copying an additional file (named DocumentB). Trying to open DocumentB in Excel produces the following error:
Could not load assembly "DocumentA", Version 1.0.0.0. Culture =Neutral or one of its dependencies. The System could not find the file specified.
I think I understand why this happens. However, if I save the original published document DocumentA as DocumentB1, I can open the renamed file
with no problem. Not sure why this works and the other case does not. The property settings for assembly name and location were identical for DocumentA and DocumentB.
Is there any type of work-around? Or must I publish each of these additional documents separately?
Thanks!
I would like to provide the end user multiple versions of this document without publishing each one separately.
You need to create separate document level add-ins then. Or you may consider developing a single application-level add-in instead. See Walkthrough: Create your first VSTO Add-in for Excel for more information.

Creating a C# program that works with an existing Excel Workbook

firstly I'm not even sure if its even possible so i thought id ask
all research that i have done haven't given me the answers and info I need.
I need to create a VS Win forms program (using visual studio 2012) that interacts with a DB & AN EXCEL 2010 WORKBOOK?
can it be reasonably done?
the specifics are these
the excel 2010 workbook already exists and comprises 35 sheets/pages, BUT NOT ALL PAGES NEED TO BE USED IN THE PROGRAM only 12 do. it is a workbook for project management
the program works with button click events, that when pressed would open a specific page/sheet of the workbook. the user would then be able to fill in fields etc and save it
ideally also print it(Specific page) (from program and not excel directly) and obviously access it and amend or add to it from the Program time and time again
the workbook is a master workbook so every time a new project is created, the program would need to generate a new "instance" of the master workbook (the 12 pages)
each project and the "instance" of the workbook would need to be saved separately on the Hard Drive
this is/would be a client side stand alone application running on a laptop
is this possible? or highly complex?
and if so what are the relevant classes that would need to be imported into the project
or is it better/possible? to take the relevant pages ad make a new workbook inside of visual studio office node and make instances of it ??
at no point at all does data in the DB or Excel workbook need to be transferred to one another. they run separately but are part of the one program
any and all help would be appreciated
This is not a complex project, visual studio supports Microsoft Excel 12.0 Object Library. You can import the library and start using the events built in. It works great with excel. I have created numerous projects just like the one you've mentioned and had no problems so far.
Try this link

Manage spreadsheet versioning

We have a lot of VBA code in spreadsheets and a lot of time people save them to local drives. When we want to upgrade the spreadsheets we push a new version out to a shared drive but dont have any way of enforcing that people dont use the old versions of the spreadsheets.
Is there some best practice here to deploy vba spreadsheets so if someone loads an old version it wont open or will ask you to upgrade. It seems like this must be an issue for any custom solution so i would have through MS would have some solution here.
Does microsoft have a standard versioning / deployment solution for this or do i need to come up with some home grown solution (spreadsheet pings a database on startup to check version)
If its just the VBA code you want to be able to upgrade one solution is to separate all the code into an XLA that sits on an accessible server.
then the users Excel has an addin loader that gets the latest version from the server, or you could embed the loader in the workbook.
There is a working example reversioning Addin Loader available at
http://www.decisionmodels.com/downloads.htm
Though I've not done this. I've see people do something similar where they store the code in dlls in the database, and then verify that the local ones are the same on start up.
Add a custom property to the workbook, such as a GUID, Integer, Date, or whatever you need. On startup, check the value and determine if VBA should continue or whatever implementation you decide. Usually, I open the "shared" latest version of the document and inspect its custom property. If user is not using latest version, display a message prompting the user to get the latest version. This is usually good enough. I have done this for years with great success for Access, Word, and Excel VBA.
One real problem is people who ignore the prompt to update. They will do this because they fear losing data, bugs in latest version, and so on. You need to address their concerns and not try to "lock" them in to your "solution" to this problem. I strongly recommend you always provid a means of "importing/upgrading" data to latest version of workbook.
Fairly simple to implement. If you address the above mentioned problem effectively, people will start to trust the "prompt" and you will find this is a really simple and effective solution.
If you workbook is tied to a database, it gets a little more complicated. Generally, you do not allow the user to maintain the data outside of the database. When they want to modify the data, you generate the workbook for them. After they are done modifying data, you import the data. (The workbook is saved for "backup" purposes or the user can maintain a copy of the workbook for reference or an archive.) This has the advantage of eliminating the need to maintain document version since the document is "virtual".
Define a current version property. Use whatever way for that, like a constant in VBA.
Find a standard way to access the latest version. It could be on a shared drive always on the same path, or whatever other means you have.
If current version number < latest version number then:
Ask to upgrade
Show the upgrade procedure
Possibly do some locking on normal VBA operations until the upgrade is done
An easy solution would be:
Store a version number somwhere in the workbook (on a hidden sheet for example so that it will not get removed accidentally) or as a variable.
Store a text file with the latest version number on your share
Include a macro which automatically reads the latest-version-textfile and compares the version number to the one in the currently running workbook. If its too old just show a message-box (telling the user to update) and close the workbook.
I'm using a similar approach and it works fine.

Surface a .NET method as a UDF in Excel 2007, using a VSTO 2008 Add-in

We have an existing add-in that we publish to users via click once. We would now like to use this as a vehicle to publish some of our existing C# methods directly into Excel so that the users can call them as a UDF.
For example - I have an assembly called MyAssembly, that has a class called MyClass with a public method called MyMethod. I also have an excel addin which adds some item to the ribbon for some custom functionality. I would now like to publish MyAssembly with my existing addin so that a person who has the addin installed can enter =MyMethod into a cell and have my custom method run.
How would one go about doing this?
I solved this quite comprehensively by using ExcelDna, an open source XLL implementation which is very simple to use, and pretty much avoids the whole COM debacle all together. So far it has matched our requirements perfectly...
http://groups.google.com/group/exceldna
you have not been very verbose about what you want to do. What do you mean with "users can call them"?
If you mean that add-in methods should be exposed to VBA you can find two articles on that here:
http://blogs.msdn.com/andreww/archive/2008/08/13/comaddins-race-condition.aspx
http://blogs.msdn.com/andreww/archive/2008/08/11/why-your-comaddin-object-should-derive-from-standardolemarshalobject.aspx

Excel Expert: need a good solution to fill some data into a complex excel sheet

I am stuck with a problem
The Requirement is that, there a complex Excel file(XLS) that is used as template; it has Macros and all the worksheets are either locked or hidden. When the user clicks to download it, the follows operation occurs
Unlock a particular worksheet, fill some data # certain cells and then lock it back.
Unhide a worksheet, fill some data # certain cells and then hide it back.
I think there are two options to resolve it (if there are more then please let me know)
Interop libraries / Excel Object Library
OLEDb Driver
I cannot got with the option 1 as excel is not installed on the webserver and I heard that it's not a good option to install MSOffice # webserver.
My question is that can we use OLDb to perform the operations mentioned above OR is there any other option ???
BTW Sharepoint service is also not available :(
Please help!!!!
You could maybe try ExcelPackge.
See this article:
Server-Side Creation of Excel 2007 Files Using .NET 3.0 and Office Open XML
see also:
Office Space - Building Office Open XML Files
Check out this question I asked some time ago for an overview of options. I ended up going with the Aspose library, which I link to in my original post. It's not cheap, but it does the job very simply and elegantly. It even has templating functionality built in (called SmartMarkers, IIRC).
SpreadsheetGear for .NET will handle this and has an API which is very similar to Excel. You can see what our customers say and download the free, fully functional evalution here.

Resources