Hie rmal mein Code:
opf.Filter = "Word-Dateien(*.doc, *.docx)|*.doc;*.docx";
if (opf.ShowDialog() == false)
return;
////// set the file name from the open file dialog
object fileName = opf.FileName;
object readOnly = false;
object isVisible = true;
////// Here is the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;
//// Make word visible, so you can see what's happening
WordApp.Visible = true;
//// Open the document that was chosen by the dialog
//Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
Document aDoc = WordApp.Documents.Open(opf.FileName, ReadOnly: false, Visible: true);
//// Activate the document so it shows up in front
aDoc.Activate();
//// JEe Tabelle im Word-Dokument durchlaufen
foreach (Table docTbl in aDoc.Tables)
{
//// Jede Row in der Tabelle durchlaufen
foreach (Row row in docTbl.Rows)
{
//// Erst Zelle der "Row" bereinigen (Texte entfernen)
string strTemp = row.Cells[1].Range.Text.Trim();
if (strTemp.Contains("\r"))
strTemp = strTemp.Replace("\r", "");
if (strTemp.Contains("\a"))
strTemp = strTemp.Replace("\a", "");
//// Suche nach Begriff in Datentabelle
DataRow[] rows = ds.Tables[0].Select("F0 = '" + strTemp + ".'");
//// Wenn Begriff in DataTable vorhanden, diesen überschreiben
if (rows.Length > 0)
{
//// ==> zwar keine Fehlermeldung, aber die Zelle wird nicht überschrieben, der Text wird davor geklemmt
row.Cells[1].Range.Text = rows[0][2].ToString();
row.Cells[1].Range.Font.Color = WdColor.wdColorViolet;
}
}
}