找回密码
 立即注册

QQ登录

只需一步,快速开始

darkelf
论坛元老   /  发表于:2013-11-15 09:17  /   查看:6179  /  回复:5
旧版本的Spread是Activex,具体版本不清楚。
FPSpread.SelLength的功能应该是设置在活动单元格中要选择的字符数。

本功能在ActiveX跟Spread7Form的相同功能对照表中有取得相对应的功能控件。但是具体无法实现。
ActiveX的“SelLength” 等同于 Form7的 “GeneralEditor.SelectionLength”


  1.     Public Property SelLength() As Integer
  2.         Get
  3.             If MyBase.ActiveSheet IsNot Nothing Then
  4.                 Dim ct As CellType.GeneralEditor
  5.                 ' 1. 这里没有出现类型转换错误
  6.                 ct = CType(MyBase.ActiveSheet.Cells(.Row, .Col).CellType, CellType.GeneralEditor)
  7.                 Return ct.SelectionLength
  8.             Else
  9.                 Return Nothing
  10.             End If
  11.         End Get
  12.         Set(value As Integer)
  13.             Dim ct As New CellType.GeneralEditor

  14.             '2. 将GeneralEditor设置为数字或者文字类型单元格时,提示错误消息,不能将两种类型转换。
  15.             If TypeOf MyBase.ActiveSheet.Cells(_Row, _Col).CellType Is CellType.TextCellType Then
  16.                 ct.EditModeCursorPosition = FarPoint.Win.EditModeCursorPosition.LastKnownPosition
  17.                 ct.SelectionLength = value
  18.                 MyBase.ActiveSheet.Cells(_Row, _Col).CellType = CType(ct, CellType.TextCellType)
  19.             ElseIf TypeOf MyBase.ActiveSheet.Cells(_Row, _Col).CellType Is CellType.NumberCellType Then
  20.                 ct.EditModeCursorPosition = FarPoint.Win.EditModeCursorPosition.LastKnownPosition
  21.                 ct.SelectionLength = value
  22.                 MyBase.ActiveSheet.Cells(_Row, _Col).CellType = CType(ct, CellType.NumberCellType)
  23.             End If

  24.         End Set
  25.     End Property
复制代码


求教,如何在Spread Form 7中实现指定单元格的SelLength功能?

5 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-11-15 10:13:00
沙发
回复 1楼darkelf的帖子

请尝试一下代码:

  1. public Form1()
  2.         {
  3.             InitializeComponent();
  4.             this.fpSpread1.EditModeOn += new EventHandler(fpSpread1_EditModeOn);
  5.             this.fpSpread1.Sheets[0].Cells[0, 0].Text = "ssssss";
  6.         }

  7.         void fpSpread1_EditModeOn(object sender, EventArgs e)
  8.         {
  9.             GeneralEditor ge = this.fpSpread1.EditingControl as GeneralEditor;

  10.             ge.EditModeCursorPosition = FarPoint.Win.EditModeCursorPosition.LastKnownPosition;
  11.             ge.SelectionStart = 2;
  12.             ge.SelectionLength = 5;
  13.         }
复制代码
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-15 10:27:00
板凳
的确利用事件可以设置并取得当前单元格内内容的指定长度部分。具体实现就如Ice所提供的代码。
  1.     Private Sub MyBase_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.EditModeOn
  2.         _ChangeMade = True
  3.         Dim ge As CellType.GeneralEditor = CType(Me.EditingControl, CellType.GeneralEditor)
  4.         ge.EditModeCursorPosition = FarPoint.Win.EditModeCursorPosition.LastKnownPosition
  5.         ge.SelectionStart = 2
  6.         ge.SelectionLength = 5
  7.     End Sub
复制代码

但是目前旧程序中,.SelLength是作为一个Spread的属性在用。代码如下。
现在想将这个属性实现。
也就是说,流程大概是,设置单元格坐标,然后全选单元格的内容,并设置为当前单元格。
  1.         With vaSpread1
  2.                 .Col = 2
  3.                 .Row = 1
  4.                 .SelLength = Len(.Value)
  5.                 .Action = FPSpread.ActionConstants.ActionActiveCell
  6.                 .Focus()
  7.         End With
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-15 13:47:00
地板
回复 3楼darkelf的帖子

如果需要全选有更方便的解决方法:

  1. Private Sub SetActiveCellToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SetActiveCellToolStripMenuItem.Click
  2.         Dim sv As SheetView = Me.FpSpread1.ActiveSheet

  3.         sv.Cells(1, 1).Text = "123456789"
  4.         sv.ActiveRowIndex = 1
  5.         sv.ActiveColumnIndex = 1

  6.         Me.FpSpread1.EditModeReplace = True
  7.         Me.FpSpread1.EditMode = True
  8.     End Sub
复制代码
回复 使用道具 举报
darkelf
论坛元老   /  发表于:2013-11-15 16:50:00
5#
3Q~~
的确这个方法解决了目前的问题。

我将您给的代码写入SelLength函数中,从执行表现上,跟需要的结果一样。

非常感谢。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-15 17:13:00
6#
回复 5楼darkelf的帖子

不客气,有问题欢迎开新帖提问。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部