Welchen Ansatz würden Sie stattdessen empfehlen? dies:
Code: Select all
private void ModifyDocument(string filePath) {
using (WordprocessingDocument document = WordprocessingDocument.Open(filePath, true))
{
var body = document.MainDocumentPart.Document.Body;
// Iterate through all paragraphs and modify text formatting
foreach (var paragraph in body.Elements
())
{
foreach (var run in paragraph.Elements())
{
// Retrieve existing RunProperties or create a new one
var runProperties = run.GetFirstChild();
if (runProperties == null)
{
runProperties = new RunProperties();
run.PrependChild(runProperties);
}
// Modify font to Times New Roman and italicize the text
runProperties.RunFonts = new RunFonts { Ascii = "Times New Roman", HighAnsi = "Times New Roman" };
runProperties.Italic = new Italic();
}
}
document.MainDocumentPart.Document.Save(); // Save changes
}
Vielen Dank!