1

How can I convert an HTML string (not a file) to a .docx file using Microsoft Office Interop Word? I have found a number of sources that offer the conversion using an HTML file, but not a string. My goal is to avoid creating an HTML file (ultimately even a .docx file, which I'll turn into a BLOB and send it in an e-mail).

Nathan A
  • 11,059
  • 4
  • 47
  • 63
Lukas
  • 2,885
  • 2
  • 29
  • 31
  • What is an HTML string? HTML doesn't have variables... – Coda17 Jun 30 '14 at 16:56
  • Simple HTML containing basic formatting tags such as
    Hello World!
    – Lukas Jun 30 '14 at 16:57
  • What's the reason for the down vote? It was a legitimate question asked after over an hour worth of research with no avail. – Lukas Jun 30 '14 at 16:59
  • What exactly are you trying to do? You're trying to create a .docx file and insert some HTML? What are you "converting"? It sounds like you just need to create a .docx file and insert the text, in which case you just need to Google for .docx file creation. – Coda17 Jun 30 '14 at 17:01
  • I have an HTML string, say Hello World! and I want this to be saved as .docx file, where if someone opens the document, they will see the writing "Hello World" in bold red letters. I want to generate this dynamically using C# code (via Interop.Word). – Lukas Jun 30 '14 at 17:04
  • Coda, you may be onto something, I didn't think of it from that approach; inserting html into a word.document instead of trying it open it from a string. Thank you, I'll look into that. – Lukas Jun 30 '14 at 17:06
  • 1
    Do not use Interop on the server side. Microsoft says [don't do it](http://support.microsoft.com/kb/257757), and I know from experience that it will cause problems. Instead, use a library such as [DocX](http://www.codeproject.com/Articles/660478/Csharp-Create-and-Manipulate-Word-Documents-Progra) or the [Open XML SDK](http://msdn.microsoft.com/en-us/library/office/bb448854(v=office.15).aspx). – mason Jun 30 '14 at 17:13
  • Thank you Mason. I assure you I've overcome the problems associated with using Interop. It was quite something let me tell ya, but after weeks of troubleshooting in the past, the server is now stable and handles Interop well. Trust me though, if I had to do it over, I would have opted in for another venue. – Lukas Jun 30 '14 at 17:22
  • Coda17, I am developing a solution based on your idea. If you can write your suggestion of opening a document and adding the html in there, I will give you credit for the answer. While the HTML itself won't hold, I am able to manipulate the text by other means and it was your idea that set me on the right path :) – Lukas Jun 30 '14 at 20:14

0 Answers0