1

I've got an app that is meant to take a string, and write it into the clipboard at 30 pt font, Courier New. The code below works great for word, outlook, basically anything that accepts RTF formatted text. it isn't being seen as anything but plain text in Teams, unfortunately, which is the most common use case, and the most important by far. Does anyone have any insight on how to format it in a way that MS Teams will recognize?

private void ExecuteCopy(String lap)
        {
            // Escape Special Characters for RTF
            StringBuilder rtf = new StringBuilder();
            StringBuilder html = new StringBuilder();
            html.Append("<p style = \"font - family:'Courier New'; font - size:30px\">");

            foreach (char c in lap)
            {
                rtf.Append(GetRtfEncoding(c));
                html.Append(c);
            }

            html.Append("</p>");

            // Add both RTF and plain Text into clipboard
            DataObject data = new DataObject();
            data.SetData(DataFormats.Text, lap);
            data.SetData(DataFormats.Rtf, @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier New;}}\f0\fs60 " + rtf.ToString() + "}", true);
            data.SetData(DataFormats.Html, html, true);
            Clipboard.SetDataObject(data);
        }
tatortot
  • 25
  • 1
  • 3

1 Answers1

0

Teams doesn't support rich HTML formatting like this, unfortunately. The best you'll get is some limited markdown support, but at least it's something. See here for more: https://support.microsoft.com/en-ie/office/use-markdown-formatting-in-teams-4d10bd65-55e2-4b2d-a1f3-2bebdcd2c772 .

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • ahh, yeah that looks like the answer. which doesn't seem to work through the clipboard :/ I'll leave the question open for a bit longer in the hopes someone has something usable for me though – tatortot Apr 19 '21 at 12:34
  • What do you mean about it not working, out of curiosity? – Hilton Giesenow Apr 19 '21 at 14:42
  • it just adds the # and ` characters as characters, it doesn't parse them as markdown at all. It's frustrating because it'll match Word or other office apps - I can paste into word then into Teams, but that seems to be the only way to get it to work as needed. at least for now :/ – tatortot Apr 20 '21 at 16:07
  • wierd, but good to know, thanks for the update – Hilton Giesenow Apr 20 '21 at 16:45