word document is like this
paragraph1:some text in this para
paragraph2: sometext in this para
big =large
center = middle
paragraph3: some text in this para
I want to get paragraph2 text from starting to ending(sometext........... center =middle) and I should insert this data into sql table using c#
can any body tell how to do this
thanq
Loading
Hemant SrivastavaPosted Sep 19, 2013, 10:05 AM
public string ReadFileParaContainingWord(string path, string word)
{
int i = 0;
StringBuilder sb = new StringBuilder();
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open
(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
Microsoft.Office.Interop.Word.Paragraphs DocPar = doc.Paragraphs;
// Count number of paragraphs in the file
long parCount = DocPar.Count;
// Step through the paragraphs
while (i < parCount)
{
i++;
if (DocPar[i].Range.Text.Contains(word))
{
sb.Append(DocPar[i].Range.Text);
break;
}
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
return (sb.ToString());
}
Hope it will work.
shahanaz vPosted Sep 23, 2013, 8:46 AM
shahanaz vPosted Sep 19, 2013, 1:01 AM
i want to search specific string in whole document if it will be there in that documenent then it should get that paragraph
thanq
Hemant SrivastavaPosted Sep 18, 2013, 9:05 AM
Hemant SrivastavaPosted Sep 17, 2013, 1:30 PM
try this:
//To read paragraph contents of a Word document using Microsoft.Office.Interop.Word DLL
private void readFileContent(string path, int paraGraphNum)
{
int i = 0;
StringBuilder sb = new StringBuilder();
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
Microsoft.Office.Interop.Word.Paragraphs DocPar = doc.Paragraphs;
// Count number of paragraphs in the file
long parCount = DocPar.Count;
// Step through the paragraphs
while (i < parCount)
{
i++;
if (i == paraGraphNum)
{
sb.Append(DocPar[i].Range.Text);
break;
}
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
Console.WriteLine(sb.ToString());
}