c# - Read from word document line by line -



i'm trying read word document using c#. able text want able read line line , store in list , bind gridview. code returns list of 1 item text (not line line desired). i'm using microsoft.office.interop.word library read file. below code till now:

    application word = new application();     document doc = new document();      object filename = path;     // define object pass api missing parameters     object missing = system.type.missing;     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, ref missing);      string read = string.empty;     list<string> data = new list<string>();     foreach (range tmprange in doc.storyranges)     {         //read += tmprange.text + "<br>";         data.add(tmprange.text);     }     ((_document)doc).close();     ((_application)word).quit();      gridview1.datasource = data;     gridview1.databind(); 

ok. found solution here.


final code follows:

    application word = new application();     document doc = new document();      object filename = path;     // define object pass api missing parameters     object missing = system.type.missing;     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, ref missing);      string read = string.empty;     list<string> data = new list<string>();     (int = 0; < doc.paragraphs.count; i++)     {         string temp = doc.paragraphs[i + 1].range.text.trim();         if (temp != string.empty)             data.add(temp);     }     ((_document)doc).close();     ((_application)word).quit();      gridview1.datasource = data;     gridview1.databind(); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -