2

I am developing an Exam Software in which I have used Subscript and superscript. so I have to store the Questions in HTML in the Database, Now i want to write those questions with HTML tags to the word, I tried Using Apache POI Library, here is the sample text :

  <html>
  <head> </head>
  <body><font face="Shruti"> MY QUESTION </font>
  </body>
  </html> 

but when I am trying to write text in word Document using apache poi , it is showing the HTML tags

2
  • Are you trying to set explicit formatting rules in POI, or are you just blindly writing HTML tags into a word file and looking confused when they rather unsurprisingly turn up in the resultant file? Commented Oct 26, 2013 at 22:31
  • I looked at those formatting rules in POI , but I did not get the one to write HTML in doc Commented Oct 28, 2013 at 6:05

1 Answer 1

2

You can add your HTML as an AltChunk, and have Word convert it to native docx content when the file is first opened.

If you need to convert to native docx content in Java, you can use docx4j-ImportXHTML

Disclosure: I manage that repo.

Sign up to request clarification or add additional context in comments.

2 Comments

I guess you did not get my Question or May be i was not able to Describe it properly, I am not converting an HTML into DOC or a DOC into HTML, In my application content type of the text pane is html so i am getting value in the html format, i want to write the same into the without HTML tags
Isn't that a simple case of converting HTML to DOC? If you want to write it yourself from scratch, there are 2 parts to your problem. First, parsing the HTML to get the text. You might look at a 'tidy' program, then SAX or DOM parsing. Second, converting that text to docx/doc/rtf format. Presumably you'll want to differentiate between block and inline content. What about tables, images, lists?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.