Re: Using Word's clipboard from .NET
From: Scott M. (s-mar_at_nospam.nospam)
Date: 02/25/05
- Previous message: Tim Mavers: "Re: Using Word's clipboard from .NET"
- In reply to: Tim Mavers: "Re: Using Word's clipboard from .NET"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 25 Feb 2005 14:30:28 -0500
If you must hold on to the formatting, it wouldn't be difficult at all to
set up a case statement that checks for the HTML formatting, strips out the
HTML tags but then applies this formatting to the text via the Selection
object.
If you really want to use the clipboard, the IDataObject interface (which
the clipboard supports for setting and getting data) has a data format
argument as I've previously mentioned. HTML is one of these formats. If
you use this format, your data will retain the formatting of the HTML
without showing the HTML. The reason you are seeing HTML when you paste is
that you are using the default format (text) and so all the embedded HTML
tags are just showing up as part of the text.
See these help in VS.NET for more:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsformsdataformatsmemberstopic.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsformsdataformatsclasshtmltopic.htm
As an example of what I mean, try this:
Open Word and type ABC
Make that text bold using the Bold button.
Save the file as a Rich Text File (.rtf)
Close Word
Open the .rtf document using Notepad
You will see that instead of applying the formatting to the characters, you
wind up seeing ALL the formatting instructions for those characters.
Essentially you are saying show me the data (all the data) as text. This is
what you are seeing when you past HTML as text.
"Tim Mavers" <webview@hotmail.com> wrote in message
news:3uqdnfC2F7uX6oLfRVn-oA@giganews.com...
> "Scott M." <s-mar@nospam.nospam> wrote in message
> news:OoqE$M2GFHA.3068@tk2msftngp13.phx.gbl...
>> The SetData and GetData methods take a DataFormat agument where you can
>> specify the text formatting. If you use these, then the formatting will
>> be preserved as you copy/paste.
>>
>> Forgive me, but I'm still not clear on how/why you have formatted text in
>> your DB. You are saying that you are storing data in the DB as HTML?
>
> Yes, I am storing text that can be formatted in HTML in the DB. It's not
> complex HTML, but just styling.
>
>> If the answer is yes:
>> I would forget the clipboard all together and just use Word's
>> Selection object to insert and format the text. You have said that this
>> works but you get actual HTML tags inserted as well. No problem, just
>> parse anything starting with < and ending with > out of the string.
>
> I need to preserve the formatting. For example, the content contains text
> formatted with HTML, i.e. words could be BOLD <b> or could contain lists
> <ul> <ol>. So I can't parse that out--that is what I need. When you copy
> content into the clipboard (HTML content) and paste it with Word, Word
> will convert the text (html) to its own format and still keep things style
> intact (bold, lists, font size, etc.). When I use Selection.Text, I get
> the actual html tags in the Word doc.
>
> That is why I am trying to use the clipboard from .NET directly, but it
> doesn't seem to be working.
>
> Thanks,
>
- Previous message: Tim Mavers: "Re: Using Word's clipboard from .NET"
- In reply to: Tim Mavers: "Re: Using Word's clipboard from .NET"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|