FpSpread控件的总结VB插件 2010-07-27 10:57:46 阅读361 评论0 字号:大中小 订阅
spread 中checkbox的用法 forpoint spreadsheet
列类别选择combo就可以了 spread的帮助文件中间搜索 CellType property, check box cells
//------------------------------------------------------ 是这样的,我的webform上放了一个FpSpread控件,我想把行头变成checkbox样式,我的方法是在后台代码中定义:
FarPoint.Web.Spread.CheckBoxCellType celltype = new FarPoint.Web.Spread.CheckBoxCellType(); 然后将此type赋给行头: FpSpread1.ActiveSheetView.RowHeader.Cells[0,0].CellType=celltype; 我的问题是:1.如果我想用一个Button控制当点击Button时,如果CheckBox是选中状态,则在该中显示某某字符,但我不知道这种CheckBox的标识是什么,还有他的状态为选中或没选中返回值是什么? 2.还有其他方法吗?比如我用 FpSpread1.ActiveSheetView.RowHeader.Cells[0,0].Text="<Input id=\"nihao\" checked type =\"CheckBox\" />" 遇到的困难和刚才一样。 请问怎么解决,多谢! FpSpread1.columnsheader.cells(0,0).text="Check #"
//-------------------------------------------------------------
确定check所在的位置,然后直接判断FpSpread1.Sheets(0).Cells(1,6).Value是否为1,为1就是选中状态。我是这样的。 Public Sub SetCOLCheck(spd As vaSpread, ByVal lCol1 As Long, ByVal lCol2 As Long, _
Optional ByVal IsCenter As Boolean = True) With spd .Col = lCol1 .Col2 = lCol2 .Row = -1 .BlockMode = True .CellType = 10 .TypeHAlign = 0 .TypeCheckCenter = IsCenter .BlockMode = False End With End Sub 我使用的是Spread,是这么填加的 //---------------------------------------------------------
1.BorderStyle:调整是否有边框 默认为Fixed3D FixedSingle只有一条线 2.location x,y 调整位置 3.horizontalScrollBarPolicy 默认为Always横向向滚共条始终存在,就是AsNeeded条数超过显示就存在,否则不显示,Never始终没有滚动条
4.verticalScrollBarPolicy 默认为Always纵向滚共条始终存在,就是AsNeeded条数超过显示就存在,否则不显示,Never始终没有滚动条
5.Enabled 是否可以编辑
点击Sheets属性旁的按钮就会出现关于Sheets页里面属性的设置
1.selectionUnit 默认为Cell运行的时候,点击单元格选中的只是一个单元 Column整列,Row整行
2.ColumnCount Spread表示数据的列数
3.RowCount Spread表示数据的行数
4.*OperationMode 主要是MultiSelect,SingleSelect两种的区分SingleSelect只能选一行, MultiSelect可以择多行。
5.rows和Column下的Resizable可以将列和行的大小固定为不可调整
AddColumns(Integer i, Integer j)添加列,i是起始位置,j是列数。
AddRows(Integer i, Integer j)添加列,i是起始位置,j是列数。
.AddSelection(I,j,k,m)添加选中的cell
.ClearRange AddSelection(I,j,k,m,true)清空Spread.还有很多常用的方法。就往Spread中放值的方法
1.创建对应的DataSource Me.FpSpread1_Sheet1().DataSource =objDs.Tables(0)
Me.FpSpread1_Sheet1().Columns(0).DataField = "id"
Me.FpSpread1_Sheet1().Columns(1).DataField = "name“
**Id,和name是从数据库中查出来得数据结果集中数据表的字段名。
这样从数据库中查出的值就可放在相应的列上了。
2.也可单独往单元格中放值
Me.FpSpread1_Sheet1.Cells(0, 0).Value() = “123”
*放值时需要注意的是FpSpread1_Sheet1的起始位置是(0,0)
如果只有4行4列的话是不存在(4,4)这样的Cells的
Me.FpSpread1_Sheet1.ActiveRowIndex
可以取得选择的行的索引值,从0开始
FpSpread1_Sheet1.Cells(FpSpread1_Sheet1.ActiveRowIndex, 1)
可以取得选择的行对应单元格的值。
Dim cellButtonType As New FarPoint.Win.Spread.CellType.ButtonCellType cellButtonType.Text = "Detail" Me.SpdYoteyi_Sheet1.ColumnHeader.Cells.Get(0, 3).BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte)) With frm.SpdYoteyi.Sheets(0) .Columns.Get(0).ForeColor = System.Drawing.Color.Red .Columns.Get(3).ForeColor = System.Drawing.Color.Blue .SetText(0, 0, "eld001") .SetText(0, 7, "2006/04/20") .SetText(0, 9, "会社AAA") // 动态添加列。 .AddColumns(10, 1)
.Columns.Get(10).Label = "詳しい" .Columns.Get(10).CellType = cellButtonType End With // 获得当前选中行
.SpdYoteyi.ActiveSheet.ActiveRowIndex()
//------------------------------------------------- 关于spread的一些基本操作
对日软件开发,经常会用到spread控件。使用中积累了一些经验,自己总结一下。
1.spread的cell 在spread的设计界面里可以设置cell的各种属性,和用惯的vb差不多。其实它的help写的挺详细的,刚开始日文不好看起来不方便,现在可以顺利理解了。Cell可以是checkbox,文字,数字,时间等等类型,可以只读,可读写,还可以设置背景色,边框等。和excel相像的。 2.Cell的读写模式。 1. 只读 ① 全体只读 With spdTEMP .Col = 1 .Col2 = .MaxCols .Row = 1 .Row2 = -1 '当spd里数据是0条时,.MaxRows会出错。用-1安全。 .Protect = True .BlockMode = True .Lock = True .BlockMode = False End With ②部分只读,设置行和列就可以 With spdTEMP .Col = 2 .Col2 = 5 .Row = 1 .Row2 = 8 .Protect = True .BlockMode = True .Lock = True .BlockMode = False End With 2.一般写模式和覆盖写模式 一般写模式:.EditMode = True 覆盖写模式:.EditModeReplace = True 区别在于 1)光标模式不同,一般写为单个鼠标入力光标,覆盖写已有内容全选,替换输入。 2)当输入带有小数的数字时,覆盖写会自动跳到小数最末位,这可能是spread3.0在win2000下的bug吧。症状是第一遍输入10.23时会变成1.03,第二遍输入时就好了。试验了很多次,最后不得已换成一般写模式。 3.spread的click事件 ① 这是一段点击每行第三列时,自动全行copy数据的例子。 Private Sub spdTMSR160_Click(ByVal Col As Long, ByVal Row As Long) Dim temp As String Dim i As Integer If Row = 0 Then Exit Sub If spdTMSR160.Lock = True Then Exit Sub With spdTMSR160 .Col = 3 .Col2 = .MaxRows .Row = Row .Row2 = Row If Col = 2 And .Value <> "" Then If MsgBox("3月の予算金額を全ての月にコピーしてもよろしいですか?", vbQuestion + vbYesNo) = vbYes Then .BlockMode = True temp = .Value For i = 1 To 11 .Col = .Col + 1: .Value = temp Next End If End If .BlockMode = False End With End Sub ② 这是一段有选择按钮的例子。选中时行变色,部分cell改变入力状态。
Private Sub spdTMSR020_Click(ByVal Col As Long, ByVal Row As Long) If Row = 0 Then Exit Sub ' If spdTMSR020.Lock = True Then Exit Sub If Col >= 1 And Col <= 7 Then With spdTMSR020 .Col = 1 .Col2 = .MaxCols .Row = Row .Row2 = Row .Value = IIf(.Value = 0, 1, 0) .BlockMode = True If .Value = 0 Then
' If Row Mod 2 = 0 Then ' .BackColor = RGB(245, 236, 233) ' Else .BackColor = RGB(255, 255, 255) ' End If .Col = 8 .Col2 = 11 .Row = Row .Row2 = Row .Protect = True .Lock = True Else .BackColor = RGB(128, 255, 128) .Col = 8 .Col2 = 11 .Row = Row .Row2 = Row .Lock = False .EditMode = True End If .BlockMode = False
End With End If End Sub spread3.0的选择按钮很脆弱,一不小心小红钩不见了,事件却没有触发。所以把边上的固定列都设为可选择状态。 4.关于背景色的设置。 Backcolor 指定范围,设置背景色 SetOddEvenRowColor,设置奇数,偶数行的颜色。 本来背景色是粉红和白色相间的,但是单行变色判断和全体变色中产生问题,不得不改成全白的。 其根本原因是backcolor比SetOddEvenRowColor要强。Backcolor可以更改SetOddEvenRowColor设置的颜色,而SetOddEvenRowColor却无法改变Backcolor设定的颜色。 而当数据很多时,背景需要刷新时,用backcolor一行一行判断更改,画面会产生剧烈颤抖…. //---------------------------------- 序号属性说明 1.MaxRows = 10设置总行数为10行 2.MaxCols = 5设置总列数为5列 3.ColHeaderRows = 2表头(列标题)行数为2 4.Row = SpreadHeader定位到表头(列标题) 5.Row = -1定位到行头(在设置列格式时使用) 6.ColWidth(1) = 16设置第1列的列宽为16 7.RowHeight(1) = 12设置第1行的行高为12 8.FontSize = 10"设置当前栏位的字体大小为10(如果.Row = -1, 则设置整列,下同)" 9.TypeHAlign = TypeHAlignRight设置文字水平对齐方式为右对齐 .TypeVAlign = TypeVAlignCenter设置文字垂直对齐方式为居中 10.CellType = CellTypeNumber设置为数字类型 11.TypeNumberDecPlaces = 2设置小数位数 12.TypeNumberShowSep = True设置千位分隔 13.SetText 2, 3, "test"设置第2列第3行的文本为"test" 14.GetText 2, 3, MyText将第2列第3行的值赋给变量MyText 15.Row = 3定位到第3行 16.Col = 2定位到第2列 17.Text = "test"设置当前栏位的文本为"test" 18MyRow = .ActiveRow将当前行号赋值给变量MyRow 19.InsertRows 2, 1在第2行前插入1行 20.DeleteRows 2, 1"在第2行前删除1行(如果Spread是通过设置数据源 取得数据的话,则必须设置.DataSource = Nothing 才能删除)" 21.InsertCols 2, 1在第2列前插入1列 22.DeleteCols 2, 1在第2列前删除1列 23.AddCellSpan 3, 4, 2, 1从第3列第4行起合并单元格,跨度为2列1行 24.RowHeadersShow = False隐藏行标题 25.ColHeadersShow = False隐藏列标题 26.PrintMarginLeft = 1000打印时左边距=1000(包括预览) 27.PrintMarginTop = 1000打印时上边距=1000(包括预览) 28.OperationMode = OperationModeRow设置Spread的操作模式为行定位(共有6种模式) 29.DataSource = Rs设置Spread的数据源为Rs记录集 |
|