Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

WORD-Serienbrief mit C#

Empfohlene Antworten

Veröffentlicht

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.

Hat sich erledigt, habs hinbekommen.

CLOSED

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.