1.FpSpread控件获取当前行号和列号
With Me.FpSpread1.ActiveSheet
Dim str As String = String.Format("当前行号 {0} 当前列号 {1}", .ActiveRow.Index, _
.ActiveColumn.Index)
Me.ShowMesage(str)
str = String.Format("当前行号 {0} 当前列号 {1}", .ActiveRow.Index2, _
.ActiveColumn.Index2)
Me.ShowMesage(str)
End With
2.FpSpread控件选择单元格时,更改这一行的颜色
'判断是否点击列头 If Not e.ColumnHeader Then Dim sheet As FarPoint.Win.Spread.SheetView = e.View.Sheets(e.View.ActiveSheetIndex) Me.ShowMesage(String.Format("共有 {0} 行", sheet.Rows.Count)) sheet.Rows(e.Row).BackColor = Color.Blue For i As Integer = 0 To sheet.Rows.Count - 1 If i <> e.Row Then sheet.Rows(i).BackColor = sheet.DefaultStyle.BackColor End If Next End If
3.FpSpread控件单元格的设置值,获取值
'获取当前单元格 If Not Me.FpSpread1.ActiveSheet.ActiveCell Is Nothing Then Me.ShowMesage("当前单元格的值 " & Me.FpSpread1.ActiveSheet.ActiveCell.Text) End If '获取指定位置单元格的值 Dim cell As FarPoint.Win.Spread.Cell = Me.FpSpread1.ActiveSheet.Cells(1, 1) Me.ShowMesage("(1,1) 单元格的值 " & cell.Text) 'tag的应用 cell = Me.FpSpread1.ActiveSheet.Cells(1, 2) cell.Tag = "ppome" cell = Me.FpSpread1.ActiveSheet.Cells("ppome") If cell Is Nothing Then Me.ShowMesage("按tag 获取单元失败,ppome 不存在") Else Me.ShowMesage(String.Format("{0},{1} 单元格值 {2}", cell.Row.Index, cell.Column.Index, cell.Text)) End If 按tag获取时,如果存在有相同的tag则只返回一个?就近一个吧.
'设置单元格的值 If Not Me.FpSpread1.ActiveSheet.ActiveCell Is Nothing Then Me.FpSpread1.ActiveSheet.ActiveCell.Text = "http://www.ppome.cn" Else MessageBox.Show("没有选择单元格.") End If
4.FpSpread控件通过下键选择单元格时时,更改行的颜色
Dim sheet As FarPoint.Win.Spread.SheetView = Me.FpSpread1.ActiveSheet
sheet.Rows(e.NewRow).BackColor = Color.Cyan
For i As Integer = 0 To sheet.Rows.Count - 1
If i <> e.NewRow Then
sheet.Rows(i).BackColor = sheet.DefaultStyle.BackColor
End If
Next