Close wrod corrctly, it's possile?
-
Hello, I create 4000 files word like this :
foreach (string s in FUSIONSS_1)
{String\[\] tbStr2 = s.Split(new Char\[\] { ';' }); string nb = tbStr2\[0\]; Object oMissing = System.Reflection.Missing.Value; Object oTrue = true; Object oFalse = false; Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document(); oWord.Visible = true; oWord.Visible = false; Object oTemplatePath = modelee; oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false; foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("P")) { int pos = range.Text.Trim().IndexOf("P"); string str = range.Text.Trim().Replace("P", "O"); range.Text = str;} } Directory.CreateDirectory((Object)path + "./PUBLI/" + nb); Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc"; oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing); oWord.Quit(ref oMissing, ref oMissing, ref oMissing); }
unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.
-
Hello, I create 4000 files word like this :
foreach (string s in FUSIONSS_1)
{String\[\] tbStr2 = s.Split(new Char\[\] { ';' }); string nb = tbStr2\[0\]; Object oMissing = System.Reflection.Missing.Value; Object oTrue = true; Object oFalse = false; Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document(); oWord.Visible = true; oWord.Visible = false; Object oTemplatePath = modelee; oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false; foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("P")) { int pos = range.Text.Trim().IndexOf("P"); string str = range.Text.Trim().Replace("P", "O"); range.Text = str;} } Directory.CreateDirectory((Object)path + "./PUBLI/" + nb); Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc"; oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing); oWord.Quit(ref oMissing, ref oMissing, ref oMissing); }
unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.
Search results[^] may be unsatisfactory. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hello, I create 4000 files word like this :
foreach (string s in FUSIONSS_1)
{String\[\] tbStr2 = s.Split(new Char\[\] { ';' }); string nb = tbStr2\[0\]; Object oMissing = System.Reflection.Missing.Value; Object oTrue = true; Object oFalse = false; Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document(); oWord.Visible = true; oWord.Visible = false; Object oTemplatePath = modelee; oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false; foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("P")) { int pos = range.Text.Trim().IndexOf("P"); string str = range.Text.Trim().Replace("P", "O"); range.Text = str;} } Directory.CreateDirectory((Object)path + "./PUBLI/" + nb); Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc"; oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing); oWord.Quit(ref oMissing, ref oMissing, ref oMissing); }
unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.
Do you really need to create and dispose of the word application, and the other objects, 4000 times? Don't you think it would be better to do this outside of the loop?
I know the language. I've read a book. - _Madmatt
-
Hello, I create 4000 files word like this :
foreach (string s in FUSIONSS_1)
{String\[\] tbStr2 = s.Split(new Char\[\] { ';' }); string nb = tbStr2\[0\]; Object oMissing = System.Reflection.Missing.Value; Object oTrue = true; Object oFalse = false; Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document(); oWord.Visible = true; oWord.Visible = false; Object oTemplatePath = modelee; oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false; foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("P")) { int pos = range.Text.Trim().IndexOf("P"); string str = range.Text.Trim().Replace("P", "O"); range.Text = str;} } Directory.CreateDirectory((Object)path + "./PUBLI/" + nb); Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc"; oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing); oWord.Quit(ref oMissing, ref oMissing, ref oMissing); }
unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.
Try changing the first oMissing to false.
abbd wrote:
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Word may be hanging on a hidden prompt to save changes or suchlike.
Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.
-
Try changing the first oMissing to false.
abbd wrote:
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Word may be hanging on a hidden prompt to save changes or suchlike.
Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.
-
Well, I used to have a similar problem automating Excel in the same way. Best way to troubleshoot it is to NOT run it invisible for the time being. Then you can see what the problem might be.
Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.
-
Well, I used to have a similar problem automating Excel in the same way. Best way to troubleshoot it is to NOT run it invisible for the time being. Then you can see what the problem might be.
Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.
-
Hello, How in can run it invisible for the time being? please help me to resolve this great big problem.
oWord.Visible = true; oWord.Visible = false; Take out that second line. You're running this on a server, right? NOT a good idea according to Microsoft (and my experience). Also check your DCOM settings to be sure permissions are there for remote running. (I don't remember how to do it...Google will help.) Actually, the best advice is to find another way to do it. If you can use Word 2007, while not necessarily easier, it's more likely to work beause you don't actually need Word on the server. (I'll be gone this week, so can't help much. Maybe try Questions & Answers for more.)
Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.
modified on Tuesday, May 24, 2011 10:49 AM