R
rsotolongo
Hello,
I really hope that somebody can helps me. Look that code that I have:
private void WriteDOC(string FileName, List<string> Strings)
{
Microsoft.Office.Interop.Word.ApplicationClass aApp = new
Microsoft.Office.Interop.Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object filename = FileName;
object noflag = false;
Microsoft.Office.Interop.Word.Document aDoc = aApp.Documents.Add(ref
missing, ref missing, ref missing, ref noflag);
aDoc.Activate();
for (int i = 0; i < Strings.Count; i++)
{
aApp.Selection.TypeText(Strings);
aApp.Selection.TypeParagraph();
}
aDoc.SaveAs(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);
aDoc.Close(ref missing, ref missing, ref missing);
aDoc = null;
aApp.Quit(ref missing, ref missing, ref missing);
aApp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
I make N calls to that method:
WriteDOC("c:\\temp\\f1.doc", strings1)
WriteDOC("c:\\temp\\f2.doc", strings2)
..
..
..
The first call it's OK. Generates the file "f1.doc" with the strings
of the list 1, but when it tries to save the second time, trows the
exception "Word cannot save this file because it is already open
elsewhere". I couldn't find an answer. Please help me.
I really hope that somebody can helps me. Look that code that I have:
private void WriteDOC(string FileName, List<string> Strings)
{
Microsoft.Office.Interop.Word.ApplicationClass aApp = new
Microsoft.Office.Interop.Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object filename = FileName;
object noflag = false;
Microsoft.Office.Interop.Word.Document aDoc = aApp.Documents.Add(ref
missing, ref missing, ref missing, ref noflag);
aDoc.Activate();
for (int i = 0; i < Strings.Count; i++)
{
aApp.Selection.TypeText(Strings);
aApp.Selection.TypeParagraph();
}
aDoc.SaveAs(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);
aDoc.Close(ref missing, ref missing, ref missing);
aDoc = null;
aApp.Quit(ref missing, ref missing, ref missing);
aApp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
I make N calls to that method:
WriteDOC("c:\\temp\\f1.doc", strings1)
WriteDOC("c:\\temp\\f2.doc", strings2)
..
..
..
The first call it's OK. Generates the file "f1.doc" with the strings
of the list 1, but when it tries to save the second time, trows the
exception "Word cannot save this file because it is already open
elsewhere". I couldn't find an answer. Please help me.