We help IT Professionals succeed at work.

How to create tokens in a Word 2007 document

Hello,

I'm trying to come up with a solution to generate reports from my asp.net/MSSQL application.  To that end, I'm looking at this codeproject example by Rahul Singla.  

Step 1 in his "How to use the code" section says "Prepare a Word or Writer document (not template) with tokens in it".  

Uhhhh...  :D

Can anyone point me to a resource that would describe how to accomplish that?  

(I think I'm going to be breaking out the Visine and coffee!)

TIA
Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014
Commented:
There are other, potentially better, options available. What sort of reports do you want?
GrahamSkanRetired
Top Expert 2012

Commented:
By tokens, the author of that article seems to be referring to some distinctive text that the template designer would insert, to be replaced later with actual data.

Word has a Bookmarks facility that is designed to do that, thought this visible 'target' text could help in designing the document layout.

Author

Commented:
Code Cruiser!  You gonna save me again? :D  

Ok - here's my situation.  I'm working on a project where my programmer is having some tough things going on at his real job and I'm doing everything I can to try to pick up the slack.  Nothing against the guy - he's brilliant and has always been there for me - it's just a tough time for him and we've all been there.  But because of this I'm in a huge time crunch and I've already blown by two deadlines.  To make things worse, although I've learned a BUNCH over the last couple months, I don't really know how to code my way out of a paper bag.  

Anyway - I have data in a SQL 2008 database and he's written some SP's to generate report data.  The data is simple stuff like Name, DOB, ID numbers, etc.  In the past, we've done stuff like exporting to excel from an HTML grid but, it looks cheesy to me and I'd like to have something that's formatted nicely that they could print from Word or save to PDF or whatever - as long as it looks nice.

So, what I envision is this - the end user goes to a reports page (reports.aspx).  On that page are several form components (date selectors, dropdown lists and buttons).   They select filter criteria from the components and click a button which triggers the SP and finally they are prompted to save the report in a Word or Excel document.  

The documents would contain lists of data
Name         | DOB          | ID        |
Doe, John  |03/12/1968| 12345 |
Doe, Jane  |02/12/1922| 23456 |
etc

I'd also like to have header and footer information, report title, subheadings etc, and be able to have control over the formatting of the document.  

Given all that - what do you recommend?  (jumping out of the window is the only thing I've come up with thus far :P)

THANKS for the response.  

Author

Commented:
Hi Graham,

So do you mean to say that I would just create my docx document and just type text in the document to represent "tokens"?

For instance, to use my example in the response above - just type something like this into a Word document and then the code would handle the replacements?
Name          | DOB          | ID         |
[$NAME$]   | [$DOB$]    | [$ ID $] |

Thanks again.
Most Valuable Expert 2012
Top Expert 2014
Commented:

Author

Commented:
Thanks CC.  Given my situation, you think I should focus on that first link?  
GrahamSkanRetired
Top Expert 2012
Commented:
Sorry for the delay. I think that was the intention of the article-writer.

Almost certainly you will be needing some code, and it looks as if you are creating a table, but all you need in the template would be a table with the header and perhaps one other row. I don't see any point in having tokens for that.

Author

Commented:
Thanks guys.