1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public void ReadFileWord()
{
string DocumentWordAll = "";
for (int i = 0; i < CS.url.Count; i++)
{
object filePath = CS.url[i];
object PathRapport = "C:\\Documents and Settings\\lmarboutie\\Bureau\\Rapport MOS TT V2VDF.doc";
object typeMissing = Type.Missing;
Word._Application applicationRapport = new Word.ApplicationClass();
Word.Documents documentsRapport = applicationRapport.Documents;
Word._Document documentRapport = documentsRapport.Open(ref PathRapport, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing);
Word._Application application = new Word.ApplicationClass();
Word.Documents documents = application.Documents;
Word._Document document = documents.Open(ref filePath, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing);
foreach (Word.Paragraph par in document.Content.Paragraphs)
{
//MessageBox.Show(par.Range.Text);
documentRapport.Paragraphs.Last.Range.InsertParagraphAfter(); // ajouter un para a la fin
Word.Paragraph paragraph = documentRapport.Paragraphs[documentRapport.Paragraphs.Count - 1];
paragraph.Range.Text = par.Range.Text;
//DocumentWordAll = DocumentWordAll + par.Range.Text;
}
document.Close(ref typeMissing, ref typeMissing, ref typeMissing);
application.Quit(ref typeMissing, ref typeMissing, ref typeMissing);
MessageBox.Show("Merge Finish");
documentRapport.Save();
documentRapport.Close(ref typeMissing, ref typeMissing, ref typeMissing);
applicationRapport.Quit(ref typeMissing, ref typeMissing, ref typeMissing);
}
} |
Partager