Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Insert HTML Formatted Text On Word Document Using C# [modified]

Insert HTML Formatted Text On Word Document Using C# [modified]

Scheduled Pinned Locked Moved C#
csharphtmlcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Niks7755
    wrote on last edited by
    #1

    Hello, I have created word document using Microsoft.Interop Library,for that i have to insert text which is contain html tags,now i need to formatt that text and putup that html text on word document,means need to put up html formatted text on word document using c#. Thanks,

    nikunj padaliya

    modified on Tuesday, May 26, 2009 12:44 AM

    T 1 Reply Last reply
    0
    • N Niks7755

      Hello, I have created word document using Microsoft.Interop Library,for that i have to insert text which is contain html tags,now i need to formatt that text and putup that html text on word document,means need to put up html formatted text on word document using c#. Thanks,

      nikunj padaliya

      modified on Tuesday, May 26, 2009 12:44 AM

      T Offline
      T Offline
      TALHAKOSEN
      wrote on last edited by
      #2

      it is late answer i know )) Create a word doc, and insert a bookmark into that, then you can paste your string to that bookmarked place wit trhe code below private void button2_Click(object sender, EventArgs e) { WordApp = new Word.ApplicationClass(); fileName = @"yourworddocname"; Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref Format, ref realencode, ref isVisible, ref missing, ref missing, ref missing, ref missing); WordApp.Visible = true; WordApp.Visible = true; bookmarkdene(aDoc, "yourbookmarinworddoc", yaz); } private static string HtmlClipboardData(string html) { StringBuilder sb = new StringBuilder(); Encoding encoding = Encoding.GetEncoding("utf-8"); string Header = @" Version: 1.0 StartHTML: {0:000000} EndHTML: {1:000000} StartFragment: {2:000000} EndFragment: {3:000000} "; string HtmlPrefix = @" !DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//TR"" html head meta http-equiv=Content-Type content=""text/html; charset={0}"" head body !--StartFragment-- "; HtmlPrefix = string.Format(HtmlPrefix, encoding.WebName); string HtmlSuffix = @" <!--EndFragment--> </body> </html> "; // Get lengths of chunks int HeaderLength = encoding.GetByteCount(Header); HeaderLength -= 16; // extra formatting characters {0:000000} int PrefixLength = encoding.GetByteCount(HtmlPrefix); int HtmlLength = encoding.GetByteCount(html); int SuffixLength = encoding.GetByteCount(HtmlSuffix); // Determine locations of chunks int StartHtml = HeaderLength; int StartFragment = StartHtml + PrefixLength; int EndFragment = StartFragment + HtmlLength; int EndHtml = EndFragment + SuffixLength; // Build the data sb.AppendFormat(Header, StartHtml, EndHtml, StartFragment, EndFragment); sb.Append(HtmlPrefix); sb.Ap

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups