gpt4 book ai didi

delphi - 以 Excel 格式将多个单元格从网格复制到剪贴板?

转载 作者:行者123 更新时间:2023-12-03 15:25:48 26 4
gpt4 key购买 nike

我正在开发一个工具,它可以连接到 SQL 数据库、获取数据集并在网格中显示该数据。用户必须能够选择一个单元格 block (只是矩形)并按 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;

关于delphi - 以 Excel 格式将多个单元格从网格复制到剪贴板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11916306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com