日期:2014-05-17  浏览次数:20450 次

.net下启动word的一系列问题!!是怎么回事呢?
Net 下启动Word
在服务器端需要做的配置操作
按如下方法做:
C# 动态生成word文档(我安装的是Office2007)。

1,添加引用->.NET->Microsoft.Office.Interop.Word 12.0
2,添加如下类
public class BiultReportForm
  {
  /// <SUMMARY></SUMMARY>  
  /// word 应用对象  
  ///  
  private Microsoft.Office.Interop.Word.Application _wordApplication;
  /// <SUMMARY></SUMMARY>  
  /// word 文件对象  
  ///
  private Microsoft.Office.Interop.Word.Document _wordDocument;  
  /// <SUMMARY></SUMMARY>
  /// 创建文档  
  ///  
  public void CreateAWord()  
  {  
  //实例化word应用对象  
  this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();  
  Object myNothing = System.Reflection.Missing.Value;  
   
  this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);  
  }
  /// <SUMMARY></SUMMARY>
  /// 添加页眉  
  ///  
  /// <PARAM name="pPageHeader" />  
  public void SetPageHeader(string pPageHeader)  
  {  
  //添加页眉  
  this._wordApplication.ActiveWindow.View.Type =Microsoft .Office .Interop .Word.WdViewType.wdOutlineView;  
  this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;  
  this._wordApplication.ActiveWindow.ActivePane.Selection.InsertAfter(pPageHeader);
  //设置中间对齐  
  this._wordApplication.Selection.ParagraphFormat.Alignment =Microsoft .Office .Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;  
  //跳出页眉设置  
  this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;  
  }  
  /// <SUMMARY></SUMMARY>  
  /// 插入文字  
  ///  
  /// <PARAM name="pText" />文本信息  
  /// <PARAM name="pFontSize" />字体打小 网管网bitsCN.com 
  /// <PARAM name="pFontColor" />字体颜色  
  /// <PARAM name="pFontBold" />字体粗体  
  /// <PARAM name="ptextAlignment" />方向  
  public void InsertText(string pText, int pFontSize, Microsoft.Office.Interop.Word.WdColor pFontColor, int pFontBold, Microsoft.Office.Interop.Word.WdParagraphAlignment ptextAlignment)  
  {  
  //设置字体样式以及方向  
  this._wordApplication.Application.Selection.Font.Size = pFontSize;  
  this._wordApplication.Application.Selection.Font.Bold = pFontBold;  
  this._wordApplication.Application.Selection.Font.Color= pFontColor;
  this._wordApplication.Application.Selection.ParagraphFormat.Alignment = ptextAlignment;  
  this._wordApplication.Application.Selection.TypeText(pText);  
  }
  /// <SUMMARY></SUMMARY>  
  /// 换行  
  ///  
  public void NewLine(