Veröffentlicht 2. März 201015 j Hallo, ich habe folgendes vor: Word Serienbrief aus C#. Dazu öffne ich eine Vorlagendatei, durchlaufe die Paragraphen, passe meine Serienbrief Key-Felder an, und schreib den Kram in ein neues Dokument. Das ganze funktioniert auch, mein Problem ist nur, das ich die Formateigenschaften des Quelldokumentes (sVorlage) nicht übernehmen kann, ich finde einfach keine Lösung. CODE: public void Start(List<string> liSelKundenIDs, string sVorlage, string sRTBText) { Microsoft.Office.Interop.Word._Document wrdDoc1; Microsoft.Office.Interop.Word.Selection wrdSelection; Microsoft.Office.Interop.Word.MailMerge wrdMailMerge; Microsoft.Office.Interop.Word.MailMergeFields wrdMergeFields; // Create an instance of Word and make it visible. wrdApp = new Microsoft.Office.Interop.Word.Application(); wrdApp.Visible = true; // Add a new document. wrdDoc = wrdApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); //Vorlage öffnen object oFile = sVorlage; wrdDoc1 = wrdApp.Documents.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, ref oMissing, ref oMissing, ref oMissing, ref oMissing); wrdDoc.Select(); wrdSelection = wrdApp.Selection; wrdMailMerge = wrdDoc.MailMerge; // Create a MailMerge Data file. CreateMailMergeDataFile(liSelKundenIDs); wrdMergeFields = wrdMailMerge.Fields; string sLines = ""; for (int i = 0; i < wrdDoc1.Paragraphs.Count; i++) { sLines = wrdDoc1.Paragraphs[i + 1].Range.Text; Range rng = wrdDoc1.Paragraphs[i + 1].Range.FormattedText; while (sLines.Contains("<<")) { string sNurText = sLines.Substring(0, sLines.IndexOf("<<")); wrdSelection.TypeText(sNurText); string sKeyField = sLines.Substring((sLines.IndexOf("<<") + 2), sLines.IndexOf(">>") - (sLines.IndexOf("<<") + 2)); wrdMergeFields.Add(wrdSelection.Range, sKeyField); sLines = sLines.Substring((sLines.IndexOf(">>") + 2), sLines.Length - (sLines.IndexOf(">>") + 2)); } wrdSelection.TypeText(sLines); //wrdSelection.Font.Bold = wrdDoc1.Paragraphs[i + 1].Range.Font.Bold; //wrdSelection.Font.Size = wrdDoc1.Paragraphs[i + 1].Range.Font.Size; //wrdSelection.Font.Italic = wrdDoc1.Paragraphs[i + 1].Range.Font.Italic; //wrdSelection.Font.Name = wrdDoc1.Paragraphs[i + 1].Range.Font.Name; //wrdSelection.Font.Underline = wrdDoc1.Paragraphs[i + 1].Range.Font.Underline; //wrdSelection.Font.UnderlineColor = wrdDoc1.Paragraphs[i + 1].Range.Font.UnderlineColor; //wrdSelection.Font.Color = wrdDoc1.Paragraphs[i + 1].Range.Font.Color; //wrdSelection.Font.Position = wrdDoc1.Paragraphs[i + 1].Range.Font.Position; //wrdSelection.Font.StrikeThrough = wrdDoc1.Paragraphs[i + 1].Range.Font.StrikeThrough; } // Perform mail merge. wrdMailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument; wrdMailMerge.Execute(ref oFalse); // Close the original form document. wrdDoc.Saved = true; wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing); wrdDoc1.Saved = false; wrdDoc1.Close(ref oFalse, ref oMissing, ref oMissing); // Release References. wrdSelection = null; wrdMailMerge = null; wrdMergeFields = null; wrdDoc = null; wrdDoc1 = null; wrdApp = null; // Clean up temp file. System.IO.File.Delete("C:\\DataDoc.doc"); } Bin für jede Hilfe und Anmerkung sehr dankbar.
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.