Какой подход вы бы порекомендовали вместо этого:
Код: Выделить всё
// Step 2: Modify the .docx file
try
{
File.Copy(inputFilePath, tempOutputFilePath, overwrite: true); // Create a copy for modification
using (WordprocessingDocument document = WordprocessingDocument.Open(tempOutputFilePath, 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())
{
RunProperties runProperties = run.GetFirstChild() ?? new RunProperties();
// Set 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();
run.PrependChild(runProperties); // Add or update properties
}
}
document.MainDocumentPart.Document.Save(); // Save changes
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ocx-italic