Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Get replace normal text from word document in C#

object o = Missing.Value;
object oFalse = false;
object oTrue = true;

Word._Application app = null;
Word.Documents docs = null;
Word.Document doc = null;

object path = @"C:pathfile.doc";

try
{
    app = new Word.Application();
    app.Visible = false;
    app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

    docs = app.Documents;
    doc = docs.Open(ref path, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
    doc.Activate();

    foreach (Word.Range range in doc.StoryRanges)
    {
        Word.Find find = range.Find;
        object findText = "[Company_Name]";
        object replacText = "Sacramento";
        object replace = Word.WdReplace.wdReplaceAll;
        object findWrap = Word.WdFindWrap.wdFindContinue;

        find.Execute(ref findText, ref o, ref o, ref o, ref oFalse, ref o,
            ref o, ref findWrap, ref o, ref replacText,
            ref replace, ref o, ref o, ref o, ref o);

        Marshal.FinalReleaseComObject(find);
        Marshal.FinalReleaseComObject(range);
    }

    doc.Save();
    ((Word._Document)doc).Close(ref o, ref o, ref o);
    app.Quit(ref o, ref o, ref o);
}
finally
{
    if (doc != null)
        Marshal.FinalReleaseComObject(doc);

    if (docs != null)
        Marshal.FinalReleaseComObject(docs);

    if (app != null)
        Marshal.FinalReleaseComObject(app);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# datediff 
Csharp :: list cast< c# 
Csharp :: c# Write a program to reverse an array or string 
Csharp :: how to display a form when a button click c# windows form 
Csharp :: list to ilist c# 
Csharp :: docker-compose cassandra db 
Csharp :: c# list to observablecollection 
Csharp :: c# textbox only numbers 
Csharp :: crud operation in asp.net 
Csharp :: get xml from url 
Csharp :: excel rows count 
Csharp :: longest palindromic substring 
Csharp :: create a file in the directory of the exe and write to it c# 
Csharp :: c# list empty 
Csharp :: bezier_curve 
Csharp :: c# quick "is" "as" 
Csharp :: AuthenticationTicket authenticationProperties C# .net 
Csharp :: how to make a chunk loader in c# 
Csharp :: wpf fixed window size 
Csharp :: c# different getter setter types 
Csharp :: insert button in c# 
Csharp :: How to return a list to view after foreach in c# 
Csharp :: c# multipthreading 
Csharp :: how do you search for how many times a character appears in user input on c sharp 
Csharp :: how to change font text mesh pro 
Csharp :: to string c# fields 
Csharp :: C# How to implement IEnumerable<T interface 
Csharp :: f# print array strings 
Csharp :: how to find all role in mysql 
Csharp :: How to fill text with 2 different color/texture 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =