Chinaunix首页 | 论坛 | 博客
  • 博客访问: 512274
  • 博文数量: 60
  • 博客积分: 1445
  • 博客等级: 上尉
  • 技术积分: 507
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-14 19:15
文章分类

全部博文(60)

文章存档

2012年(1)

2011年(7)

2010年(52)

我的朋友

分类: C/C++

2010-07-12 14:01:40

近期因为项目需要,写了许多word2003编程的东东.有时候遇到难题想查sdk说明,很难找到中文解释,对于e文不好的我来说,简直是天书.想必很多人多有感慨.
    下面列出内容是一些常用的内容说明,希望对大家有帮助.

引用部分:

 

  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Web;  
  5. using System.Web.Security;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. using System.Web.UI.WebControls.WebParts;  
  9. using System.Web.UI.HtmlControls;  
  10. using Microsoft.Office;  
  11. using Microsoft.Office.Core;  
  12. using Microsoft.Office.Interop;  
  13. using Microsoft.Office.Interop.Word;  

打开word2003文档,项目中的文档模板实际是doc的文档,dot的很不好用.
做doc文档模板的时候不要用空格留空白,使用段落缩进的方式.标签的添加等文档格式完全编辑好再添加.
对于要预留空白的内容,通过插入1个只有1个单元格(无边框)的方式来进行.这样保证单元格以后内容位置固定,不会因为插入了文字内容而移动位置,这队固定格式公文很有好处.

  1. #region 打开word模板和word文件  
  2.   
  3.         public static void OpenWordDot()  
  4.         {  
  5.   
  6.         }  
  7.   
  8.         private void OpenWordDoc(string FileName, ref Microsoft.Office.Interop.Word.Document wDoc, ref  Microsoft.Office.Interop.Word.Application WApp)  
  9.         {  
  10.             if (FileName == ""return;  
  11.             Microsoft.Office.Interop.Word.Document thisDocument = null;  
  12.             Microsoft.Office.Interop.Word.FormFields formFields = null;  
  13.             Microsoft.Office.Interop.Word.Application thisApplication = new Microsoft.Office.Interop.Word.ApplicationClass();  
  14.             thisApplication.Visible = true;  
  15.             thisApplication.Caption = "";  
  16.             thisApplication.Options.CheckSpellingAsYouType = false;  
  17.             thisApplication.Options.CheckGrammarAsYouType = false;  
  18.   
  19.             Object filename = FileName;  
  20.             Object ConfirmConversions = false;  
  21.             Object ReadOnly = true;  
  22.             Object AddToRecentFiles = false;  
  23.   
  24.             Object PasswordDocument = System.Type.Missing;  
  25.             Object PasswordTemplate = System.Type.Missing;  
  26.             Object Revert = System.Type.Missing;  
  27.             Object WritePasswordDocument = System.Type.Missing;  
  28.             Object WritePasswordTemplate = System.Type.Missing;  
  29.             Object Format = System.Type.Missing;  
  30.             Object Encoding = System.Type.Missing;  
  31.             Object Visible = System.Type.Missing;  
  32.             Object OpenAndRepair = System.Type.Missing;  
  33.             Object DocumentDirection = System.Type.Missing;  
  34.             Object NoEncodingDialog = System.Type.Missing;  
  35.             Object XMLTransform = System.Type.Missing;  
  36.   
  37.             try  
  38.             {  
  39.                 Microsoft.Office.Interop.Word.Document wordDoc =  
  40.                  thisApplication.Documents.Open(ref filename, ref ConfirmConversions,  
  41.                  ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,  
  42.                  ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,  
  43.                  ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,  
  44.                  ref NoEncodingDialog, ref XMLTransform);  
  45.   
  46.                 thisDocument = wordDoc;  
  47.                 wDoc = wordDoc;  
  48.                 WApp = thisApplication;  
  49.                 formFields = wordDoc.FormFields;  
  50.             }  
  51.             catch (Exception ex)  
  52.             {  
  53.                   
  54.             }  
  55.   
  56.         }  
  57.  
  58.         #endregion  


阅读(1318) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~