TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Lokesh Sharma
NA
4
818
Extract lines between two keywords in Word Document
Aug 7 2018 6:40 AM
Need to search for two keywords in Word document
E.g..
Keyword1
Keyword2
Lines between both the keywords then needs to be returned.
Trying this but i couldn't get this to work even for single keyword search
using word = Microsoft.Office.Interop.Word;
object fileName = "D:\\Files\\Scan.doc"; //The filepath goes here
string textToFind = "Keyword1"; //The text to find goes here
Word.Application word = new Word.Application();
Word.Document doc = new Word.Document();
object missing = System.Type.Missing;
try
{
doc = word.Documents.Open(ref fileName, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
doc.Activate();
foreach (Word.Range docRange in doc.Words)
{
if (docRange.Text.Trim().Equals(textToFind,
StringComparison.CurrentCultureIgnoreCase))
{
Response.Write(docRange.Text);
}
}
}
catch (Exception ex)
{
Response.Write("Error : " + ex.Message);
}
Reply
Answers (
3
)
How to show message in empty gridview coulmn
How to post data into a foreign Key table