下面是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);
}
|
Office编程在dot Net环境中总结(Word生成表格报表篇) (二)
最新推荐文章于 2021-02-01 07:44:11 发布