I'm tyring to read out a table of content from a word document. I made a working system for that but I don't like it at all and I was thinking if there is any way to do this much more simple. My Goal is to show every content into a Datagridview. Sry for bad English :)
static void Main(string[] args)
{
Application app = new Application();
Document doc = app.Documents.Open("C:\\Users\\----\\Desktop\\Kopie.docx");
int count = doc.Words.Count;
var table = doc.TablesOfContents[1].Range.Text;
var strings = table.Split(new string[] {"\r"},StringSplitOptions.None);
List<string> inhalt = new List<string>();
foreach (var item in strings)
{
var tmpA= item.Split(new string[] { "\t" }, StringSplitOptions.None);
if (tmpA.Length==1)
{
break;
}
string erg = tmpA[0] +" "+ tmpA[1];
inhalt.Add(erg);
}
inhalt.RemoveAt(0);
app.Quit();
Console.Read();
}