This commit is contained in:
@@ -1,11 +1,29 @@
|
||||
namespace QWERTYkez.ExcelProcessor;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Определяет границы ячейки: верхнюю, нижнюю, левую, правую и диагональные.
|
||||
/// Каждая граница может иметь стиль и цвет.
|
||||
/// </summary>
|
||||
public readonly struct CellBorder : IEquatable<CellBorder>
|
||||
{
|
||||
|
||||
public static CellBorder Bottom { get; } = new() { BottomBorder = BorderSide.BlackThin };
|
||||
public static CellBorder Top { get; } = new() { TopBorder = BorderSide.BlackThin };
|
||||
public static CellBorder Left { get; } = new() { LeftBorder = BorderSide.BlackThin };
|
||||
public static CellBorder Right { get; } = new() { RightBorder = BorderSide.BlackThin };
|
||||
public static CellBorder All { get; } = new()
|
||||
{
|
||||
BottomBorder = BorderSide.BlackThin,
|
||||
TopBorder = BorderSide.BlackThin,
|
||||
LeftBorder = BorderSide.BlackThin,
|
||||
RightBorder = BorderSide.BlackThin
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// <summary>Верхняя граница.</summary>
|
||||
public BorderSide? TopBorder { get; init; }
|
||||
|
||||
@@ -24,6 +42,33 @@ public readonly struct CellBorder : IEquatable<CellBorder>
|
||||
/// <summary>Диагональная граница «из левого нижнего в правый верхний» (//).</summary>
|
||||
public BorderSide? DiagonalRight { get; init; }
|
||||
|
||||
|
||||
public bool TryMerge(CellBorder other, out CellBorder result)
|
||||
{
|
||||
if (other.TopBorder == TopBorder &&
|
||||
other.BottomBorder == BottomBorder &&
|
||||
other.LeftBorder == LeftBorder &&
|
||||
other.RightBorder == RightBorder &&
|
||||
other.DiagonalLeft == DiagonalLeft &&
|
||||
other.DiagonalRight == DiagonalRight)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = new CellBorder
|
||||
{
|
||||
TopBorder = other.TopBorder ?? TopBorder,
|
||||
BottomBorder = other.BottomBorder ?? BottomBorder,
|
||||
LeftBorder = other.LeftBorder ?? LeftBorder,
|
||||
RightBorder = other.RightBorder ?? RightBorder,
|
||||
DiagonalLeft = other.DiagonalLeft ?? DiagonalLeft,
|
||||
DiagonalRight = other.DiagonalRight ?? DiagonalRight
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Создаёт элемент Border для Open XML.</summary>
|
||||
public Border? ToBorder()
|
||||
{
|
||||
@@ -112,11 +157,23 @@ public readonly struct CellBorder : IEquatable<CellBorder>
|
||||
/// <summary>Стиль и цвет границы.</summary>
|
||||
public readonly struct BorderSide : IEquatable<BorderSide>
|
||||
{
|
||||
/// <summary>Тонкая черная линия</summary>
|
||||
public static BorderSide BlackThin { get; } = new() { Color = System.Drawing.Color.Black, Style = BorderStyle.Thin };
|
||||
|
||||
/// <summary>Толстая черная линия</summary>
|
||||
public static BorderSide BlackThick { get; } = new() { Color = System.Drawing.Color.Black, Style = BorderStyle.Thick };
|
||||
|
||||
/// <summary>Средняя черная линия</summary>
|
||||
public static BorderSide BlackMedium { get; } = new() { Color = System.Drawing.Color.Black, Style = BorderStyle.Medium };
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>Стиль линии границы.</summary>
|
||||
public BorderStyle? Style { get; init; }
|
||||
|
||||
/// <summary>Цвет границы.</summary>
|
||||
public ExColor? Color { get; init; }
|
||||
public System.Drawing.Color? Color { get; init; }
|
||||
|
||||
internal T ToBorderElement<T>() where T : BorderPropertiesType, new()
|
||||
{
|
||||
@@ -141,9 +198,9 @@ public readonly struct BorderSide : IEquatable<BorderSide>
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
}
|
||||
if (Color.HasValue && Color.Value.Color.HasValue)
|
||||
if (Color.HasValue)
|
||||
{
|
||||
var c = Color.Value.Color.Value;
|
||||
var c = Color.Value;
|
||||
element.Color = new Color { Rgb = $"{c.R:X2}{c.G:X2}{c.B:X2}" };
|
||||
}
|
||||
return element;
|
||||
@@ -162,17 +219,18 @@ public readonly struct BorderSide : IEquatable<BorderSide>
|
||||
}
|
||||
if (borderElement.Color?.Rgb?.Value is { } rgb && rgb.Length >= 6)
|
||||
{
|
||||
var color = System.Drawing.Color.FromArgb(
|
||||
Convert.ToByte(rgb.Substring(0, 2), 16),
|
||||
Convert.ToByte(rgb.Substring(2, 2), 16),
|
||||
Convert.ToByte(rgb.Substring(4, 2), 16)
|
||||
);
|
||||
result = result with { Color = new ExColor(color) };
|
||||
result = result with
|
||||
{
|
||||
Color = System.Drawing.Color.FromArgb(
|
||||
Convert.ToByte(rgb.Substring(0, 2), 16),
|
||||
Convert.ToByte(rgb.Substring(2, 2), 16),
|
||||
Convert.ToByte(rgb.Substring(4, 2), 16))
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BorderStyle MapBorderStyleFromExcel(BorderStyleValues value)
|
||||
static BorderStyle MapBorderStyleFromExcel(BorderStyleValues value)
|
||||
{
|
||||
if (value == BorderStyleValues.Thin)
|
||||
{
|
||||
@@ -278,4 +336,25 @@ public enum BorderStyle
|
||||
MediumDashDotDot,
|
||||
/// <summary> Наклонная штрих-пунктирная (для диагональных) </summary>
|
||||
SlantDashDot,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Определяет, какие границы диапазона следует применить.
|
||||
/// </summary>
|
||||
public enum BorderTarget
|
||||
{
|
||||
/// <summary>Все границы (внешние и внутренние) – полная сетка.</summary>
|
||||
All,
|
||||
/// <summary>Только внешние границы диапазона.</summary>
|
||||
Outside,
|
||||
/// <summary>Только внутренние границы (между ячейками).</summary>
|
||||
Inside,
|
||||
/// <summary>Только верхняя граница диапазона.</summary>
|
||||
Top,
|
||||
/// <summary>Только нижняя граница диапазона.</summary>
|
||||
Bottom,
|
||||
/// <summary>Только левая граница диапазона.</summary>
|
||||
Left,
|
||||
/// <summary>Только правая граница диапазона.</summary>
|
||||
Right
|
||||
}
|
||||
Reference in New Issue
Block a user