diff --git a/internal/serializer/serializer.go b/internal/serializer/serializer.go index 3ed95a1..1905083 100644 --- a/internal/serializer/serializer.go +++ b/internal/serializer/serializer.go @@ -780,9 +780,27 @@ func (s *TableSerializer) serializeCellProperties(cell domain.TableCell) *xml.Ta } } + // Borders (table cell borders) + borders := cell.Borders() + if s.hasTableBorders(borders) { + props.Borders = &xml.TableBorders{ + Top: s.paraSerializer.serializeBorder(borders.Top), + Bottom: s.paraSerializer.serializeBorder(borders.Bottom), + Left: s.paraSerializer.serializeBorder(borders.Left), + Right: s.paraSerializer.serializeBorder(borders.Right), + } + } + return props } +func (s *TableSerializer) hasTableBorders(borders domain.TableBorders) bool { + return borders.Top.Style != domain.BorderNone || + borders.Bottom.Style != domain.BorderNone || + borders.Left.Style != domain.BorderNone || + borders.Right.Style != domain.BorderNone +} + func (s *TableSerializer) widthTypeToString(wType domain.WidthType) string { switch wType { case domain.WidthAuto: diff --git a/internal/serializer/serializer_test.go b/internal/serializer/serializer_test.go index b7685ec..9d8e9ae 100644 --- a/internal/serializer/serializer_test.go +++ b/internal/serializer/serializer_test.go @@ -185,6 +185,11 @@ func TestTableSerializer(t *testing.T) { // Fill first cell row0, _ := table.Row(0) cell, _ := row0.Cell(0) + cell.SetBorders(domain.TableBorders{Top: domain.BorderStyle{ + Style: domain.BorderSingle, + Width: 4, + Color: domain.ColorRed, + }}) cellPara, _ := cell.AddParagraph() cellRun, _ := cellPara.AddRun() cellRun.SetText("Cell 0,0") @@ -212,6 +217,10 @@ func TestTableSerializer(t *testing.T) { if len(firstCell.Content) == 0 { t.Fatal("expected at least one element in first cell content") } + + if firstCell.Properties.Borders == nil || firstCell.Properties.Borders.Top == nil { + t.Errorf("expected border top to be set") + } firstPara, ok := firstCell.Content[0].(*xmlstructs.Paragraph) if !ok { t.Fatalf("expected first content element to be paragraph, got %T", firstCell.Content[0])