📄 cgridstore.pas
字号:
unit CGridStore;
{*******************************************************
TGridStore Component (1.0) -- by WeiYF, 1998.10.29
该组件提供了将TStringGrid内容复制到剪贴板的几个函数
由于采用制表符#9作为分隔符,可以直接粘贴到在excel中
********************************************************}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, Clipbrd;
type
TGridStore = class(TComponent)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure CopyAllToClipboard(pGrid: TStringGrid);
procedure CopySelectionToClipboard(pGrid: TStringGrid);
procedure CopySpecialToClipboard(pGrid: TStringGrid; iRowBegin,iRowEnd,iColBegin,iColEnd: integer);
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('WeiYF', [TGridStore]);
end;
constructor TGridStore.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor TGridStore.Destroy;
begin
inherited Destroy;
end;
procedure TGridStore.CopyAllToClipboard(pGrid: TStringGrid);
var
//BufString: AnsiString;
i,j: integer;
begin
Screen.Cursor := crHourGlass;
ClipBoard.Open;
try
//BufString := '';
ClipBoard.AsText := '';
with pGrid do begin
for i:=0 to RowCount-1 do begin
for j:=0 to ColCount-1 do begin
if (j=0) then ClipBoard.AsText := ClipBoard.AsText+Cells[j,i]
else ClipBoard.AsText := ClipBoard.AsText+#9+Cells[j,i];
end;
if (i<>RowCount-1) then
ClipBoard.AsText := ClipBoard.AsText+#13+#10;
Application.ProcessMessages;
end;
end;
//Application.MainForm.Caption:= IntToStr(Length(BufString));
//ClipBoard.SetTextBuf(PChar(BufString));
finally
Clipboard.Close;
Screen.Cursor := crDefault;
end;
end;
procedure TGridStore.CopySelectionToClipboard(pGrid: TStringGrid);
var
i,j,iStart,iStop: integer;
begin
Screen.Cursor := crHourGlass;
ClipBoard.Open;
try
ClipBoard.AsText := '';
with pGrid do begin
if (goRowSelect in Options) then begin
iStart := 0; iStop := ColCount-1;
end
else begin
iStart := Selection.Left; iStop := Selection.Right;
end;
i := 0;
for j:=iStart to iStop do begin
if (j=iStart) then ClipBoard.AsText := ClipBoard.AsText+Cells[j,i]
else ClipBoard.AsText := ClipBoard.AsText+#9+Cells[j,i];
end;
for i:=Selection.Top to Selection.Bottom do begin
for j:=iStart to iStop do begin
if (j=iStart) then ClipBoard.AsText := ClipBoard.AsText+Cells[j,i]
else ClipBoard.AsText := ClipBoard.AsText+#9+Cells[j,i];
end;
if (i<>Selection.Bottom) then
ClipBoard.AsText := ClipBoard.AsText+#13+#10;
Application.ProcessMessages;
end;
end;
finally
Clipboard.Close;
Screen.Cursor := crDefault;
end;
end;
procedure TGridStore.CopySpecialToClipboard(pGrid: TStringGrid;
iRowBegin,iRowEnd,iColBegin,iColEnd: integer);
var
i,j: integer;
begin
Screen.Cursor := crHourGlass;
ClipBoard.Open;
try
ClipBoard.AsText := '';
with pGrid do begin
for i:=iRowBegin to iRowEnd do begin
for j:=iColBegin to iColEnd do begin
if (j=iColBegin) then ClipBoard.AsText := ClipBoard.AsText+Cells[j,i]
else ClipBoard.AsText := ClipBoard.AsText+#9+Cells[j,i];
end;
if (i<>iRowEnd) then
ClipBoard.AsText := ClipBoard.AsText+#13+#10;
Application.ProcessMessages;
end;
end;
finally
Clipboard.Close;
Screen.Cursor := crDefault;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -