[英]Copy cells with format from an excel worksheet to another workbook worksheet in Delphi
[英]Copy multiple cells from grid to clipboard in excel format?
我正在開發一種工具,該工具可連接到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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.