ASP.NET Forums
首页 搜索 用户列表 FAQ 注册 登录  
ASP.NET Forums » .Net 专区 » 英文原稿 » Developing Word Application using C# & DSO Framer
  Developing Word Application using C# & DSO Framer
帖子发起人: wy_rover   发起时间: 2004-8-30 10:59 PM   回复数: 0
« 上一主题 下一主题 »
楼主
  2004-8-30, 10:59 PM
wy_rover 离线,最后访问时间: 3/26/2005 7:22:54 PM wy_rover

发帖数前25位

排长
等级: 排长
注册: 2004年8月7日
积分: 139
精华: 0
发贴: 99
Developing Word Application using C# & DSO Framer
 
Developing Word Application using C# & DSO Framer
By Naveen K S
 
Article Posted: January 19, 2004
 
Introduction
 
This article explains how to display MS Word document programmatically using C# on windows or web form using DSO Framer Active-X control.
 
The examples demonstrate how to automate the following activities:
 
Referencing DSO Framer Active-X control on form
Starting Word
Creating a new document
 
Background
 
Automation is a process that allows applications to control other application for e.g. application developed using Visual Basic .NET or C# can programmatically control other applications. The automation process can be performed through the Object Model of the application which is controlled. Word exposes this programmatic functionality through an object model library. The object model is a collection of classes and methods that serve as counterparts to the logical components of Word. Automation to Word allows you to perform actions such as creating & opening documents, adding text to documents, saving documents in different formats, handling e-mail, mail merge, and formatting documents and much more. With Word and other Microsoft Office applications, nearly all of the functionalities which you would perform manually through the user interface are available to control through programmatically by using automation. You would find various objects such as Application, Document, Paragraph, Range etc., each of which contain the functionality of that component in Word.
 
You could invoke word document as document in word application or you could have a DSO Framer Active-X control on your form to host word document. DSO Framer Active-X control acts as an ActiveX document container for hosting Office documents (including Microsoft Word, Microsoft Excel, Microsoft PowerPoint, Microsoft Project, and Microsoft Visio documents) in a custom form or Web page. The control (Dsoframer.ocx) is lightweight and flexible, and gives developers new possibilities for using Office in a custom solution. You can find more information on DSO Framer Active-X with source code at
 
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q311/7/65.asp&NoWebContent=1
 
Steps
 
1. Download DSO Framer from above link and register DSOFramer.ocx into system directory using regsvr32 command.
  C:\\WINNT\System32\regsvr32 Dsoframer.ocx
2. On successful registration you would get message dialog.
3. Add DSO Framer Active-X control on your form through customize toolbox window as shown below.
 
4. Drag and drop DSO from toolbox on your form and resize as per requirement.
5. Now add reference for Word Object Library 11.0 from add reference on solution explorer. Here I am using Word 2003, so object library version is 11.0. See figure
 
6. You can see all added reference on solution explorer as shown in figure. Two reference has been added for DSO framer (brown circle) and three libraries for Office & Word (red circle).
 
7. Define a variable for word document in public section of form as
 
public Word.Document oDoc;
8. Add a button to form and “Launch Word” as its text, on click event it would open a new word document.
9. Add following code for button click event
 
private void button1_Click(object sender, System.EventArgs e)
{
     //Remove DSO Title Bar and create a new Word document
     axFramerControl1.Titlebar = false;
     axFramerControl1.CreateNew("Word.Document");
     axFramerControl1.Activate();
     //Invoke Word properties
     oDoc = (Word.Document)axFramerControl1.ActiveDocument;
     oDoc.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView;
     oDoc.ActiveWindow.DisplayRulers = false;
     oDoc.ActiveWindow.DisplayScreenTips = false;
     oDoc.ActiveWindow.DisplayHorizontalScrollBar = false;
     oDoc.ActiveWindow.DisplayVerticalRuler = false;
     oDoc.ActiveWindow.DisplayVerticalScrollBar = true;
}
10. Now you can add text, format it, send mail do all functionalities.
11. You can control all word functionalities to be made available or unavailable programmatically through code with all available objects, properties & Methods of word.
 
Conclusion
 
You can play around with all objects, properties and methods of word to control it programmatically through your code.

IP 地址: 已登录   来自: 已登录    返回顶部
 第 1 页 总共 1 页 [共有 1 条记录]
ASP.NET Forums » .Net 专区 » 英文原稿 » Developing Word Application using C# & DSO Framer

友情链接: hiDotNet官方论坛 | hiDotNet知识库 | 其它友情链接

Asp.Net Forums version: 2.5.2725
(C)Copyright 2004-2007, hiDotNet.com. All Rights Reserved.
意见反馈 | 关于我们

Powered by Community Server :: Forums 中文本地化: hiDotNet.com