This commit is contained in:
melekhin
2026-06-08 14:31:31 +07:00
parent f9cca53f75
commit f5eb667973
36 changed files with 159 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
namespace QWERTYkez.ExcelProcessor.Editors;
namespace QWERTYkez.ExcelProcessor;
/// <summary>
/// Определяет форматирование отдельного фрагмента (Run) внутри ячейки с богатым текстом.
@@ -30,6 +30,66 @@ public readonly struct RunFormat
/// <summary>Вертикальное смещение (надстрочный или подстрочный).</summary>
public VerticalTextRunAlignment? Vertical { get; init; }
public static RunFormat? FromRunProperties(RunProperties rPr)
{
UnderlineStyle? underline;
if (rPr.GetFirstChild<Underline>()?.Val?.Value is { } underlineVal)
{
if (underlineVal == UnderlineValues.Single)
{
underline = UnderlineStyle.Single;
}
else if (underlineVal == UnderlineValues.Double)
{
underline = UnderlineStyle.Double;
}
else if (underlineVal == UnderlineValues.SingleAccounting)
{
underline = UnderlineStyle.SingleAccounting;
}
else if (underlineVal == UnderlineValues.DoubleAccounting)
{
underline = UnderlineStyle.DoubleAccounting;
}
else underline = null!;
}
else underline = null!;
VerticalTextRunAlignment? vertical;
if (rPr.GetFirstChild<VerticalTextAlignment>()?.Val?.Value is { } verticalVal)
{
if (verticalVal == VerticalAlignmentRunValues.Superscript)
{
vertical = VerticalTextRunAlignment.Superscript;
}
else if (verticalVal == VerticalAlignmentRunValues.Subscript)
{
vertical = VerticalTextRunAlignment.Subscript;
}
else vertical = null!;
}
else vertical = null!;
if (rPr == null) return null;
var fmt = new RunFormat
{
IsBold = rPr.GetFirstChild<Bold>() != null,
IsItalic = rPr.GetFirstChild<Italic>() != null,
IsStrike = rPr.GetFirstChild<Strike>() != null,
// DoubleStrike в Excel не поддерживается, опускаем
Underline = underline,
Color = rPr.GetFirstChild<Color>()?.Rgb is not null
? ExColor.FromRgb(rPr.GetFirstChild<Color>()!.Rgb!.Value!)
: null!,
FontSize = rPr.GetFirstChild<FontSize>()?.Val?.Value,
FontFamily = rPr.GetFirstChild<RunFont>()?.Val,
Vertical = vertical
};
return fmt;
}
/*
методы для извлечения OpenXmlElement или других более удобных типов