HOW TO: Events from Office 2003 Web Components in Visual Studio .NET

zhaozj2021-02-16  106

Suitable

This task content

Summary

Steps for background modification and regeneration class packaging

SUMMARY This step-by-step guide describes how to modify the class packages of the Microsoft Office 2003 web component. It then introduces how to regenerate class packages so that you can manage their events in the application you created using Microsoft Visual Studio .NET.

By default, the class packages generated by Microsoft Visual Studio .NET do not allow the following Office 2003 web components:

Chart Spreadstered Pivot Pivot Table To process events of these components, you can modify the source code of the class package and recompile the code.

Back to top

Microsoft Visual Studio .NET generates one

Event listening program class, this class implements one

Event interface. Should

The event listening program class will be passed to Office Web Components (OWC). Subsequent, OWC call

Idispatch interface

QueryInterface method, not call

Event interface. However, the generated class

The IDispatch interface does not contain the scheduling identifier (DISPID).

To resolve this issue, you can use

ClassInterFaceType.none value marks the generated class to force Com Interop to the interface (not class)

Idispatch.

The IDispatch interface contains events DISPID.

Back to top

Steps to modify and regenerate classes

Start the Visual Studio .NET command prompt. In the command prompt, do the following:

Create a new directory called OWC11, then change to this directory: MD C: / OWC11CD C: / OWC11 Generates the source code for Microsoft Windows Forms (C # Language): AXIMP "C: / Program Files / Common Files / Microsoft Shared / Web Components / 11 / OWC11.DLL "/ source Delete Generated Graphic Axowc11.dll: del C: /owc11/adowc11.dll In Text Editor, Open" C: / OWC11 " /AXOWC11.CS. Add [ToolboxItem (TRUE) to the generated class of chart components, spreadsheet components, and PivotTable components, as shown in the following example: Chart Components [System.comPonentModel.ToolboxItem (True)]

Public class axchartspace: system.windows.forms.axhost {

...

} Spreadsheet components [system.componentmodel.toolboxItem (TRUE)]

Public class axspreadsheet: system.windows.forms.axhost {

...

} PivotTable Components [System.comPonentModel.ToolboxItem (TRUE)]

Public class Axpivottable: System.windows.Forms.Axhost {

...

} Tag event class as classInterfacePE.None, as shown below: Chart component [System.Runtime.InteropServices.classinterface

System.Runtime.InteropServices.classInterfacePe.none)]]

Public Class AxchartSpaceEventMulticaster: OWC11.ICHARTEVENTS {...

} Spreadsheet components [System.Runtime.InteropServices.classinterface

System.Runtime.InteropServices.classInterfacePe.none)]]

Public Class AxSpreadsheteTMulticaster: Owc11.ispreadsheteEventsink {

...

} PivotTable component [System.Runtime.InteropServices.classinterface

System.Runtime.InteropServices.classInterfacePe.none)]]

Public Class AxpivottableEventMulticaster: Owc11.ipivotconTrolevents {

...

} Save your changes to AXOWC11.CS. Under the Visual Studio .NET command prompt, do the following:

Add C: / Program Files / Microsoft.Net / Program Files / Microsoft.Net / Primary Interop Assemblies in your lib environment variable: set lib = c: / program files / microsoft.net / primary interop assembly;% PATH% from installing Microsoft Office 2003 GAC assemblies of replication and Microsoft.Office.Interop.OWC11.dll MSComCtl.dll: copy% windir% / assembly / GAC / Microsoft.Office.Interop.Owc11 / 11.0.0.0__71e9bce111e9429c / Microsoft.Office.Interop.Owc11 .dll COPY% WINDIR% / $ 10.0.4504.0__31bf3856ad364e35 / mscomctl.dll Compilation Source File AXOWC11.CS: CSC / T: library /r:Microsoft.Office.Interop.owc11.dll / r: AdoDB. DLL /R: MSDataSrc.dll /R: mscomctl.dll Axowc11.cs Note You will receive the following CS0108 error message:

The Keyword New Is Required

You can ignore this error. Start Visual Studio .NET. Add newly compiled "AxowC11.dll" to "Toolbox":

On the Tools menu, click Custom Toolbox (in Visual Studio .NET 2002) or click Add / Remove Toolbox items (in Visual Studio .NET 2003), then click ". Net Framework Component tab. On the ".NET Framework Components tab, click" Browse ". In the File Name text box, type C: /owc11/Axowc11.dll. Click "Open". Click OK to close the Custom Toolbox dialog. When you create a new Microsoft Visual Basic .NET project or a new Microsoft Visual C # .NET project, you will notice the "AxChartSpace" control, "AxPivottable" control in the "Toolbox" in the "Toolbox" tab. And "AxSpreadsheet" controls. These components can now be added to the form.

Back to top

For additional information about using the Visual Studio .NET Management Office XP Web Component event, click the article number below to view the article in the Microsoft Knowledge Base: 328275 How to: Handle Events for the Office Web Components in Visual Studio. Net

Back to top

转载请注明原文地址:https://www.9cbs.com/read-10339.html

New Post(0)