掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
StringGridでカット・&ペーストするのには (ID:33790)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
>エクセルのデータを範囲選択してStringGridに貼り付け及びその逆を行いたいのですが、どのようにコードを書けば良いでしょうか。 このようにコードを書いて下さい uses ClipBrd, StrUtils; //ClipBord to StringGrid procedure TForm2.Button1Click(Sender: TObject); var ClipBoard: TClipBoard; StringList: TStringList; X,Y,X2: Integer; S,S2: String; Col,Row: Integer; begin StringList := TStringList.Create; ClipBoard := TClipBoard.Create; ClipBoard.Open; StringList.Text := ClipBoard.AsText; Y := 0; Row := StringGrid1.Row; while Y < StringList.Count do begin Col := StringGrid1.Col; S := StringList[Y]; X := 1; while X <> 0 do begin X2 := PosEx(Char(9),S,X); if X2 = 0 then begin S2 := Copy(S,X,Length(S)); X := 0; end else begin S2 := Copy(S,X,X2-X); X := X2 + 1; end; StringGrid1.Cells[Col,Row] := S2; Inc(Col); end; Inc(Y); Inc(Row); end; ClipBoard.Close; ClipBoard.Free; StringList.Free; end; //StringGrid to ClipBoard procedure TForm2.Button2Click(Sender: TObject); var ClipBoard: TClipBoard; StringList: TStringList; X,Y: Integer; S: String; begin StringList := TStringList.Create; for Y:=StringGrid1.Selection.Top to StringGrid1.Selection.Bottom do begin S := ''; for X:=StringGrid1.Selection.Left to StringGrid1.Selection.Right do begin S := S + StringGrid1.Cells[X,Y]; if X <> StringGrid1.Selection.Right then S := S + Char(9); end; StringList.Add(S); end; ClipBoard := TClipBoard.Create; ClipBoard.Open; ClipBoard.AsText := StringList.Text; ClipBoard.Close; ClipBoard.Free; StringList.Free; end; BDS 2006 + EXCEL 2002
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.