FpSpread控件的總結(jié)VB插件 2010-07-27 10:57:46 閱讀361 評(píng)論0 字號(hào):大中小 訂閱
spread 中checkbox的用法 forpoint spreadsheet
列類(lèi)別選擇combo就可以了 spread的幫助文件中間搜索 CellType property, check box cells
//------------------------------------------------------ 是這樣的,我的webform上放了一個(gè)FpSpread控件,我想把行頭變成checkbox樣式,我的方法是在后臺(tái)代碼中定義:
FarPoint.Web.Spread.CheckBoxCellType celltype = new FarPoint.Web.Spread.CheckBoxCellType(); 然后將此type賦給行頭: FpSpread1.ActiveSheetView.RowHeader.Cells[0,0].CellType=celltype; 我的問(wèn)題是:1.如果我想用一個(gè)Button控制當(dāng)點(diǎn)擊Button時(shí),如果CheckBox是選中狀態(tài),則在該中顯示某某字符,但我不知道這種CheckBox的標(biāo)識(shí)是什么,還有他的狀態(tài)為選中或沒(méi)選中返回值是什么? 2.還有其他方法嗎?比如我用 FpSpread1.ActiveSheetView.RowHeader.Cells[0,0].Text="<Input id=\"nihao\" checked type =\"CheckBox\" />" 遇到的困難和剛才一樣。 請(qǐng)問(wèn)怎么解決,多謝! FpSpread1.columnsheader.cells(0,0).text="Check #"
//-------------------------------------------------------------
確定check所在的位置,然后直接判斷FpSpread1.Sheets(0).Cells(1,6).Value是否為1,為1就是選中狀態(tài)。我是這樣的。 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:調(diào)整是否有邊框 默認(rèn)為Fixed3D FixedSingle只有一條線 2.location x,y 調(diào)整位置 3.horizontalScrollBarPolicy 默認(rèn)為Always橫向向滾共條始終存在,就是AsNeeded條數(shù)超過(guò)顯示就存在,否則不顯示,Never始終沒(méi)有滾動(dòng)條
4.verticalScrollBarPolicy 默認(rèn)為Always縱向滾共條始終存在,就是AsNeeded條數(shù)超過(guò)顯示就存在,否則不顯示,Never始終沒(méi)有滾動(dòng)條
5.Enabled 是否可以編輯
點(diǎn)擊Sheets屬性旁的按鈕就會(huì)出現(xiàn)關(guān)于Sheets頁(yè)里面屬性的設(shè)置
1.selectionUnit 默認(rèn)為Cell運(yùn)行的時(shí)候,點(diǎn)擊單元格選中的只是一個(gè)單元 Column整列,Row整行
2.ColumnCount Spread表示數(shù)據(jù)的列數(shù)
3.RowCount Spread表示數(shù)據(jù)的行數(shù)
4.*OperationMode 主要是MultiSelect,SingleSelect兩種的區(qū)分SingleSelect只能選一行, MultiSelect可以擇多行。
5.rows和Column下的Resizable可以將列和行的大小固定為不可調(diào)整
AddColumns(Integer i, Integer j)添加列,i是起始位置,j是列數(shù)。
AddRows(Integer i, Integer j)添加列,i是起始位置,j是列數(shù)。
.AddSelection(I,j,k,m)添加選中的cell
.ClearRange AddSelection(I,j,k,m,true)清空Spread.還有很多常用的方法。就往Spread中放值的方法
1.創(chuàng)建對(duì)應(yīng)的DataSource Me.FpSpread1_Sheet1().DataSource =objDs.Tables(0)
Me.FpSpread1_Sheet1().Columns(0).DataField = "id"
Me.FpSpread1_Sheet1().Columns(1).DataField = "name“
**Id,和name是從數(shù)據(jù)庫(kù)中查出來(lái)得數(shù)據(jù)結(jié)果集中數(shù)據(jù)表的字段名。
這樣從數(shù)據(jù)庫(kù)中查出的值就可放在相應(yīng)的列上了。
2.也可單獨(dú)往單元格中放值
Me.FpSpread1_Sheet1.Cells(0, 0).Value() = “123”
*放值時(shí)需要注意的是FpSpread1_Sheet1的起始位置是(0,0)
如果只有4行4列的話是不存在(4,4)這樣的Cells的
Me.FpSpread1_Sheet1.ActiveRowIndex
可以取得選擇的行的索引值,從0開(kāi)始
FpSpread1_Sheet1.Cells(FpSpread1_Sheet1.ActiveRowIndex, 1)
可以取得選擇的行對(duì)應(yīng)單元格的值。
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, "會(huì)社AAA") // 動(dòng)態(tài)添加列。 .AddColumns(10, 1)
.Columns.Get(10).Label = "詳しい" .Columns.Get(10).CellType = cellButtonType End With // 獲得當(dāng)前選中行
.SpdYoteyi.ActiveSheet.ActiveRowIndex()
//------------------------------------------------- 關(guān)于spread的一些基本操作
對(duì)日軟件開(kāi)發(fā),經(jīng)常會(huì)用到spread控件。使用中積累了一些經(jīng)驗(yàn),自己總結(jié)一下。
1.spread的cell 在spread的設(shè)計(jì)界面里可以設(shè)置cell的各種屬性,和用慣的vb差不多。其實(shí)它的help寫(xiě)的挺詳細(xì)的,剛開(kāi)始日文不好看起來(lái)不方便,現(xiàn)在可以順利理解了。Cell可以是checkbox,文字,數(shù)字,時(shí)間等等類(lèi)型,可以只讀,可讀寫(xiě),還可以設(shè)置背景色,邊框等。和excel相像的。 2.Cell的讀寫(xiě)模式。 1. 只讀 ① 全體只讀 With spdTEMP .Col = 1 .Col2 = .MaxCols .Row = 1 .Row2 = -1 '當(dāng)spd里數(shù)據(jù)是0條時(shí),.MaxRows會(huì)出錯(cuò)。用-1安全。 .Protect = True .BlockMode = True .Lock = True .BlockMode = False End With ②部分只讀,設(shè)置行和列就可以 With spdTEMP .Col = 2 .Col2 = 5 .Row = 1 .Row2 = 8 .Protect = True .BlockMode = True .Lock = True .BlockMode = False End With 2.一般寫(xiě)模式和覆蓋寫(xiě)模式 一般寫(xiě)模式:.EditMode = True 覆蓋寫(xiě)模式:.EditModeReplace = True 區(qū)別在于 1)光標(biāo)模式不同,一般寫(xiě)為單個(gè)鼠標(biāo)入力光標(biāo),覆蓋寫(xiě)已有內(nèi)容全選,替換輸入。 2)當(dāng)輸入帶有小數(shù)的數(shù)字時(shí),覆蓋寫(xiě)會(huì)自動(dòng)跳到小數(shù)最末位,這可能是spread3.0在win2000下的bug吧。癥狀是第一遍輸入10.23時(shí)會(huì)變成1.03,第二遍輸入時(shí)就好了。試驗(yàn)了很多次,最后不得已換成一般寫(xiě)模式。 3.spread的click事件 ① 這是一段點(diǎn)擊每行第三列時(shí),自動(dòng)全行copy數(shù)據(jù)的例子。 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 ② 這是一段有選擇按鈕的例子。選中時(shí)行變色,部分cell改變?nèi)肓顟B(tài)。
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的選擇按鈕很脆弱,一不小心小紅鉤不見(jiàn)了,事件卻沒(méi)有觸發(fā)。所以把邊上的固定列都設(shè)為可選擇狀態(tài)。 4.關(guān)于背景色的設(shè)置。 Backcolor 指定范圍,設(shè)置背景色 SetOddEvenRowColor,設(shè)置奇數(shù),偶數(shù)行的顏色。 本來(lái)背景色是粉紅和白色相間的,但是單行變色判斷和全體變色中產(chǎn)生問(wèn)題,不得不改成全白的。 其根本原因是backcolor比SetOddEvenRowColor要強(qiáng)。Backcolor可以更改SetOddEvenRowColor設(shè)置的顏色,而SetOddEvenRowColor卻無(wú)法改變Backcolor設(shè)定的顏色。 而當(dāng)數(shù)據(jù)很多時(shí),背景需要刷新時(shí),用backcolor一行一行判斷更改,畫(huà)面會(huì)產(chǎn)生劇烈顫抖…. //---------------------------------- 序號(hào)屬性說(shuō)明 1.MaxRows = 10設(shè)置總行數(shù)為10行 2.MaxCols = 5設(shè)置總列數(shù)為5列 3.ColHeaderRows = 2表頭(列標(biāo)題)行數(shù)為2 4.Row = SpreadHeader定位到表頭(列標(biāo)題) 5.Row = -1定位到行頭(在設(shè)置列格式時(shí)使用) 6.ColWidth(1) = 16設(shè)置第1列的列寬為16 7.RowHeight(1) = 12設(shè)置第1行的行高為12 8.FontSize = 10"設(shè)置當(dāng)前欄位的字體大小為10(如果.Row = -1, 則設(shè)置整列,下同)" 9.TypeHAlign = TypeHAlignRight設(shè)置文字水平對(duì)齊方式為右對(duì)齊 .TypeVAlign = TypeVAlignCenter設(shè)置文字垂直對(duì)齊方式為居中 10.CellType = CellTypeNumber設(shè)置為數(shù)字類(lèi)型 11.TypeNumberDecPlaces = 2設(shè)置小數(shù)位數(shù) 12.TypeNumberShowSep = True設(shè)置千位分隔 13.SetText 2, 3, "test"設(shè)置第2列第3行的文本為"test" 14.GetText 2, 3, MyText將第2列第3行的值賦給變量MyText 15.Row = 3定位到第3行 16.Col = 2定位到第2列 17.Text = "test"設(shè)置當(dāng)前欄位的文本為"test" 18MyRow = .ActiveRow將當(dāng)前行號(hào)賦值給變量MyRow 19.InsertRows 2, 1在第2行前插入1行 20.DeleteRows 2, 1"在第2行前刪除1行(如果Spread是通過(guò)設(shè)置數(shù)據(jù)源 取得數(shù)據(jù)的話,則必須設(shè)置.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隱藏行標(biāo)題 25.ColHeadersShow = False隱藏列標(biāo)題 26.PrintMarginLeft = 1000打印時(shí)左邊距=1000(包括預(yù)覽) 27.PrintMarginTop = 1000打印時(shí)上邊距=1000(包括預(yù)覽) 28.OperationMode = OperationModeRow設(shè)置Spread的操作模式為行定位(共有6種模式) 29.DataSource = Rs設(shè)置Spread的數(shù)據(jù)源為Rs記錄集 |
|