Jer*_*dge 4 delphi excel clipboard tstringgrid delphi-xe2
我正在开发一种工具,它连接到SQL数据库,获取数据集,并在网格中显示该数据.用户必须能够选择一个单元格块(只是矩形),然后按CTRL+ C将其复制到剪贴板.
我该怎么做呢:
在可以粘贴到Excel的格式?我希望已经有一些现成的东西.它不需要Excel之类的所有剪贴板功能,只需突出显示一组矩形单元格并将其复制到剪贴板即可.
如果它可以在一个TStringGrid我喜欢保持我的功能,但也可以使用支持它的组件.
您可以尝试复制单元格值TAB delimited text,就像这段代码一样:
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
X, Y: Integer;
begin
S := '';
for Y := StringGrid1.Selection.Top to StringGrid1.Selection.Bottom do
begin
for X := StringGrid1.Selection.Left to StringGrid1.Selection.Right - 1 do
S := S + StringGrid1.Cells[X, Y] + #9;
S := S + StringGrid1.Cells[StringGrid1.Selection.Right, Y] + sLineBreak;
end;
Delete(S, Length(S) - Length(sLineBreak) + 1, Length(sLineBreak));
Clipboard.AsText := S;
end;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6380 次 |
| 最近记录: |