concatenate the word document, it's possible?
-
How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :
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("$")) { int pos = range.Text.Trim().IndexOf("$"); string str = range.Text.Trim().Replace("$", ""); range.Text = str;} } foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("$$")) { int pos = range.Text.Trim().IndexOf("$$"); string str = range.Text.Trim().Replace("$$", ""); range.Text = str;} } Object oSaveAsFile ="./1.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);
-
How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :
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("$")) { int pos = range.Text.Trim().IndexOf("$"); string str = range.Text.Trim().Replace("$", ""); range.Text = str;} } foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("$$")) { int pos = range.Text.Trim().IndexOf("$$"); string str = range.Text.Trim().Replace("$$", ""); range.Text = str;} } Object oSaveAsFile ="./1.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);
-
How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :
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("$")) { int pos = range.Text.Trim().IndexOf("$"); string str = range.Text.Trim().Replace("$", ""); range.Text = str;} } foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("$$")) { int pos = range.Text.Trim().IndexOf("$$"); string str = range.Text.Trim().Replace("$$", ""); range.Text = str;} } Object oSaveAsFile ="./1.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);
A tip you will often see is to record a macro for the operation you want to perform. In your case just find out what code is generated for the Insert File operation. In Word 2002 the macro code is
Sub Macro1()
Selection.InsertFile FileName:="xxxxx.doc", Range:="", ConfirmConversions:= False, Link:=False, Attachment:=False
End SubFrom the MS Word Visual Basic reference we can get the InsertFile method signature and remove the named arguments to give the conventional method call
Selection.InsertFile("xxxx.doc", "", False, False, False)
which can be easily translated into C#. Alan.
-
How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :
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("$")) { int pos = range.Text.Trim().IndexOf("$"); string str = range.Text.Trim().Replace("$", ""); range.Text = str;} } foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("$$")) { int pos = range.Text.Trim().IndexOf("$$"); string str = range.Text.Trim().Replace("$$", ""); range.Text = str;} } Object oSaveAsFile ="./1.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);
Who in their right mind would want to open a 1,000 page document in Word?? That'll take, what, a few hours to do?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Who in their right mind would want to open a 1,000 page document in Word?? That'll take, what, a few hours to do?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
No, only a few seconds if not bloated with a shed load of pictures. E.g. the C# Specification v3.0 is 519 pages and takes about 3 seconds to open over here in the UK. Alan.
Damn, must be my machine.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :
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("$")) { int pos = range.Text.Trim().IndexOf("$"); string str = range.Text.Trim().Replace("$", ""); range.Text = str;} } foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words) {if (range.Text.Trim().Contains("$$")) { int pos = range.Text.Trim().IndexOf("$$"); string str = range.Text.Trim().Replace("$$", ""); range.Text = str;} } Object oSaveAsFile ="./1.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);
Try Merge Multiple Microsoft Word Documents in C#[^] I hope it will might help you.
-
Try Merge Multiple Microsoft Word Documents in C#[^] I hope it will might help you.