【问题标题】:Copy paste from clipboard in c# windows text box in the same format从剪贴板复制粘贴到 c# windows 文本框中,格式相同
【发布时间】:2013-07-11 17:27:15
【问题描述】:

我想从 word 或 excel 或任何其他外部应用程序复制到我的应用程序文本框或 Richtextbox 并以相同格式保存和检索数据,这将用作发送电子邮件的消息正文。

有人可以指导我吗?

【问题讨论】:

  • 您需要使用 RichTextBox 来获得接收格式化文本的希望。 TextBox 只是纯文本。 Sandeep 的链接可以回答您的问题。
  • IMO 不重复,OP 不会 RTF,因为 RTF 不适合电子邮件

标签: c# .net richtextbox clipboard richtext


【解决方案1】:

您可以从 Word 或 Excel(或任何其他应用程序)中获取 html 格式的内容,这对于电子邮件来说是理想的:

string data = Clipboard.GetText(TextDataFormat.Html);

您将获得 html 字符串,但前面有一些标题,请查看下面的链接以获取如何处理它的示例:

http://blogs.msdn.com/b/jmstall/archive/2007/01/21/html-clipboard.aspx

http://theartofdev.wordpress.com/2012/11/11/setting-html-and-plain-text-formatting-to-clipboard/

警告 word 生成的 html 实在是太可怕了,所以可能有些人在查看带有凌乱 html 的此类邮件时会遇到问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多