近期因为项目需要,写了许多word2003编程的东东.有时候遇到难题想查sdk说明,很难找到中文解释,对于e文不好的我来说,简直是天书.想必很多人多有感慨.
下面列出内容是一些常用的内容说明,希望对大家有帮助.
引用部分:
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using Microsoft.Office;
- using Microsoft.Office.Core;
- using Microsoft.Office.Interop;
- using Microsoft.Office.Interop.Word;
打开word2003文档,项目中的文档模板实际是doc的文档,dot的很不好用.
做doc文档模板的时候不要用空格留空白,使用段落缩进的方式.标签的添加等文档格式完全编辑好再添加.
对于要预留空白的内容,通过插入1个只有1个单元格(无边框)的方式来进行.这样保证单元格以后内容位置固定,不会因为插入了文字内容而移动位置,这队固定格式公文很有好处.
- #region 打开word模板和word文件
-
- public static void OpenWordDot()
- {
-
- }
-
- private void OpenWordDoc(string FileName, ref Microsoft.Office.Interop.Word.Document wDoc, ref Microsoft.Office.Interop.Word.Application WApp)
- {
- if (FileName == "") return;
- Microsoft.Office.Interop.Word.Document thisDocument = null;
- Microsoft.Office.Interop.Word.FormFields formFields = null;
- Microsoft.Office.Interop.Word.Application thisApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
- thisApplication.Visible = true;
- thisApplication.Caption = "";
- thisApplication.Options.CheckSpellingAsYouType = false;
- thisApplication.Options.CheckGrammarAsYouType = false;
-
- Object filename = FileName;
- Object ConfirmConversions = false;
- Object ReadOnly = true;
- Object AddToRecentFiles = false;
-
- Object PasswordDocument = System.Type.Missing;
- Object PasswordTemplate = System.Type.Missing;
- Object Revert = System.Type.Missing;
- Object WritePasswordDocument = System.Type.Missing;
- Object WritePasswordTemplate = System.Type.Missing;
- Object Format = System.Type.Missing;
- Object Encoding = System.Type.Missing;
- Object Visible = System.Type.Missing;
- Object OpenAndRepair = System.Type.Missing;
- Object DocumentDirection = System.Type.Missing;
- Object NoEncodingDialog = System.Type.Missing;
- Object XMLTransform = System.Type.Missing;
-
- try
- {
- Microsoft.Office.Interop.Word.Document wordDoc =
- thisApplication.Documents.Open(ref filename, ref ConfirmConversions,
- ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
- ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
- ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,
- ref NoEncodingDialog, ref XMLTransform);
-
- thisDocument = wordDoc;
- wDoc = wordDoc;
- WApp = thisApplication;
- formFields = wordDoc.FormFields;
- }
- catch (Exception ex)
- {
-
- }
-
- }
-
- #endregion
阅读(1352) | 评论(0) | 转发(0) |