c#, How to create and assign a string to clipboard so that when pasted MS Word will accept it as a table?

Issue

This Content is from Stack Overflow. Question asked by kas

I have to find a way to generate a string so that when set and then pasted to a Word document it will display a table.

I did some research about this, but non of them seem to work. One of the things i tried was to generate a string of html , then setting it as the clipboard data and passing format as html.

string html = @"<html><body><table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  </table></body></html>";

Clipboard.SetData(DataFormats.Html, html);

but it did not work, nothing was pasted to word doc when i tried. And then when i set Data format as text (DataFormats.Text) it was pasted but only as text , not as a table.

Hoping for some help
Thanks in advance!



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?