HTML to Clipboard

  • Thread starter Thread starter Robert Manookian
  • Start date Start date
R

Robert Manookian

Can anybody show me how to place simple HTML into the clipboard that can be
copied to an office application? I've tried setting simple using the
following:
Dim strHTML As String = "<P>The <B><FONT
size='4'><U>Clipboard</U></FONT></B>" & _

"is <FONT size='5'>Cool!</FONT></P>"

' Place HTML version in DataObject

Dim myDataObject As New DataObject()

myDataObject.SetData(DataFormats.Html, strHTML)

' Now place myDataObject, and thus all formats on the Clipboard

Clipboard.SetDataObject(myDataObject, True)

Can not paste this HTML into Word or Excel.
 
When you copy some html from ie to paste into word/excel it has its special
format. Copy something from a web page and then use the following code to
look at it

IDataObject data = Clipboard.GetDataObject();
string blah = (string)data.GetData(System.Windows.Forms.DataFormats.Html);
Console.WriteLine(blah);

You will need to format your html like this for word etc.

Peter
 
Back
Top