many debugs
All checks were successful
Publish NuGet packages / publish (push) Successful in 28s

This commit is contained in:
melekhin
2026-06-19 15:06:40 +07:00
parent 08b39b7bfe
commit e373d4108a
24 changed files with 1569 additions and 632 deletions

View File

@@ -19,7 +19,7 @@ public readonly struct RunFormat
public bool? IsStrike { get; init; }
/// <summary>Цвет текста фрагмента.</summary>
public ExColor? Color { get; init; }
public System.Drawing.Color? Color { get; init; }
/// <summary>Размер шрифта фрагмента в пунктах.</summary>
public double? FontSize { get; init; }
@@ -80,9 +80,7 @@ public readonly struct RunFormat
// DoubleStrike в Excel не поддерживается, опускаем
Underline = underline,
Color = rPr.GetFirstChild<Color>()?.Rgb is not null
? ExColor.FromRgb(rPr.GetFirstChild<Color>()!.Rgb!.Value!)
: null!,
Color = FromExcelColor(rPr.GetFirstChild<Color>()?.Rgb),
FontSize = rPr.GetFirstChild<FontSize>()?.Val?.Value,
FontFamily = rPr.GetFirstChild<RunFont>()?.Val,
Vertical = vertical
@@ -90,6 +88,45 @@ public readonly struct RunFormat
return fmt;
}
static System.Drawing.Color? FromExcelColor(string? rgb)
{
if (string.IsNullOrWhiteSpace(rgb)) return null;
if (rgb!.Length == 6)
{
byte r = Convert.ToByte(rgb.Substring(0, 2), 16);
byte g = Convert.ToByte(rgb.Substring(2, 2), 16);
byte b = Convert.ToByte(rgb.Substring(4, 2), 16);
return System.Drawing.Color.FromArgb(r, g, b);
}
else if (rgb.Length == 8)
{
byte a = Convert.ToByte(rgb.Substring(0, 2), 16);
byte r = Convert.ToByte(rgb.Substring(2, 2), 16);
byte g = Convert.ToByte(rgb.Substring(4, 2), 16);
byte b = Convert.ToByte(rgb.Substring(6, 2), 16);
return System.Drawing.Color.FromArgb(a, r, g, b);
}
else return null;
}
public bool TryGetExcelColor(out Color excelColor)
{
if (Color is { } c)
{
excelColor = new Color() { Rgb = $"{c.R:X2}{c.G:X2}{c.B:X2}" };
return true;
}
else
{
excelColor = null!;
return false;
}
}
/*
методы для извлечения OpenXmlElement или других более удобных типов