473,659 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Word Template

Hello everyone.
I have a question that I tried to find an answer over the weekend but did
not succeeded.
I have a Word template with a couple of "tags" ( <<My Tag>>) that I need to
replace with data from the DB. Please point me in the right direction on how
to approach this. Code samples, links or articles. Anything would work.

Thank you very much in advance.
Nov 15 '05 #1
2 3073
Ruslan,

In order to get data from the database, you are going to have to use the
classes in one of the following namespaces:

System.Data.Sql Client
System.Data.Ole Db
System.Data.Odb c

Which you use is dependent on the datbase technology you are using. If
you have a different provider that you need to use, you can use that.

To access Word in .NET, you will have to automate it. In order to do
that, check out the knowledge base article titled "HOW TO: Automate Word
from Visual C# .NET to Create a New Document", located at (watch for line
wrap):

http://support.microsoft.com/default...b;EN-US;316384

While this example shows how to perform rudimentary operations in Word
from C#, it shows you how to interact with it, which you can use as a base
for whatever you are trying to do.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ruslan Shlain" <rs*****@hotmai l.com> wrote in message
news:O0******** ******@TK2MSFTN GP12.phx.gbl...
Hello everyone.
I have a question that I tried to find an answer over the weekend but did
not succeeded.
I have a Word template with a couple of "tags" ( <<My Tag>>) that I need to replace with data from the DB. Please point me in the right direction on how to approach this. Code samples, links or articles. Anything would work.

Thank you very much in advance.

Nov 15 '05 #2
EX:

object nRef = Type.Missing;
object falseRef = false;

object trueRef = true;

object oEndOfDoc = "\\endofdoc "; /* \endofdoc is a predefined bookmark */
try

{

word = new Word.Applicatio n();

word.Visible = false;

object path = this.templateDi rectory + this.ClientTemp late;
Word._Document dc = word.Documents. Add(ref path,ref nRef,ref nRef,ref
trueRef);
//Date

object dDisplay = "Date";

dc.Bookmarks.It em(ref dDisplay).Range .Text = this.DateDispla yed;
//App names

//First name

object fName = "FirstName" ;

dc.Bookmarks.It em(ref fName).Range.Te xt = this.FirstName;

object lName = "LastName";

dc.Bookmarks.It em(ref lName).Range.Te xt = this.LastName;

object addr = "Address";

dc.Bookmarks.It em(ref addr).Range.Tex t = this.Address;

object aCity = "City";

dc.Bookmarks.It em(ref aCity).Range.Te xt = this.City;

object aState = "State";

dc.Bookmarks.It em(ref aState ).Range.Text = this.State;

object aZip = "Zip";

dc.Bookmarks.It em(ref aZip).Range.Tex t = this.Zip;

object openName = "OpenName";

dc.Bookmarks.It em(ref openName).Range .Text = this.FirstName;

object openNameLast = "OpenNameLa st";

dc.Bookmarks.It em(ref openNameLast).R ange.Text = this.LastName;

object sig = "Signature" ;

dc.Bookmarks.It em(ref sig).Range.Text = this.Signature;
///Use this name to save this file

object fileName = generateFileNam e();

object savePath = this.WorkingDir ectory + fileName;

dc.SaveAs(ref savePath,ref nRef,ref nRef,ref nRef,ref falseRef,ref nRef,ref
nRef,

ref nRef,ref trueRef,ref nRef,ref nRef);

return savePath.ToStri ng();

}

catch (Exception ex)

{

this.lastError = ex.ToString();

}

finally

{

if (word != null)

word.Quit(ref falseRef,ref nRef,ref nRef);

}
HTH,

Alex
"Ruslan Shlain" <rs*****@hotmai l.com> wrote in message
news:O0******** ******@TK2MSFTN GP12.phx.gbl...
Hello everyone.
I have a question that I tried to find an answer over the weekend but did
not succeeded.
I have a Word template with a couple of "tags" ( <<My Tag>>) that I need to replace with data from the DB. Please point me in the right direction on how to approach this. Code samples, links or articles. Anything would work.

Thank you very much in advance.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7409
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the collection that I need. To begin, I am using xsltproc that conmes with Cygwin as my processor. I have no particular affinity to this processor except that it is open source and standards compliant. I don't like M$, but if using a M$ processing...
0
1539
by: Sudipto Sen | last post by:
================== Problem Description ================== Following code is for 1. Load a Word Template called CustomerInfo1.dot 2. CustomerInfo1.dot is a normal Word Template with Form fields 3. After opening a document on that template, I put "2" in all the fields for test Problem is,
2
12511
by: Steve M | last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want to output a new Word .doc file with the template filled in with the record I've generated. (To refresh your memory, in Word a mailmerge is achieved by a) under Tools -> Letters and Mailings, check off Show Mail Merge Toolbar; b) open a document...
4
21475
by: Paolo | last post by:
Hello, I am trying to create a procedure to export my Access data to a word template. I would like to export data from two tables to a word file at the same time. My two tables are named CASES AND CLIENTS. The word (it is a template) is named MASTER To store data, I have created two forms named CASES and MASTER. Since both forms have a lot of fields, I have added the form CLIENTS as a SubForm on the form CASES.
6
2676
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we were using without issue previous to the switch: 'Start Word and create a new doc from the template Set objWord = CreateObject("Word.Basic") objWord.AppMaximize "Microsoft Word", 1 objWord.FileNew Template:=StrTemplPath & "letter.dot"
0
4024
by: Raj Singh | last post by:
I am facing a problem with Visual C# 2003 and MS Word XP. I am using a customized template for Word and in that template I have defined some bookmarks. I am trying to create a Word document based on the customized template, reading all the bookmarks and replacing them with desired values, resulting in a new one page document being created which is then saved. This all works fine but when I try to extend the process so that the template...
4
2691
by: Nikhil Patel | last post by:
Hi all, I need to generate a word document and save it on the server from an ASP.Net application. Basically I want to load a word template and insert some field values from a dataset and save the final output as a Word document. I know there are different options to do this. But I can't decide which one I should use. I don't want to use automation on the server because of scalability issues and it is not recommended by Microsoft. So I am...
2
13504
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a template file containing the field names Line1 thru Line5 for each record to be printed. If a...
7
6237
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the user and populated (with info from an Access database) at run-time, then saved as Word documents. The program I have coded works fine -- it does what I need it to do. But it has two problems: (1) it runs very slowly, and (2) it does not seem to...
12
10653
by: Dixie | last post by:
Is there a way to shell to Microsoft Word from Access and load a specific template - using VBA? dixie
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.