关于farpoint公司的控件:SPREAD for .NET Windows Forms Ed.的一些简单方法.
View Code
using System;
using FarPoint.Win.Spread ;
using System.Drawing;
using System.Windows.Forms;
namespace DFO010
{
/// <summary>
/// Fpspread的相关函数.2006/4/12 制作:Chouka
/// </summary>
public class Classspd
{
public Classspd()
{
}
/// <summary>
///设置spd的最大行列数 参数:表格对象,最大行数,最大列数
/// </summary>
public static void spdOption(FpSpread ospd,int omaxrow,int omaxcol)
{
if(omaxrow>=0 && omaxcol>=0)
{
ospd.ActiveSheet.ColumnCount = omaxcol;
ospd.ActiveSheet.RowCount =omaxrow;
}
}
///<summary>
/// 清除spd中文本 参数:表格对象
///</summary>
public static void spdTextClear(FpSpread ospd)
{
//其中,true是只清除文本,false是清除文本+sheet内部所有的格式.
ospd.ActiveSheet.ClearRange(0,0,ospd.ActiveSheet.RowCount,ospd.ActiveSheet.ColumnCount,true);
}
///<summary>
/// 设定单元格的焦点 参数:表格对象,单元格行号,单元格列号
///</summary>
public static void spdSetFocus(FpSpread ospd,int orow ,int ocol)
{
if(orow>=0 && ocol>=0)
{
ospd.Focus();
//ospd.ActiveSheet.SetActiveCell(orow,ocol,false);
ospd.ActiveSheet.ActiveRowIndex =orow;
ospd.ActiveSheet.ActiveColumnIndex =ocol;
}
}
///<summary>
/// 获取指定单元格内的值 参数:表格对象,单元格行号,单元格列号 返回:值(文本)
///</summary>
public static string spdGetValue(FpSpread ospd,int orow,int ocol)
{
string str ="";
if(orow>=0 && ocol>=0)
{
str=System.Convert.ToString (ospd.ActiveSheet.GetValue(orow,ocol));
}
return str;
}
///<summary>
/// 设定指定单元格内的值 参数:表格对象,值,单元格行号,单元格列号
///</summary>
public static void spdSetValue(FpSpread ospd,string str,int orow,int ocol)
{
if (orow>=0 && ocol>=0)
{
ospd.ActiveSheet.SetValue(orow,ocol,str);
}
}
///<summary>
/// 设定单元格的锁定(多行多列) 参数:表格对象,开始行号,开始列号,终止行号,终止列号
///</summary>
public static void spdLock(FpSpread ospd,int orow1,int ocol1,int orow2,int ocol2)
{
ospd.ActiveSheet.Cells[orow1,ocol1,orow2,ocol2].Locked=true;
ospd.ActiveSheet.LockBackColor =Color.LightYellow;
}
///<summary>
/// 设定单元格的锁定(单个) 参数:表格对象,行号,列号
///</summary>
public static void spdLock(FpSpread ospd,int orow,int ocol)
{
ospd.ActiveSheet.Cells[orow,ocol].Locked =true;
ospd.ActiveSheet.LockBackColor =Color.LightYellow;
}
///<summary>
/// 解锁单元格(多行多列) 参数:表格对象,开始行号,开始列号,终止行号,终止列号
///</summary>
public static void spdUnLock(FpSpread ospd,int orow1,int ocol1,int orow2,int ocol2)
{
ospd.ActiveSheet.Cells[orow1,ocol1,orow2,ocol2].Locked =false;
ospd.ActiveSheet.LockBackColor =Color.White;
}
///<summary>
/// 解锁单元格(单个) 参数:表格对象,行号,列号
///</summary>
public static void spdUnLock(FpSpread ospd,int orow,int ocol)
{
ospd.ActiveSheet.Cells[orow,ocol].Locked =false;
ospd.ActiveSheet.LockBackColor =Color.White;
}
///<summary>
/// spd的初始属性设置.(回车跳格,清除split,锁定行高列宽.直接更改文本)
///</summary>
public static void spdLoad(FpSpread ospd)
{
//回车进行到下一个单元格
InputMap im;
im = ospd.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter,Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextColumnWrap);
im = ospd.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter,Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextColumnWrap);
// 清除split按钮
ospd.RowSplitBoxPolicy =SplitBoxPolicy.Never;
ospd.ColumnSplitBoxPolicy =SplitBoxPolicy.Never ;
//锁定列宽和行高
ospd.ActiveSheet.Columns[0,ospd.ActiveSheet.ColumnCount - 1].Resizable =false;
ospd.ActiveSheet.Rows[0,ospd.ActiveSheet.RowCount - 1].Resizable =false;
//单元格进入后文本全选.
ospd.EditModeReplace =true;
}
///<summary>
/// spd 按回车光标横向移动,跳过lock的单元格.在spd的LeaveCell事件中使用.参数:sender,事件
///</summary>
public static void spdLockCheck(FpSpread ospd,object sender, LeaveCellEventArgs e)
{
if(ospd.ActiveSheet.Cells[e.NewRow,e.NewColumn].Locked ==true)
System.Windows.Forms.SendKeys.Send("{ENTER}");
}
///<summary>
/// 设置多行类型的列标题. 参数:表格控件,行号(标题的index号),列号,标题
///<summary>
public static void spdColLabel(FpSpread ospd,int orow,int ocol,string ostr)
{
ospd.ActiveSheet.SetColumnLabel(orow,ocol,ostr);
}
///<summary>
/// 设置多列类型的行标题. 参数:表格控件,行号,列号(标题的index号),标题
///<summary>
public static void spdRowLabel(FpSpread ospd,int orow,int ocol,string ostr)
{
ospd.ActiveSheet.SetRowLabel(orow,ocol,ostr);
}
///<summary>
///获得尾行(不空)行号
///</summary>
public static int spdFullRow(FpSpread ospd)
{
return ospd.ActiveSheet.NonEmptyRowCount;
}
///<summary>
///获得表格的行数
///</summary>
public static int spdGetRowNumber(FpSpread ospd)
{
return ospd.ActiveSheet.RowCount;
}
///<summary>
///获得表格的列数
///</summary>
public static int spdGetColNumber(FpSpread ospd)
{
return ospd.ActiveSheet.ColumnCount ;
}
}
}