using the actions pane, host controls, and smart tags donald drake development manager visual studio...

45
Using the Actions Using the Actions Pane, Host Controls, Pane, Host Controls, and Smart Tags and Smart Tags Donald Drake Donald Drake Development Manager Development Manager Visual Studio Tools for Office Visual Studio Tools for Office

Upload: tobias-johns

Post on 28-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Using the Actions Pane, Using the Actions Pane, Host Controls, and Smart Host Controls, and Smart TagsTags

Donald DrakeDonald DrakeDevelopment ManagerDevelopment ManagerVisual Studio Tools for OfficeVisual Studio Tools for Office

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Actions Pane OverviewActions Pane Overview

Enables contextual UI complementary Enables contextual UI complementary to the documentto the document

Flexible way of designing custom UIFlexible way of designing custom UI

Addresses UI layout challengesAddresses UI layout challenges

Plugs naturally into Office UIPlugs naturally into Office UI

Acts like a toolbar: floating or dockedActs like a toolbar: floating or docked

Actions Pane Technology OverviewActions Pane Technology Overview

Smart Document SDKSmart Document SDK Actions Panes (VSTO)Actions Panes (VSTO)

Requires Requires ISmartDocument ISmartDocument interface implementationinterface implementation

Not required. VSTO Not required. VSTO takes care of this takes care of this implementation for youimplementation for you

Requires XML expansion Requires XML expansion packspacks

Not required. VSTO Not required. VSTO takes care of this for youtakes care of this for you

Requires XML-based Requires XML-based documentdocument

Optional. You can create Optional. You can create a solution that is not a solution that is not based on XMLbased on XML

Supports ActiveX Supports ActiveX controlscontrols

Supports Windows Supports Windows Forms controlsForms controls

Adding an Actions PaneAdding an Actions Pane

Actions pane becomes visible when Actions pane becomes visible when you add a control to ityou add a control to it

Use Windows Forms controls, custom Use Windows Forms controls, custom User controls or Actions Pane controlsUser controls or Actions Pane controls

Actions Pane control gives a nice Actions Pane control gives a nice design-time experiencedesign-time experience

Globals.ThisWorkbook.ActionsPane.Controls.Add(New DateTimePicker)

Create a SimpleCreate a SimpleActions PaneActions Pane

Managing LayoutManaging Layout

Add multiple controls to the actions paneAdd multiple controls to the actions pane

Change the stack order of controls on the Change the stack order of controls on the actions pane when the user changes the actions pane when the user changes the orientation of the actions paneorientation of the actions pane

Programmatically change the orientation Programmatically change the orientation of the actions paneof the actions pane

Show and hide controls on the actions Show and hide controls on the actions pane pane

Show and hide the actions paneShow and hide the actions pane

Managing Control Managing Control LayoutLayout

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host ControlsHost Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

What is a Host Control?What is a Host Control?

A type that extends the host application A type that extends the host application (Word or Excel) Object Model to (Word or Excel) Object Model to provide provide new functionalitynew functionality or to or to enhance programmabilityenhance programmability..

Host Control FeaturesHost Control Features

Extends Office object model

Properties and methods

Richer event model

WinForms style data binding

Simplifies programming model

Automating Excel Automating Excel without Host Controlswithout Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in ExcelHost Controls in Excel

ChartChart

ListObjectListObject

NamedRangeNamedRange

XMLMappedRangeXMLMappedRange

Creating Excel Host Creating Excel Host ControlsControls

Drag and drop host control from Visual Drag and drop host control from Visual Studio ToolboxStudio Toolbox

Drag and drop a data element from the Data Drag and drop a data element from the Data Sources window that is mapped to a host Sources window that is mapped to a host controlcontrol

Use menus to add the underlying Excel Use menus to add the underlying Excel object to a document. The VSTO designer object to a document. The VSTO designer creates a host control to wrap the Excel creates a host control to wrap the Excel object being created. object being created.

XMLMappedRange controlsXMLMappedRange controls

Use the XML Source task paneUse the XML Source task pane

Using Excel Host Using Excel Host ControlsControls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Host Controls in WordHost Controls in Word

BookmarkBookmark

XMLNodeXMLNode

Creating Word Host Creating Word Host ControlsControls

Bookmark controlsBookmark controls

Drag/drop from ToolboxDrag/drop from Toolbox

Drag/drop from Data Sources Drag/drop from Data Sources windowwindow

Click Bookmark on the Insert menuClick Bookmark on the Insert menu

XMLNode controlsXMLNode controls

Use the XML Structure task paneUse the XML Structure task pane

Using Bookmark Host Using Bookmark Host ControlsControls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

Dynamic ControlsDynamic Controls

A control (managed or host control) A control (managed or host control) added to the Word or Excel document added to the Word or Excel document at runtime at runtime Enable you to create interactive Enable you to create interactive documents because you can add documents because you can add controls in response to user input or controls in response to user input or eventsevents

Managing Dynamic ControlsManaging Dynamic ControlsControls collection references static and Controls collection references static and dynamic controlsdynamic controlsCreate dynamic controls with methods of the Create dynamic controls with methods of the Controls collectionControls collection

Managed controls: AddButton, Managed controls: AddButton, AddTextBoxAddTextBoxHost controls: AddBookmark, Host controls: AddBookmark, AddListObject, AddNamedRangeAddListObject, AddNamedRangeYou cannot dynamically create XMLNode You cannot dynamically create XMLNode or XMLMappedRanges controlsor XMLMappedRanges controls

You can only remove dynamic controls (not You can only remove dynamic controls (not static) from the Controls collection at static) from the Controls collection at runtime runtime

Dynamic Controls and Dynamic Controls and Persistence Persistence

Dynamic controls are not persistedDynamic controls are not persisted

Underlying data in dynamic Underlying data in dynamic hosthost controls controls may be persisted.may be persisted.For example:For example:

If you remove an Excel NamedRange If you remove an Excel NamedRange control, the data in the cells remainscontrol, the data in the cells remains

If you delete a Bookmark control, the If you delete a Bookmark control, the contents of the bookmark remainscontents of the bookmark remains

Dynamic Host ControlsDynamic Host Controls

AgendaAgenda

Actions Pane Actions Pane OverviewOverview

Managing Control LayoutManaging Control Layout

Host Controls Host Controls OverviewOverview

Excel Host ControlsExcel Host Controls

Word Host ControlsWord Host Controls

Dynamic ControlsDynamic Controls

Smart TagsSmart Tags

SmartTags OverviewSmartTags Overview

What is a SmartTag?What is a SmartTag?Context Based ActionsContext Based Actions

What makes up a SmartTag?What makes up a SmartTag?Recognized TextRecognized Text

ActionsActions

Developing VSTO SmartTagsDeveloping VSTO SmartTags

Steps:Steps:

1)1) Create a SmartTag instanceCreate a SmartTag instance

2)2) Add strings to recognizeAdd strings to recognize

3)3) Add actionsAdd actions

4)4) Register SmartTag object with the Register SmartTag object with the documentdocument

Create a SmartTag InstanceCreate a SmartTag Instance

Create a SmartTag objectCreate a SmartTag objectExcel: Excel: Microsoft.Office.Tools.Excel.SmartTagMicrosoft.Office.Tools.Excel.SmartTag

Word: Word: Microsoft.Office.Tools.Word.SmartTagMicrosoft.Office.Tools.Word.SmartTag

Stores RecognizersStores RecognizersTerms Collection PropertyTerms Collection Property

Expressions Collection PropertyExpressions Collection Property

Stores ActionsStores ActionsActions Array PropertyActions Array Property

Create a SmartTag InstanceCreate a SmartTag Instance

Constructor ParametersConstructor ParametersSmartTag typeSmartTag type

CaptionCaption

SmartTag myTag = new SmartTag

("www.example.com#prodInfo",

"Product Info");

Add Strings to Recognize Add Strings to Recognize

Terms CollectionTerms CollectionStatic stringsStatic strings

Expressions CollectionExpressions CollectionRegular expressionsRegular expressions

myTag.Terms.Add(“Tofu”);

myTag.Expressions.Add

(new Regex(“[A-Z]{1}[0-9]{3}”));

Add ActionsAdd Actions

Create Action objectsCreate Action objectsExcel: Microsoft.Office.Tools.Excel.ActionExcel: Microsoft.Office.Tools.Excel.Action

Word: Microsoft.Office.Tools.Word.ActionWord: Microsoft.Office.Tools.Word.Action

Set Caption propertySet Caption propertyAction action1 = new Action("Reorder");myTag.Actions = new Action[] {action1} ;

Add Action Click EventAdd Action Click Event

Create Click event for actionCreate Click event for action

action1.Click += newActionClickEventHandler(action1_Click);

void action1_Click(object sender, Microsoft.Office.Tools.Excel.

ActionEventArgs e){

// TODO: Add Event Handler Code}

Register SmartTag with Register SmartTag with DocumentDocument

VstoSmartTagsCollectionVstoSmartTagsCollectionExcel: ThisWorkbook classExcel: ThisWorkbook class

Word: ThisDocument classWord: ThisDocument class

// In ThisWorkbook.csthis.VstoSmartTags.Add(myTag);

Smart TagsSmart Tags

SummarySummaryCreate actions pane with one line of codeCreate actions pane with one line of codeManage actions pane control layoutManage actions pane control layoutHost Controls give you the ability to rapidly Host Controls give you the ability to rapidly develop powerful VSTO applications by develop powerful VSTO applications by providing:providing:

Simplified programming model Simplified programming model Rich event modelRich event modelWinforms style DatabindingWinforms style Databinding

Add controls to documents either at design Add controls to documents either at design time or run timetime or run timeUse SmartTags to augment your UI based Use SmartTags to augment your UI based on document contenton document content

Next StepsNext Steps

Participate in our newsgroups and web forumParticipate in our newsgroups and web forummicrosoft.public.vsnet.vstools.officemicrosoft.public.vsnet.vstools.office

microsoft.public.officedevmicrosoft.public.officedev

microsoft.public.office.developermicrosoft.public.office.developer

http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16ForumID=16

Participate in VSTO-related blogsParticipate in VSTO-related blogsTeam blog: Team blog: http://blogs.msdn.com/vsto2http://blogs.msdn.com/vsto2

VSTO MVP Chris Kunicki’s blog: VSTO MVP Chris Kunicki’s blog: http://www.officezealot.com/VSTO/http://www.officezealot.com/VSTO/

Attend a free chat or webcastAttend a free chat or webcasthttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx

For More InformationFor More Information

Visit the VSTO sections of these MSDNVisit the VSTO sections of these MSDN®® Developer CentersDeveloper Centers

Office Developer CenterOffice Developer Center http://msdn.microsoft.com/office/understanding/http://msdn.microsoft.com/office/understanding/vsto/default.aspxvsto/default.aspx

Smart Client Developer CenterSmart Client Developer Center http://msdn.microsoft.com/smartclient/understanhttp://msdn.microsoft.com/smartclient/understanding/vsto/default.aspxding/vsto/default.aspx

VSTO Help documentation on MSDNVSTO Help documentation on MSDN

http://msdn2.microsoft.com/library/d2tx7z6d(en-http://msdn2.microsoft.com/library/d2tx7z6d(en-us,vs.80).aspxus,vs.80).aspx

Questions?Questions?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Why extend Office OM?Why extend Office OM?

• But the types exposed lack some features that .NET developers take for granted in Winforms

• To utilize the power of Word and Excel, we need to present most of the data in the document, not in Winform controls

• Word and Excel Object Models expose types for this purpose

XMLMappedRange Host XMLMappedRange Host ControlControl

Mapping cells in an Excel worksheet to an Mapping cells in an Excel worksheet to an XML Schema is a feature provided by Excel.XML Schema is a feature provided by Excel.

When you map an Excel worksheet to XML, When you map an Excel worksheet to XML, VSTO creates instances of VSTO creates instances of XMLMappedRange host controls for each XMLMappedRange host controls for each mapped cellmapped cell

Almost same as the NamedRange Host Almost same as the NamedRange Host Control.Control.

Provides you direct programmatic access to Provides you direct programmatic access to the Range that is mapped to XML. the Range that is mapped to XML.

Adding Bookmark at Run Adding Bookmark at Run TimeTimeprivate void bookmarkExample(){ Microsoft.Office.Tools.Word.Bookmark bookmark1 = this.Controls.AddBookmark( this.Paragraphs[1].Range,

“bookmark1”); bookmark1.Text = “Sample bookmark text.”;}

Outlook SolutionsOutlook Solutions

Add custom menu with buttons to Add custom menu with buttons to standard menu barstandard menu bar

Display custom formsDisplay custom forms

Add custom controls to custom formsAdd custom controls to custom forms

Outlook Task Add-in Outlook Task Add-in SolutionSolution