zmhere

 

public partial class ThisDocument
    
{
        
private Office.CommandBarPopup MenuBarItem;
        
// Arbitrary Tag value for new menu item.
        private const string MENU_TAG = "DEMO_CODE";
        
Manipulate Menubar
        
private Office.CommandBarButton CreateButton(string Caption)
        
{
            Office.CommandBarButton cbb 
= null;
            
try
            
{
                cbb 
= (Office.CommandBarButton)this.MenuBarItem.Controls.Add(Office.MsoControlType.msoControlButton, missing,missing, missing, true);
                cbb.Caption 
= Caption;
                cbb.Visible 
= true;
            }

            
catch (Exception ex)
            
{
                MessageBox.Show(ex.Message,ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            
return cbb;
        }


        
private void RemoveDemoMenuItem()
        
{
            
try
            
{
                Office.CommandBar MainMenuBar 
= ThisApplication.CommandBars["Menu Bar"];

                
// Need to locate the custom menu item again.
                this.MenuBarItem = (Office.CommandBarPopup)MainMenuBar.FindControl(
                  Office.MsoControlType.msoControlPopup, missing, MENU_TAG, missing, missing);
                
this.MenuBarItem.Delete(missing);
            }

            
catch
            
{
                
// if there\'s an error, don\'t complain.
            }

        }


        
public void ResetDemoText()
        
{
            
try
            
{
                
string docText = @"Visual Studio Tools for the Microsoft Office System"+Environment.NewLine+@"在创建收集、分析、处理或提供信息的业务应用程序时,可以利用 Microsoft Office 2003 的强大功能。通过将功能丰富的客户端应用程序集成到业务解决方案中,不但可以使用每个桌面都提供的功能,而且最终用户也可以使用熟悉的工作环境。" + Environment.NewLine + @"Microsoft Visual Studio 2005 Tools for the Microsoft Office System 可以帮助您利用 Microsoft .NET Framework 2.0 版 中的效率增强,使用 Visual Basic 和 Visual C# 扩展 Microsoft Office Word 2003、Microsoft Office Excel 2003 和 Microsoft Office Outlook 2003。工具中包含新的 Visual Studio 项目,用于帮助您为 Office 应用程序创建自定义功能。" + Environment.NewLine + @"有关 Office 可编程技术的最新信息,请参见 Microsoft Office 开发人员中心 (http://www.microsoft.com/china/office/default.mspx)。该站点包含一些链接,指向技术文章、代码示例、下载、社区信息、支持以及有关生成自定义 Office 解决方案的其他 MSDN 文档。" + Environment.NewLine + @"本节内容:" + Environment.NewLine + @"入门 (Visual Studio Tools for Office) " + Environment.NewLine + @"提供一些链接,指向有关安装 Visual Studio Tools for Office、如何开始创建解决方案以及从早期版本以来发生了哪些更改的信息。" + Environment.NewLine + @"Visual Studio Tools for Office 解决方案的结构 " + Environment.NewLine + @"提供一些链接,指向有关 Visual Studio Tools for Office 解决方案如何工作的信息(包括有关自定义文档属性、数据模型以及运行时存储控件的信息)。" + Environment.NewLine + @"升级 Office 解决方案" + Environment.NewLine + @"包含一些链接,指向有关升级过程、升级项目中必须做的更改以及 Microsoft .NET Framework 并行安装的注意事项的信息。" + Environment.NewLine + @"在 Visual Studio 中创建 Office 解决方案 " + Environment.NewLine + @"提供一些链接,指向有关创建 Office 解决方案以及程序集在解决方案中的作用的信息。" + Environment.NewLine + @"编写 Word 和 Excel 应用程序" + Environment.NewLine + @"提供一些链接,指向有关在 Word 和 Excel 解决方案中使用托管代码的信息(包括自定义 Office 用户界面、在 Office 文档中使用控件和使用操作窗格)。" + Environment.NewLine + @"使用 Office 对象模型实现应用程序自动化 " + Environment.NewLine + @"提供一些链接,指向有关使用托管代码使 Office 解决方案自动化的信息。" + Environment.NewLine + @"Office 解决方案中的数据" + Environment.NewLine + @"提供一些链接,指向解释数据如何在 Office 解决方案中工作的主题(包括有关面向架构的编程、数据缓存和服务器端数据访问的信息)。" + Environment.NewLine + @"生成并调试 Office 项目" + Environment.NewLine + @"列出解释生成和调试 Visual Studio Tools for Office 项目和 Visual Studio 中其他类型的项目(如 Windows 窗体)之间的几处不同的主题。" + Environment.NewLine + @"Office 解决方案的疑难解答" + Environment.NewLine + @"提供一些链接,指向包含关于解决在使用 Visual Studio Tools for Office 创建 Office 解决方案时可能遇到的常见问题的提示的主题。" + Environment.NewLine + @"Office 解决方案中的安全性" + Environment.NewLine + @"包含解释 Visual Studio Tools for Office 解决方案如何合并 Microsoft .NET Framework 提供的安全功能的主题。" + Environment.NewLine + @"部署 Office 解决方案" + Environment.NewLine + @"提供一些链接,指向有关如何使 Office 解决方案可供用户使用以及在选择部署方法和设置安全性时要考虑的主要问题的信息。" + Environment.NewLine + @"Visual Studio Tools for Office 中的项目扩展性 " + Environment.NewLine + @"列出提供有关 Visual Studio Tools for Office 项目中的自动化和扩展性的信息的主题,这些信息可以用来使集成开发环境中的任务自动化以及扩展项目类型和项目项。" + "\n\r" + Environment.NewLine + @"Office 开发示例和演练" + Environment.NewLine + @"提供一些链接,指向示例应用程序和提供关于执行常见任务的分步指导的主题。" ;

                Object start 
= 0;
                Object end 
= this.Characters.Count;
                Object styleName 
= "lorem";
                Word.Range rng 
= this.Range(ref start, ref end);
                rng.Text 
= docText;
                rng.set_Style(
ref styleName);
            }

            
catch
            
{
                
// do nothing
            }

        }


        
private void ThisDocument_Startup(object sender, System.EventArgs e)
        
{
            InitMenuBarItems();
            ResetDemoText();
        }


        
private void ThisDocument_Shutdown(object sender, System.EventArgs e)
        
{
            RemoveDemoMenuItem();
        }

        
ActiveWindow
        
Application Caption
        
CapsLock
        
DisplayAlerts
        
DisplayStatusBar
        
FileSearch
        
Path
        
Options

        
UserName

        
Visible

        
CheckSpelling

        
Help

        
Move and Resize
        
Quit
        
SendFax

        
Using the Built-In Dialog Boxes in Word
        
Display
        
Execute

        
Modifying Dialog Values

        
Creating a New Word Document
        
Opening an Existing Document

        
Saving Documents

        
SaveAs
        
Closing Documents
        
Looping Through the Documents Collection
        
Using the Type Property
        
Home and End Key Methods
        
Arrow Key Methods
        
MoveUp and MoveDown methods
        
Move Method
        
Inserting Text
        
Range Object Range Object
        
The Bookmark Object Bookmark

        
Searching and Replacing Text

        
public void FindInRange()
        
{
            
// Set the second paragraph as the search range
            Word.Range rng = this.Paragraphs[2].Range;
            Word.Find fnd 
= rng.Find;

            
// Clear existing formatting
            fnd.ClearFormatting();

            
// Execute the search
            fnd.Text = "Office";
            
if (ExecuteFind(fnd))
            
{
                MessageBox.Show(
"找到了“Office”""在区域中查找");
            }

            
else
            
{
                MessageBox.Show(
"没有找到“Office”""在区域中查找");
            }


            
// The word faucibus is displayed if the
            
// search succeeds; paragraph 2 is displayed
            
// if the search fails.
            rng.Select();
        }

        
Looping through Found Items
        
Replacing Text
        
Restoring the User\'s Selection After a Search
        
Printing
        
Creating Word Tables
        
Working with a Table Object
        
The Cells Collection
        
Rows and Columns
        
DistributeWidth method to make them all the same width:
        
Pulling it all Together
        
VSTO Designer generated code

        
private void ThisDocument_BeforeClose(object sender, System.ComponentModel.CancelEventArgs e)
        
{
            
        }

    }

分类:

技术点:

相关文章:

  • 2023-01-25
  • 2021-11-23
  • 2021-05-19
  • 2022-12-23
  • 2022-01-02
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-11-18
  • 2021-10-24
  • 2022-12-23
  • 2021-08-13
相关资源
相似解决方案