using System.Collections.Generic;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using Microsoft.Office.Interop.Word;
using System.Text.RegularExpressions;
using DocumentFormat.OpenXml.Office2010.Word;
using DocumentFormat.OpenXml.ExtendedProperties;
using System.Runtime.InteropServices.ComTypes;
using Spire.Doc.Documents;
using Document = Spire.Doc.Document;
using Paragraph = Spire.Doc.Documents.Paragraph;
namespace HelloWorldMvcApp.Controllers
public class HomeController : Controller
public ActionResult Index()
return View(new SampleViewModel());
public static void SearchAndReplace()
string filename = @"C:\Users\anujrsin\OneDrive - Capgemini\Attachments\test.docx";
Document document1 = new Document();
document1.LoadFromFile(filename);
TextSelection[] selections1 = document1.FindAllString("Test2", true, true);
foreach (TextSelection selection1 in selections1)
TextRange range1 = selection1.GetAsOneRange();
Paragraph paragraph = range1.OwnerParagraph;
int index1 = paragraph.ChildObjects.IndexOf(range1);
paragraph.AppendHTML("<b>Hello</b>");
range1.OwnerParagraph.ChildObjects.Remove(range1);
document1.SaveToFile(filename, FileFormat.Docx);