Office编程在dot Net环境中总结(Word生成表格报表篇) (二)

下面是HLCell对象 它的功能就像是Excel中对单元格的操作
代码
namespace WordReport.HLWord
{
     ///<summary>
     /// 表格对象 ,封装了Word。Cell的部分主要的功能
     ///</summary>
     public class HLCellClass:HLCell
     {
        
         private Word.Cell _Cell=null;
        
         public HLCellClass(Word.Cell CurCell) // 初始化是 赋值需要操作的Word.Cell对象
         {
              _Cell=CurCell;
         }
         #region HLCell 成员
         public Word.Cell BaseCell()
         {
             
              return _Cell;
         }
         public void SetLineSpace(Word.WdLineSpacing LineSpaceType,float Size)
         {
              _Cell.Range.ParagraphFormat.LineSpacingRule=LineSpaceType;
              _Cell.Range.ParagraphFormat.LineSpacing=Size;
         }
         public void SetFontSize(float Size)
         {
              _Cell.Range.Font.Size =Size;
         }
         ///<param ></param>
         public void SetFontBold(int Bold)
         {
              _Cell.Range.Font.Bold =Bold;
         }
         public void SetPositionAlign(Word.WdParagraphAlignment Alignment, Word.WdCellVerticalAlignment VerticalAlignment)
         {
              _Cell.VerticalAlignment=VerticalAlignment;
              _Cell.Range.ParagraphFormat.Alignment =Alignment;
         }
         public void SetBorderStyle(Word.WdLineStyle LineStyle,Word.WdLineWidth lineWidth)
         {
              _Cell.Borders[Word.WdBorderType.wdBorderLeft].LineStyle=LineStyle;
              _Cell.Borders[Word.WdBorderType.wdBorderRight].LineStyle=LineStyle;
              _Cell.Borders[Word.WdBorderType.wdBorderTop].LineStyle=LineStyle;
              _Cell.Borders[Word.WdBorderType.wdBorderBottom].LineStyle=LineStyle;
              _Cell.Borders[Word.WdBorderType.wdBorderLeft].LineWidth=lineWidth;
              _Cell.Borders[Word.WdBorderType.wdBorderRight].LineWidth=lineWidth;
              _Cell.Borders[Word.WdBorderType.wdBorderTop].LineWidth=lineWidth;
              _Cell.Borders[Word.WdBorderType.wdBorderBottom].LineWidth=lineWidth;
             
         }
         public void values(string Values)
         {
              _Cell.Range.InsertAfter(Values);
         }
         #endregion
     }
     ///<summary>
     /// the interface of HLCell ,change the Word Cell 's VBA Code to the C# Code
     ///</summary>
     public interface HLCell
     {
         Word.Cell BaseCell();
         //base Table Style
         void SetLineSpace(Word.WdLineSpacing LineSpaceType,float Size);
         void SetFontSize(float Size);
         void SetFontBold(int Bold);
         void SetPositionAlign(Word.WdParagraphAlignment Alignment,Word.WdCellVerticalAlignment VerticalAlignment);
         void SetBorderStyle(Word.WdLineStyle LineStyle,Word.WdLineWidth lineWidth);
         //Set CellValues into table's cell
         void values(string Values);
        
     }
}
下面还有 行数组对象 HLRows 和行对象HLRow ,具体的功能就不细说拉下面是代码部分。
/// <summary>
     /// HLRows 的摘要说明。
     ///</summary>
     public class HLRowsClass:HLRows
     {
         private Word.Rows _Rows=null;
         public HLRowsClass(Word.Rows CurRow)
         {
              _Rows=CurRow;
         }
         #region HLRows 成员
         public HLRow this[int i]
         {
              get
              {
                   return new HLRowClass(_Rows[i]);
              }
         }
         #endregion
     }
     public interface HLRows
     {
         HLRow this[int i]{get;}
    
     }
/// <summary>
     /// HLRow 的摘要说明。
     ///</summary>
     public class HLRowClass:HLRow
     {
         private Word.Row _Row =null;
        
         public HLRowClass(Word.Row CurRow)
         {
              _Row=CurRow;
         }
         #region HLRow 成员
         public void SetRowHeight(Word.WdRowHeightRule HeightRule, float Values)
         {
              _Row.HeightRule =HeightRule;
              _Row.Height=Values;
         }
         public void SetLineSpace(Word.WdLineSpacing LineSpaceType, float Size)
         {
              _Row.Range.ParagraphFormat.LineSpacingRule=LineSpaceType;
              _Row.Range.ParagraphFormat.LineSpacing=Size;
         }
         public void SetFontSize(float Size)
         {
              _Row.Range.Font.Size=Size;
         }
         public void SetFontBold(int Bold)
         {
              _Row.Range.Font.Bold =Bold;
         }
         #endregion
     }
     public interface HLRow
     {
         void SetRowHeight( Word.WdRowHeightRule HeightRule, float Values);
         void SetLineSpace(Word.WdLineSpacing LineSpaceType,float Size);
         void SetFontSize(float Size);
         void SetFontBold(int Bold);
     }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值