如何在运行时将 Windows 剪贴板的内容复制到 Excel 电子表格中?
我可以打开 Excel,将一些内容复制到剪贴板,但无法在运行时将剪贴板复制或粘贴到 Excel 中。
这是一个缺少剪贴板粘贴到 Excel 的小示例:-
uses Vcl.Clipbrd, System.Win.ComObj{CreateOLEObject};
var
xls, wb: OLEVariant;
begin
try
// Create the Excel App.
xls := CreateOLEObject('Excel.Application');
// Create a WorkBook.
wb := xls.Workbooks.Add;
// Clear the Clipboard.
Clipboard.Clear;
// Assign some test text.
Clipboard.AsText := 'Test Text';
// Put the Clipboard contents into the Spreadsheet here:-
// Display Excel
xls.Visible := True;
except
on E:Exception do
begin
MessageDlg('Problems.' + E.Exception, mtWarning, [mbOk], 0);
end
end;
end;
谢谢
根据 Excel 从剪贴板粘贴多个单元格 [原文如此],它应该是:
xls.Visible:= TRUE;
xls.Range['B1','B1'].Select; // Something must be selected before.
xls.ActiveSheet.Paste; // Insert whatever the clipboard contains (may not be text only).
当您手动使用 Excel 时:您首先必须选择目标工作表,然后选择要粘贴剪贴板内容的目标单元格。