Generally, the customer's Computer Major level is not high, but some office level is quite good, especially the Excel operation is very skilled. Therefore, if you can integrate some features of the product into the office, it will have a good foundation.
However, due to the different versions of the office installed by the customer, the deployment of the vsto project is particularly important and many issues need to be considered.
Download test code
All tests in this seriesCodeAll of them passed the test on Visual Studio 2010 ultimate SP1 + office 2010 Professional plus x64 SP1
Generally, there are the following situations:
1. Different Office versions
At present, there are mainly Office 2003, Office 2007, and office 2010.
2. 32-bit and 64-bit Office
Currently, only office 2010 supports 64-bit versions.
3. 32-bit office is installed on a 64-bit operating system.
Currently, many new laptops are currently available, most of which are win7 64-bit and 32-bit Office 2007 and 2010 are installed.
In addition, different vsto projects are deployed in different ways. There are the following vsto project types:
1. Document Type
Such as Word document and Excel Workbook
2. addin type
Such as Word addin and Excel addin
3. Shared addin type
4. Excel custom formula type
Next we will discuss the corresponding deployment solutions one by one.
Note that vs2010 only supports Office 2007 and office 2010. To develop a vsto project based on Office 2003, use vs2005 and vs2008.
1. The project to be deployed is of the document type.
1.1. Use vs 2010 to create an Excel Workbook project:
1.2. Select office format .xlsx:
1.3 place a button in a worksheet:
1.4. A dialog box is displayed in the click event:
1.5. When F5 runs, the Excel file is opened. click the button to display the expected information:
1.6. the following files are generated in the DEBUG directory:
As it is a document type, it is normal to generate an Excel Workbook. There is a file in the. vsto format that is rarely seen as the installation file during vsto project deployment.
The. vsto file is actually an XML file. Open it in a text editor and you can see the specific content:
Contains the specific information of the vsto project, such as. Net runtime version, dependentProgramSet, digital signature, and other information. Do not manually modify this file.
. Net Runtime is 4.0, so the client must first install. NET Framework 4.0.
The default vsto open method is Visual Studio Tools for office execution engine:
This component is included When Visual Studio Tools for office is running. Therefore, to run the vsto program on the client, you must install Visual Studio Tools for office.
Visual Studio 2010 tools for office runtime can be found inHereDownload.
1.7. I used a virtual machine simulated client. After installing. Net 4.0 and office 2010, I can open. vsto:
1.8 After the installation is successful, you can open the Excel file in debug:
Note that after the document-type vsto project is installed, it is only valid for the published document (only for excel in debug) and does not affect other office files of the user. That is, the document-type project is not global.
1.9 In the control panel, you can uninstall the vsto project:
2. The project to be deployed is of the add in type.
2.1 create a word add in project:
2.2 Add a visual Ribbon:
2.3 Add a button to ribbon:
2.4. Click the pop-up dialog box:
2.5. After F5 is run, word is opened:
2.6. Some files will be generated in the DEBUG directory:
2.7. The client still needs to install. Net 4.0 and Visual Studio 2010 tools for office runtime to run the vsto project:
Note that the add in type is global. After installation, the add in type is included in any office document.
Iii. Shared addin type
Shared Addin is a plug-in that can be shared by multiple office documents, but it is generally developed for one Office document.
3.1 create a shared addin project:
3.2 here I select only for Excel:
3.3 set the loading attributes:
3.4 by default, there are two projects: one is the plug-in and the other is the MSI installation project:
Here we only talk about deployment. For details about how to develop related projects, refer to other materials.
Add a reference to system. Windows. forms, and then a dialog box will pop up in the onstartupcomplete event in connect. CS:
3.5 set the properties of the installation project:
Note that targetplatform does not have any CPU, so you need to compile an MSI Installation File for x86 and x64 respectively.
3.6 set the installation project to run the dependent components:
You can set the. NET Framework 4.0 as follows:
On the installation project properties page, you can set more running dependency components in prerequisites:
3.7 after the setup is complete, compile the installation project and generate the corresponding MSI installation package:
3.8 right-click the installation projectÀInstall:
After the installation is complete, open an Excel file and you will see our dialog box:
Iv. Excel custom formula type
The reason for taking out the Excel custom formula type separately is that the registration of the Excel custom formula is somewhat special, especially Excel 2010x64.
4.1 create a class library project:
4.2,Write addition, subtraction, multiplication, division, and four functionsComRegistration and anti-registration functions:
View code
UsingSystem;
UsingSystem. runtime. interopservices;
UsingMicrosoft. Win32;
NamespaceExceludf
{
[GUID (E72F44C7-DD4A-4FA2-BC32-4EA9925749DB")]
[Classinterface (classinterfacetype. autodual)]
[Comvisible ( true )]
Public class exceludf
{< br> Public int Add ( int , int B)
{< br> return A + B;
}
Public int subtract ( int , int B)
{< br> return A-B;
}
Public int multiply ( int , int B)
{< br> return A * B;
}
Public IntDivide (IntA,IntB)
{
ReturnA/B;
}
# RegionCom related
[Comregisterfunction]
Public StaticVoidRegisterfunction (type)
{
Registry. classesroot. createsubkey (getsubkeyname (type, "programmable" );
var key = registry. classesroot. opensubkey (getsubkeyname (type, "inprocserver32" ), true );
key. setvalue ( "" , environment. systemdirectory + @ "\ mscoree. DLL ", registryvaluekind. string );
}
[Comunregisterfunction]
Public Static VoidUnregisterfunction (type)
{
Registry. classesroot. deletesubkey (getsubkeyname (type,"Programmable"),False);
}
PrivateStaticStringGetsubkeyname (type,StringSubkeyname)
{
VaR S =New system. text. stringbuilder ();
S. append ( @ "CLSID \ {" );
S. append (type. guid. tostring (). toupper ();
S. append ( @ "}\" );
S. append (subkeyname);
return S. tostring ();
}< br> # endregion
}< br> / span>
4.3What I installed isExcel x64You must manually register the assembly of the custom formula.Build EventsThe batch processing script is automatically registered:
% Windir % \ Microsoft. NET \Framework64\ V4.0.30319 \ regasm/codebase "$ (targetpath )"
If yesExcel x86To register:
% Windir % \ Microsoft. NET \Framework\ V4.0.30319 \ regasm/codebase "$ (targetpath )"
Execute this batch processing script when deploying to the client.
In this way, the custom formula is automatically registered after each compilation is successful.
4.4In the generation manager, configureX64:
4.5InRibbonAdd the code to call the custom formula in the project:
UsingMicrosoft. Office. Tools. ribbon;
NamespaceExceladdin
{
Public Partial ClassRibbondemo
{
Private VoidRibbondemo_load (ObjectSender, ribbonuieventargs E)
{
}
Private VoidBtnadd_click (ObjectSender, ribboncontroleventargs E)
{
Globals. thisaddin. application. activecell. formula ="= Add ()";
}
private void btnsubtract_click ( Object sender, ribboncontroleventargs e)
{< br> globals. thisaddin. application. activecell. formula = "= subtract ()" ;
}
private void btnmultiply_click ( Object sender, ribboncontroleventargs e)
{< br> globals. thisaddin. application. activecell. formula = "= multiply ()" ;
}
private void btndivide_click ( Object sender, ribboncontroleventargs e)
{< br> globals. thisaddin. application. activecell. formula = "= divide ()" ;
}< BR >}< span style = "color: # 4b4b4b ">
4.6, ModifyRibbonProject Properties, SetExcelSet to the started extension:
4.7, Compile, run, will callExcelTo automatically load our plug-ins.Exceladdin:
4.8, Activation custom formula:
In 【DeveloperClick 【Add-ins], And then click 【Automation] Find the custom formula we have compiled ,【OK].
4.9At this timeExcelYou can use our formula.;
Summary:
1. If the customer uses Office 2003, use vs2008 for Development (. NET 3.5). If the customer uses Office 2007 or an updated version, use vs2010 for development. (. NET 4.0)
2. The general installation sequence is:
. NET Framework-> Visual Studio Tools for office RuntimeÀMSI or. vsto
3rd, it is best to uninstall the original version before installation. If .vstois out of law, you can use mage.exe to clear the cache and try to install it.
Execute the following command line: Mage-CC
Mage.exe is a small tool in the Windows SDK. After the Windows SDK is installed, it is located by default:
C: \ Program Files (x86) \ microsoft sdks \ windows \ XX \ binÀWindows x64
C: \ Program Files \ microsoft sdks \ windows \ XX \ binÀWindows x86
XX is the version number of the Windows SDK, such as v6.0a, v7.0a, and v7.1.
We recommend that you use the vsto client to install Office 2007 or the latest version, because vsto is customized for Office 2007 or the latest version. Office 2003 is difficult to adapt to the new architecture due to historical issues.
In this regard, we need to guide the customer. Although the customer is God, if we can persuade the customer to upgrade the office, it will have significant benefits for the user experience and the upgrade and maintenance at the end of the project.