如何将文本放入剪贴板以便将其粘贴为Word中的表格?

发布于 2024-07-09 05:04:35 字数 67 浏览 5 评论 0原文

在 MS Office 中使用 VBA,如何将文本添加到 Windows 剪贴板,以便将其作为表格粘贴到 Word 中?

Using VBA in MS Office, how do I add text to the Windows clipboard so that it will paste into Word as a table?

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

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

发布评论

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

评论(4

笑,眼淚并存 2024-07-16 05:04:35

Windows 剪贴板支持多种格式。 当您想要将内容放入剪贴板时,您可以对 RegisterClipboardFormat() 进行一次或多次调用,告诉它您将放置在剪贴板上的对象的格式,然后调用 SetClipboardData(),它实际上将数据放入剪贴板。

如果您希望能够将表格粘贴到 Word 中,那么 HTML 是最容易使用的格式。 只要将 HTML 表格复制到剪贴板上,它就会正确粘贴到 Word 中,前提是您首先将剪贴板数据注册为 HTML 对象。

我会给你一些代码,但最简单的方法是引用 MSDN 上的示例:

How to add HTML code to使用 Visual Basic 的剪贴板

此页面甚至显示了将 HTML 表复制到剪贴板的示例。

The Windows clipboard supports multiple formats. When you want to place things in the clipboard, you make one or more calls to RegisterClipboardFormat() telling it the formats of the objects you will be placing on the clipboard, followed by calls to SetClipboardData() which actually places the data into the clipboard.

If you want to be able to paste a Table into Word, then HTML is the easiest format to work with. Just copy an HTML table onto the clipboard, and it will paste correctly into Word, provided that you first register the clipboard data as an HTML object.

I'd give you some code, but it's easiest to just reference an example on MSDN:

How to add HTML code to the clipboard using Visual Basic

This page even shows an example of copying an HTML table onto the clipboard.

我乃一代侩神 2024-07-16 05:04:35

您是否尝试过将其格式化为 HTML 表格?

Have you tried formatting it as a HTML table?

对风讲故事 2024-07-16 05:04:35

我已经有一段时间没有做过任何Windows编程了,但我似乎记得你注册了对象的格式。 事实上,您可以注册多个不同格式的对象,粘贴应用程序可以在它们之间进行选择(例如使用 Word 的选择性粘贴选项)。

我会尝试创建一个 Word 表格对象,用您的数据填充它的单元格,然后将其复制到剪贴板。

It's been a while since I've done any Windows programming, but I seem to recall that you register the format of the object. In fact, you can register multiple objects of different formats and the pasting application can choose between them (such as with Word's Paste Special option).

I would try to create a Word table object, fill it's cells with your data and then copy that onto the clipboard.

热情消退 2024-07-16 05:04:35

剪贴板很棒...但是使用它来保存程序的输出以粘贴到 Word 中似乎有点粗略。 您正在尝试做的事情是什么,而您可能应该以其他方式做?

The Clipboard is great... But something seems a little sketchy about using it to hold the output from your program to paste into Word. What is it that you're trying to do that you probably should be doing some other way?

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