spread 知識點滴積累(1)

來源:互聯網
上載者:User
spread 知識點滴積累

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記錄集

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.