Now lets write the code behind code. What we are going to do here is we are generating a dynamic html content based on the textbox value. Also we are writing one table with 2 cell and at last we are adding some text.

Here is the component that generates document based on the custom template. The documents are generated from the sharepoint list ... so the data is pulled from the list item into the document on the fly:
http://store.sharemuch.com/products/generate-word-documents-from-sharepoint-list

Generating Microsoft Word documents using HTML is a far better approach than the Office COM (MS Office automation) one. This solution is robust but is probably limited in terms of charts, pictures, and all other MS Word concepts that are at least hard to achieve. This was a MS Word document generation solution for some quite time in our company, then we purchase Docentric toolkit (http://www.docentric.com) which pushed our previous solution into oblivion. It really helped at building templates and also ther maintinance is much better (customers frequently want to change copany logo in header, add a data field, ...). Before choosing the product we tested couple of other commercial products and docentric proved far better, simply for the following reasons: document templates and a very powerfull Word add-in.

Here is another .NET WORD Component for generating word files and also for reading, modifying and even converting word files to other formats. You can also get codes from their documentation page also for adding MS Word features in your .NET Applications: