Excel document version in VSTO add-in

I often use solutions based on VSTO Excel templates. One of the things that I like about this type of project is that I can use cached data sets in an Excel template or worksheet to process the state of the application that is saved after the user saves the file. However, cached datasets pose a problem: the document schema is tied to the application version.

This was not a big problem, but I realized that it would be nice to create a mechanism that will read the version of the Excel document when it is opened, in order to detect and handle version incompatibilities. For example, if my 2.1 plugin opens document 1.5, the cached data scheme will not match what was expected.

Is there a standard or recommended way to print an Excel stamp or worksheet? If not, does anyone have any suggestions on how to do this?

+4
source share
3 answers

I usually use Worksheet.CustomProperties to store such information on my worksheet. Any information that you put in the CustomProperties collection is saved with the worksheet and loaded with the worksheet information when you reload the worksheet.

The books also support custom properties, but I think Worksheet.CustomProperties is the way to go in your case.

+3
source

I do not know any standard, but you might think:

At the first approach, the user can manually change this property or delete it. However, the second approach is that you would protect the cells on the sheet, which, if I remember correctly, will introduce some problems if you want to sort any data on this sheet.

0
source

I had a similar problem (how to determine Excel version from VSTO code). I found your question while searching for a solution. The Version property of the Excel application object worked for me. From inside the sheet:

 Me.Application.Version 

or maybe depending on where you are on

 Globals.ThisWorkbook.Application.Version 

In any case, the value is "11.0" for Excel 2003 and "12.0" for 2007.

However, when re-reading your problem, you need to know the version that created the book. You can try Workbook.CalculationVersion , which "Gets a number that indicates the Excel version that the last workbook was completely recounted. The rightmost four digits are the version number of the minor calculator number, and the remaining digits (left) are the main version of Microsoft Office Excel." according to http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.calculationversion.aspx

0
source

Source: https://habr.com/ru/post/1302399/


All Articles