Click here to Skip to main content
15,895,557 members
Home / Discussions / C#
   

C#

 
GeneralRe: private/public get/set Pin
George_George3-May-08 4:40
George_George3-May-08 4:40 
AnswerRe: private/public get/set Pin
Luc Pattyn3-May-08 5:40
sitebuilderLuc Pattyn3-May-08 5:40 
GeneralRe: private/public get/set Pin
PIEBALDconsult3-May-08 5:46
mvePIEBALDconsult3-May-08 5:46 
GeneralRe: private/public get/set Pin
George_George3-May-08 19:38
George_George3-May-08 19:38 
GeneralRe: private/public get/set Pin
George_George3-May-08 19:37
George_George3-May-08 19:37 
GeneralRe: private/public get/set Pin
Luc Pattyn3-May-08 22:49
sitebuilderLuc Pattyn3-May-08 22:49 
GeneralRe: private/public get/set Pin
George_George4-May-08 0:00
George_George4-May-08 0:00 
QuestionAutomated Mail Merge: Help! Pin
Member 42630173-May-08 2:44
Member 42630173-May-08 2:44 
I have read all the mail merge threads and articles I could find, and I'm a little frustrated at the moment... I really hope someone could help me here!

I found a very simple approach to merging, which I've implemented, and the code is show below:

//OBJECT OF MISSING "NULL VALUE"<br />
            Object oMissing = System.Reflection.Missing.Value;<br />
<br />
            //OBJECTS OF FALSE AND TRUE<br />
            Object oTrue = true;<br />
            Object oFalse = false;<br />
            DataRow row;<br />
<br />
            //CREATING OBJECTS OF WORD AND DOCUMENT<br />
            Word.Application oWord = new Word.Application();<br />
            Word.Document oWordDoc = new Word.Document();<br />
<br />
            //DEFINE FILE<br />
            openFileDialog.ShowDialog();<br />
            openFileDialog.Filter = "Word Template File (*.dot)|*.dot|Word File (*.doc)|*.doc|All files (*.*)|*.*";<br />
<br />
            //SETTING THE VISIBILITY TO TRUE<br />
            oWord.Visible = true;<br />
<br />
            //THE LOCATION OF THE TEMPLATE FILE ON THE MACHINE<br />
            Object oTemplatePath = openFileDialog.FileName;<br />
<br />
            //ADDING A NEW DOCUMENT FROM A TEMPLATE<br />
            oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);<br />
<br />
            bs_results.MoveFirst();<br />
            row = ((DataRowView)bs_results.Current).Row;<br />
<br />
            foreach (Word.Field myMergeField in oWordDoc.Fields)<br />
            {<br />
                String fieldtext = myMergeField.Code.Text;<br />
<br />
                if (fieldtext.StartsWith(" NEXT"))<br />
                {<br />
                    if (bs_results.Position == bs_results.Count-1) break;<br />
                    bs_results.MoveNext();<br />
                    row = ((DataRowView)bs_results.Current).Row;<br />
                    myMergeField.Code.Text = String.Empty;<br />
                }<br />
<br />
                if (fieldtext.Contains("firstname"))<br />
                {<br />
                    myMergeField.Select();<br />
                    oWord.Selection.TypeText(row["firstName"].ToString());<br />
                }<br />
                if (fieldtext.Contains("lastname"))<br />
                {<br />
                    myMergeField.Select();<br />
                    oWord.Selection.TypeText(row["lastName"].ToString());<br />
                }<br />
                if (fieldtext.Contains("cellphone"))<br />
                {<br />
                    myMergeField.Select();<br />
                    oWord.Selection.TypeText(row["phoneCell"].ToString());<br />
                }<br />
            }


This is simple, and to the point, and works well. It has limitations though. It loops merge fields, so there are only so many labels created for example as are propagated in the .dot template file, as apposed to rows in the datatable.

My QUESTION:
How do I either propagate labels based on the row count, or do it completely different??

I basically have a results datatable with all the data I need, and would like to mail merge that data to labels in a Word template.

Any help would be appeciated! PLEASE!
Questioninterface implementation Pin
George_George3-May-08 2:19
George_George3-May-08 2:19 
AnswerRe: interface implementation Pin
Roger Alsing3-May-08 2:28
Roger Alsing3-May-08 2:28 
GeneralRe: interface implementation Pin
George_George3-May-08 2:31
George_George3-May-08 2:31 
AnswerRe: interface implementation Pin
snorkie3-May-08 2:30
professionalsnorkie3-May-08 2:30 
GeneralRe: interface implementation Pin
George_George3-May-08 2:33
George_George3-May-08 2:33 
GeneralRe: interface implementation Pin
snorkie3-May-08 2:41
professionalsnorkie3-May-08 2:41 
GeneralRe: interface implementation Pin
George_George3-May-08 2:43
George_George3-May-08 2:43 
AnswerRe: interface implementation Pin
tgrt3-May-08 14:51
tgrt3-May-08 14:51 
GeneralRe: interface implementation Pin
George_George3-May-08 18:15
George_George3-May-08 18:15 
GeneralRe: interface implementation Pin
tgrt4-May-08 4:07
tgrt4-May-08 4:07 
QuestionA static riddle (or: how to avoid lazy instantiation?) Pin
Luca Leonardo Scorcia3-May-08 1:45
professionalLuca Leonardo Scorcia3-May-08 1:45 
AnswerRe: A static riddle (or: how to avoid lazy instantiation?) Pin
carbon_golem3-May-08 4:15
carbon_golem3-May-08 4:15 
Questionopening pdf file in windows application using c# Pin
maruthi2-May-08 23:50
maruthi2-May-08 23:50 
AnswerRe: opening pdf file in windows application using c# Pin
Ed.Poore2-May-08 23:59
Ed.Poore2-May-08 23:59 
GeneralRe: opening pdf file in windows application using c# Pin
maruthi3-May-08 0:29
maruthi3-May-08 0:29 
GeneralRe: opening pdf file in windows application using c# Pin
Ed.Poore3-May-08 0:49
Ed.Poore3-May-08 0:49 
GeneralRe: opening pdf file in windows application using c# Pin
maruthi3-May-08 1:10
maruthi3-May-08 1:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.