在ole自动化中用delphi粘贴

发布于 2024-09-09 21:33:49 字数 377 浏览 4 评论 0原文

我想在delphi中从richedit粘贴到word应用程序 我使用了以下代码,但两次将数据粘贴到word中(重复)

  WordApp := GetActiveOleObject('Word.Application');
  WordApp.Visible := True;
  Wordapp.documents.open('C:\Doc1.docx');
  Richedit.Text := 'test text';
  Richedit.SelectAll;
  Richedit.CopyToClipboard;
  WordApp.ActiveDocument.ActiveWindow.Selection.Paste;
  WordApp.selection.paste;

i want paste in delphi from richedit to word application
i used Following code but Twice paste data in word (duplicate)

  WordApp := GetActiveOleObject('Word.Application');
  WordApp.Visible := True;
  Wordapp.documents.open('C:\Doc1.docx');
  Richedit.Text := 'test text';
  Richedit.SelectAll;
  Richedit.CopyToClipboard;
  WordApp.ActiveDocument.ActiveWindow.Selection.Paste;
  WordApp.selection.paste;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灵芸 2024-09-16 21:33:49

尝试省略代码的最后一行

Try leaving out the last line of your code

早茶月光 2024-09-16 21:33:49

你想以此结束吗?

test text
test text

但只得到这个?

test text

如果是这样,那么“选择”可能会导致它将相同的数据粘贴到相同的选择中,因此第二个粘贴会擦除第一个粘贴。

Are you trying to end up with this?

test text
test text

But only getting this?

test text

If so, then maybe the "selection" is causing it to paste the same data into the same selection, thus the 2nd paste wipes out the first one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文