Re: Using Word's clipboard from .NET

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Scott M. (s-mar_at_nospam.nospam)
Date: 02/25/05

  • Next message: Thomas Delany: "Structure Marshalling Question"
    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,
    >


  • Next message: Thomas Delany: "Structure Marshalling Question"

    Relevant Pages

    • [OT] Re: Asking if elements in struct arre zero
      ... >> What, besides source code, would be easier to read in monospace? ... > effort of formatting it in a variable-width font, ... Keith is right: plain ASCII text is one of the easiest media to ... If HTML postings were generally supported, ...
      (comp.lang.c)
    • Re: Word v.X freezes up when handling bullet points
      ... > substitute default list formatting. ... > Format>Bullets and Numbering bullets or numbers is even more likely to cause ... > because the result is NOT HTML. ... > making lightweight web pages suited for the Internet of yesteryear when ...
      (microsoft.public.mac.office.word)
    • Re: Cant read email
      ... Antivirus - just one more thing that complicates trying to send as a html ... the page...in other words, no special formatting. ... Now convert the publication to a PDF by File> ... My email client is html enabled, but I have it set to not download ...
      (microsoft.public.publisher)
    • Re: automating the insertion of HTML tables (or tab delimited files)
      ... Word is overwriting the obvious intent of the HTML to center the table ... during updates" selector. ... the HTML formatting to take precedence, ... that formatting will be applied to the field code result. ...
      (microsoft.public.word.vba.general)
    • Re: EX07: force remote message to plain text
      ... Thank you, Robbin, but the ContentType is already set to Mimetext, yet the ... recipients are getting both text and html in their messages. ... and formatting. ... " MimeHtmlText converts messages to MIME messages that use HTML ...
      (microsoft.public.exchange.admin)