Startseite
Stellenmarkt
Downloads
Kontakt
  Community Center:   Forum  |  Gruppen  |  Chat  |

Zurück   Forum Fachinformatiker.de > Programmierung > .NET



Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 02.03.2010, 10:31   #1
Reg.-Benutzer
 
Reg.-Datum: 09.01.2008
Standard WORD-Serienbrief mit C#

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.WdMailMergeDestinati on.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.
msc84 ist offline   Mit Zitat antworten
Alt 03.03.2010, 12:06   #2
Reg.-Benutzer
 
Reg.-Datum: 09.01.2008
Standard

Hat sich erledigt, habs hinbekommen.

CLOSED
msc84 ist offline   Mit Zitat antworten
Antwort

Tags:


Lesezeichen
Zurück   Forum Fachinformatiker.de > Programmierung > .NET

Themen-Optionen
Ansicht


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Serienbrief aus Word 2003 als PDF versenden Nooper Anwendungssoftware 3 06.11.2009 15:57
Word Serienbrief drucken AHNUNG? Anwendungssoftware 1 18.03.2009 15:55
Word Serienbrief VatoLoco Anwendungssoftware 1 19.01.2009 18:14
Adressen in Excel zuweisen für Serienbrief in Word thwmoe Anwendungssoftware 3 23.11.2008 16:17
Serienbrief Word - 2 Datenquellen? Meik Anwendungssoftware 2 29.04.2003 10:12


Alle Zeitangaben in WEZ +2. Es ist jetzt 22:18 Uhr.