Click here to Skip to main content
15,879,535 members
Home / Discussions / C#
   

C#

 
AnswerRe: Using StringBuilder inside another class? Pin
Luc Pattyn21-Sep-09 9:40
sitebuilderLuc Pattyn21-Sep-09 9:40 
GeneralRe: Using StringBuilder inside another class? Pin
helfri6221-Sep-09 10:00
professionalhelfri6221-Sep-09 10:00 
GeneralRe: Using StringBuilder inside another class? Pin
Luc Pattyn21-Sep-09 10:10
sitebuilderLuc Pattyn21-Sep-09 10:10 
QuestionThread reach synchronized code block Pin
FJJCENTU21-Sep-09 6:33
FJJCENTU21-Sep-09 6:33 
AnswerRe: Thread reach synchronized code block Pin
N a v a n e e t h21-Sep-09 7:01
N a v a n e e t h21-Sep-09 7:01 
Question[SOLVED] File Encryption Broken [modified] Pin
Ben Magee21-Sep-09 6:26
Ben Magee21-Sep-09 6:26 
NewsRe: File Encryption Broken Pin
Ben Magee21-Sep-09 6:41
Ben Magee21-Sep-09 6:41 
QuestionPlease help me about working with Word - Very URGENT Pin
designervc21-Sep-09 6:18
designervc21-Sep-09 6:18 
Hi everybody,
Now, I have to create a Word file from a word template, i have faced a difficult problem when replace a text on Word file.

In my file Word template, I have 5 lines with the text is "Name_of_Applicant". (Please note that the BOOKMARK will not use in this template)

In my C# code, I would like to do as follows:
1. Find the text "Name_of_Applicant" and Replace it.

2. I do Foreach(Word.Range tmpRange in oWordDoc.StoryRanges) { ... do something ... }. In the FOR loop, I will replace 5 lines as "Name_1", "Name_2", .... , "Name_5".

private void OpenWord_Click(object sender, EventArgs e)
{
    object oMissing = System.Reflection.Missing.Value;

    oWord = new Word.Application();
    oWordDoc = new Word.Document();
    oWord.Visible = true;
    oWord.NormalTemplate.Saved = true;

    oTemplatePath = "D:\\Template.doc";
    oWordDoc = oWord.Documents.Open(ref oTemplatePath, ref oMissing, ref readOnly, ref readOnly, ref oMissing, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

    object findText = "Name_of_Applicant";
    try
    {
        int index_name = 0;
        object oReplace = "Name_" + index_name.ToString();
        foreach (Word.Range tmpRange in oWordDoc.StoryRanges)
        {
            //The Paramater 11 is the REPLACED text
            if (oWord.Application.Selection.Find.Execute(ref findText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oReplace, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing))
            {
                index++;
            }
        }
    }
    catch
    {
        MessageBox.Show("The text could not be located.");
    }
}



The code above is only one of many different way that I have tried, but I have only replace the FIRST line.

Do you have any idea for this problem. It's will be appreciate your help so much.

Thank you
QuestionSocket programming problem Pin
JLP18821-Sep-09 6:07
JLP18821-Sep-09 6:07 
QuestionRecovering delivery Errors sending SMTP Mails Pin
FJJCENTU21-Sep-09 4:14
FJJCENTU21-Sep-09 4:14 
QuestionCreate a delegate at run time Pin
bonzaiholding21-Sep-09 2:50
bonzaiholding21-Sep-09 2:50 
AnswerRe: Create a delegate at run time Pin
Not Active21-Sep-09 4:04
mentorNot Active21-Sep-09 4:04 
QuestionCreating Registry Keys with Setup if key doesn't exist. Pin
Paramhans Dubey21-Sep-09 2:50
professionalParamhans Dubey21-Sep-09 2:50 
AnswerRe: Creating Registry Keys with Setup if key doesn't exist. Pin
Manas Bhardwaj21-Sep-09 3:24
professionalManas Bhardwaj21-Sep-09 3:24 
GeneralRe: Creating Registry Keys with Setup if key doesn't exist. Pin
Paramhans Dubey21-Sep-09 19:06
professionalParamhans Dubey21-Sep-09 19:06 
QuestionReportViewer control problem Pin
firefeet21-Sep-09 1:23
firefeet21-Sep-09 1:23 
AnswerRe: ReportViewer control problem Pin
Abhishek Sur21-Sep-09 11:42
professionalAbhishek Sur21-Sep-09 11:42 
GeneralRe: ReportViewer control problem Pin
firefeet21-Sep-09 18:16
firefeet21-Sep-09 18:16 
QuestionHow to delete outlook appointment Pin
tspradeep198021-Sep-09 1:06
tspradeep198021-Sep-09 1:06 
Questionsplitting values randomly - C# Pin
flower_t21-Sep-09 1:05
flower_t21-Sep-09 1:05 
AnswerRe: splitting values randomly - C# [modified] Pin
Calla21-Sep-09 1:29
Calla21-Sep-09 1:29 
AnswerRe: splitting values randomly - C# Pin
OriginalGriff21-Sep-09 2:46
mveOriginalGriff21-Sep-09 2:46 
AnswerRe: splitting values randomly - C# Pin
flower_t21-Sep-09 2:56
flower_t21-Sep-09 2:56 
GeneralRe: splitting values randomly - C# Pin
harold aptroot21-Sep-09 3:38
harold aptroot21-Sep-09 3:38 
GeneralRe: splitting values randomly - C# Pin
PIEBALDconsult21-Sep-09 7:39
mvePIEBALDconsult21-Sep-09 7:39 

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.