Thread Rating:
  • 306 Vote(s) - 2.71 Average
  • 1
  • 2
  • 3
  • 4
  • 5
グリッドでエクセルのように張り付けたい
03-02-2015, 01:08 PM,
#2
RE: グリッドでエクセルのように張り付けたい
貼り付け開始位置となるグリッドのフォーカス位置は、RecordGridUI.grid-focusで取得しています。
範囲選択処理をしてから、RecordGrid.do-command "paste" で、貼り付け処理を行えば、実現できそうです。


Code:
{define-proc public {paste-data grid:RecordGrid}:void

    def c ={Clipboard.get-system-clipboard}
    def data = {c.get-string}

    ||貼り付け範囲の測定(行、列の最大)
    let rows:int = 0
    let cols:int = 0
    def lines = {data.split split-chars = '\n'}
    set rows = lines.size
    {for ln in lines do
        set cols ={max cols,  {ln.split split-chars = '\t'}.size}
    }

    {if-non-null cell =  grid.ui.grid-focus then
        {if-non-null col = cell.column then

            ||貼り付け範囲の作成
            def first-row:int =  cell.record-index
            def first-column:int = {grid.columns.find col}
            def row-count:int = {min rows, grid.records.size - first-row}
            def column-count:int = {min cols, grid.columns.size - first-column}
            def region = {RecordGridRegion first-row,first-column ,row-count, column-count}

||++        {popup-message
||++            {VBox
||++                "貼り付け範囲",
||++                {Table columns= 2,
||++                    "コピー行数", rows, "コピー列数", cols,
||++                    "開始行",first-row, "開始列",first-column,
||++                    "範囲行数", row-count, "範囲列数", column-count
||++                }
||++            }
||++        }

            ||範囲の選択と貼り付け
            {with grid.region-selection-enabled? = true do
                {grid.select-region region}
                {grid.do-command "paste"}
            }

           ||表示位置のリセット
            set grid.current-index = cell.record-index
        }
    }
}



{def rf-list =
    {{Array-of RecordField}}
}
{def cols = 20}
{def rows = 20}

{for i:int = 1 to cols do
    {rf-list.append
        {RecordField {String i}, nullable?= true}
    }
}

{def rfs =
    {RecordFields
        {RecordField "index", nullable?= true}
        ,{RecordField "select", domain = bool}
        ,{splice rf-list}
    }
}

{def rs = {RecordSet rfs}}

{for i:int = 1 to rows do
    def new-r = {rs.new-record}
    set new-r["index"] = i
    {for j:int = 1 to cols do
        set new-r[{String j}] = {String i * j}
    }
    {rs.append new-r}
}

{def grid = {RecordGrid width = 8in, height = 3in, record-source = rs }}

{value grid}

{def paste-cb = {CommandButton  label = "貼り付け",  {on Action do {paste-data grid}}}}


{def copy-cb =
    {CommandButton
        label = "コピー",
        {on Action do
            {grid.select-all}
            {grid.do-command "copy"}
            {grid.select-nothing}
        }
    }
}

{HBox copy-cb, paste-cb}

Ctrl+v で行うようにするには、貼り付けイベントを上書きしたほうがいいかもですね。



Messages In This Thread
RE: グリッドでエクセルのように張り付けたい - by umemura - 03-02-2015, 01:08 PM
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('1206')