2026-06-08 14:31:31 +07:00
|
|
|
namespace QWERTYkez.WordProcessor;
|
2026-06-05 15:58:03 +07:00
|
|
|
|
|
|
|
|
public readonly struct CellProps(double? width = null!)
|
|
|
|
|
{
|
|
|
|
|
public double? Width { get; init; } = width;
|
|
|
|
|
public TableVerticalAlignmentValues? VerticalAlignment { get; init; } = default;
|
|
|
|
|
public MergedCell? Merge { get; init; } = default;
|
2026-09-24 14:09:37 +07:00
|
|
|
public TextDirection TextDirection { get; init; } = TextDirection.LeftToRight;
|
2026-06-05 15:58:03 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable IDE1006 // Стили именования
|
|
|
|
|
public static CellProps V_H_ { get; } = new() { Merge = MergedCell.V_H_ };
|
|
|
|
|
public static CellProps H_ { get; } = new() { Merge = MergedCell.H_ };
|
|
|
|
|
public static CellProps V_ { get; } = new() { Merge = MergedCell.V_ };
|
|
|
|
|
public static CellProps _V_H { get; } = new() { Merge = MergedCell._V_H };
|
|
|
|
|
public static CellProps _H { get; } = new() { Merge = MergedCell._H };
|
|
|
|
|
public static CellProps _V { get; } = new() { Merge = MergedCell._V };
|
|
|
|
|
public static CellProps _VH_ { get; } = new() { Merge = MergedCell._VH_ };
|
|
|
|
|
public static CellProps V__H { get; } = new() { Merge = MergedCell.V__H };
|
|
|
|
|
#pragma warning restore IDE1006 // Стили именования
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal bool TryExtract(out List<OpenXmlElement> list)
|
|
|
|
|
{
|
|
|
|
|
list =
|
|
|
|
|
[
|
|
|
|
|
new TableCellVerticalAlignment() { Val = VerticalAlignment ?? TableVerticalAlignmentValues.Center },
|
|
|
|
|
new TableCellMargin()
|
|
|
|
|
{
|
|
|
|
|
TopMargin = new TopMargin() { Width = "0" },
|
|
|
|
|
BottomMargin = new BottomMargin() { Width = "0" },
|
|
|
|
|
LeftMargin = new LeftMargin() { Width = "0" },
|
|
|
|
|
RightMargin = new RightMargin() { Width = "0" }
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (Width.HasValue)
|
|
|
|
|
list.Add(new TableCellWidth()
|
|
|
|
|
{
|
|
|
|
|
Type = TableWidthUnitValues.Dxa,
|
|
|
|
|
Width = ((uint)(Width.Value * 567d)).ToString() // 1 см = 567 DXA
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-24 14:09:37 +07:00
|
|
|
if (TextDirection is not TextDirection.LeftToRight)
|
|
|
|
|
{
|
|
|
|
|
list.Add(new DocumentFormat.OpenXml.Wordprocessing.TextDirection
|
|
|
|
|
{
|
|
|
|
|
Val = TextDirection switch
|
|
|
|
|
{
|
|
|
|
|
TextDirection.BottomToTop => TextDirectionValues.BottomToTopLeftToRight,
|
|
|
|
|
TextDirection.TopToBottom => TextDirectionValues.TopToBottomRightToLeft,
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(TextDirection), TextDirection, "Unsupported text direction"),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 15:58:03 +07:00
|
|
|
if (Merge.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (Merge.Value)
|
|
|
|
|
{
|
|
|
|
|
case MergedCell.V_H_:
|
|
|
|
|
list.Add(new HorizontalMerge() { Val = MergedCellValues.Restart });
|
|
|
|
|
list.Add(new VerticalMerge() { Val = MergedCellValues.Restart });
|
|
|
|
|
break;
|
|
|
|
|
case MergedCell.H_:
|
|
|
|
|
list.Add(new HorizontalMerge() { Val = MergedCellValues.Restart }); break;
|
|
|
|
|
case MergedCell.V_:
|
|
|
|
|
list.Add(new VerticalMerge() { Val = MergedCellValues.Restart }); break;
|
|
|
|
|
case MergedCell._V_H:
|
|
|
|
|
list.Add(new HorizontalMerge() { Val = MergedCellValues.Continue });
|
|
|
|
|
list.Add(new VerticalMerge() { Val = MergedCellValues.Continue });
|
|
|
|
|
break;
|
|
|
|
|
case MergedCell._H:
|
|
|
|
|
list.Add(new HorizontalMerge() { Val = MergedCellValues.Continue }); break;
|
|
|
|
|
case MergedCell._V:
|
|
|
|
|
list.Add(new VerticalMerge() { Val = MergedCellValues.Continue }); break;
|
|
|
|
|
case MergedCell._VH_:
|
|
|
|
|
list.Add(new HorizontalMerge() { Val = MergedCellValues.Restart });
|
|
|
|
|
list.Add(new VerticalMerge() { Val = MergedCellValues.Continue });
|
|
|
|
|
break;
|
|
|
|
|
case MergedCell.V__H:
|
|
|
|
|
list.Add(new HorizontalMerge() { Val = MergedCellValues.Continue });
|
|
|
|
|
list.Add(new VerticalMerge() { Val = MergedCellValues.Restart });
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public enum MergedCell
|
|
|
|
|
{
|
|
|
|
|
V_H_,
|
|
|
|
|
H_,
|
|
|
|
|
V_,
|
|
|
|
|
|
|
|
|
|
_V_H,
|
|
|
|
|
_H,
|
|
|
|
|
_V,
|
|
|
|
|
|
|
|
|
|
_VH_,
|
|
|
|
|
V__H,
|
2026-09-24 14:09:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum TextDirection
|
|
|
|
|
{
|
|
|
|
|
/// <summary> ⇒ ⇒ ⇒ Стандартный свева направо </summary>
|
|
|
|
|
LeftToRight,
|
|
|
|
|
/// <summary> ⇑ ⇑ ⇑ Снизу вверх </summary>
|
|
|
|
|
BottomToTop,
|
|
|
|
|
/// <summary> ⇓ ⇓ ⇓ Сверху вниз </summary>
|
|
|
|
|
TopToBottom,
|
2026-06-05 15:58:03 +07:00
|
|
|
}
|