Problem bei Verweis hinzufügen
-
Hallo,
ich würde in unserem Projekt gerne den Verweis
using Microsoft.Office.Interop.Word;
hinzufügen.
Ich kann dies aber in der .Net Liste nicht finden.
So wie hier beschrieben, habe ich es versucht (vernde selbst allerdings Visual Studio 2008): http://msdn.microsoft.com/en-us/library/dd264733.aspx
Und das soll eigentlich dabei raus kommen http://dotnet-snippets.de/dns/textmarken-in-word-fuellen-SID864.aspx
Hat jemand einen Tipp, wie ich den Verweis hinzufügen kann?
-
"Browse" mal direkt zum Ordner "C:\Windows\Assembly\GAC".
(auch bei mir mit VS2010 sehe ich die Office-DLLs nicht direkt im Verweise-Fenster)
-
GAC kann ich unter Assembly leider gar nicht finden
Vielleicht heißt mein Assembly auch noch anderst, da wir hier Word 2000 verwenden?
Haben es jetzt wie folgt versucht zu lösen
private object document(string textmark, string textmarkValue) { object oMissing = System.Reflection.Missing.Value; Word.ApplicationClass oWord = new Word.ApplicationClass(); oWord.Visible = true; try { Word.Documents oDocs = oWord.Documents; object oFile = "C:\\L0001V00.doc"; Word._Document oDoc = oDocs.Open(ref oFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); if (oDoc.Bookmarks.Exists(textmark)) { oDoc.Bookmarks.Item(textmark).Range.Text = textmarkValue; } } catch (IOException ex) { MessageBox.Show("Datei nicht vorhanden");} finally { oWord.Application.Quit(); } return (0); }
Leider stimmen die Typen string --> ref object noch nicht überein.
Dann sollte es aber funktionieren?! Würde ich dann die .dll noch benötigen?
-
public static void InsertTextAtBookmark(ref Word.Bookmarks oBookmarks, string textmark, string textmarkValue) { Word.Bookmark oBookmark = null; Word.Range oRange = null; object oName = textmark; object oMissing = System.Reflection.Missing.Value; Word.ApplicationClass oWord = new Word.ApplicationClass(); oWord.Visible = true; try { Word.Documents oDocs = oWord.Documents; object oFile = "C:\\L0001V00.doc"; Word._Document oDoc = oDocs.Open(ref oFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); if (oDoc.Bookmarks.Exists(textmark)) { oBookmark = oBookmarks.Item(ref oName); oRange = oBookmark.Range; oRange.Text = textmarkValue; } } catch { } finally { } }
So läuft es nun ... nur wir mein Bookmark wohl nicht erkannt??
Im if-Block wird nur die erste Zeile vom Debugger angesprungen (für oBookmark bzw. oBookmarks erhalte ich immer den Wert null) - die zwei anderen Zeilen werden nicht brücksichtigt.