Skip to content

Commit

Permalink
Merge pull request #50 from ofipify/main
Browse files Browse the repository at this point in the history
A few functions exposing underlying properties
  • Loading branch information
gomutex authored Jan 12, 2025
2 parents 66ab8cd + c178d5f commit 7b28b7b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docx/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,15 @@ func (r *Run) Style(value string) *Run {
r.getProp().Style = ctypes.NewRunStyle(value)
return r
}

// VerticalAlign sets the vertical alignment for the run text.
//
// Parameter: A value from the stypes.VerticalAlignRun type indicating the desired vertical alignment. One of:
//
// VerticalAlignRunBaseline, VerticalAlignRunSuperscript, VerticalAlignRunSubscript
//
// Returns: The modified Run instance with the updated vertical alignment.
func (r *Run) VerticalAlign(value stypes.VerticalAlignRun) *Run {
r.getProp().VertAlign = ctypes.NewGenSingleStrVal(value)
return r
}
51 changes: 51 additions & 0 deletions docx/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ func (t *Table) unmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return t.ct.UnmarshalXML(d, start)
}

func (t *Table) Width(v int, u stypes.TableWidth) *Table {
w := ctypes.TableWidth{
Width: &v,
WidthType: &u,
}
t.ct.TableProp.Width = &w
return t
}

func (t *Table) Grid(widths ...uint64) *Table {
for _, w := range widths {
col := ctypes.Column{Width: &w}
t.ct.Grid.Col = append(t.ct.Grid.Col, col)
}
return t
}

func NewTable(root *RootDoc) *Table {
return &Table{
root: root,
Expand Down Expand Up @@ -196,3 +213,37 @@ func (c *Cell) AddEmptyPara() *Paragraph {

return p
}

// ColSpan sets the number of columns a cell should span across in a table.
func (c *Cell) ColSpan(cols int) *Cell {
if c.ct.Property != nil {
c.ct.Property.GridSpan = &ctypes.DecimalNum{Val: cols}
}
return c
}

// RowSpan sets the cell to span vertically in a table, indicating it is part of a vertically merged group of cells.
func (c *Cell) RowSpan() *Cell {
if c.ct.Property != nil {
vMerge := ctypes.AnnotationVMergeRest
c.ct.Property.CellMerge = &ctypes.CellMerge{
VMerge: &vMerge,
}
}
return c
}

// VerticalAlign sets the vertical alignment of a cell based on the provided string: "top", "center", "middle", or "bottom".
func (c *Cell) VerticalAlign(valign string) *Cell {
if c.ct.Property != nil {
switch valign {
case "top":
c.ct.Property.VAlign = ctypes.NewGenSingleStrVal(stypes.VerticalJcTop)
case "center", "middle":
c.ct.Property.VAlign = ctypes.NewGenSingleStrVal(stypes.VerticalJcCenter)
case "bottom":
c.ct.Property.VAlign = ctypes.NewGenSingleStrVal(stypes.VerticalJcBottom)
}
}
return c
}

0 comments on commit 7b28b7b

Please sign in to comment.