Skip to content

Commit

Permalink
fix: tidy formats
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Sep 24, 2024
1 parent 7782d22 commit 753783d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
47 changes: 21 additions & 26 deletions apitable.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
//
// unit: twips (1/20 point)
func (f *Docx) AddTable(
row int,
col int,
tableWidth int64,
row int,
col int,
tableWidth int64,
borderColors *APITableBorderColors,
) *Table {
trs := make([]*WTableRow, row)
Expand All @@ -50,14 +50,17 @@ func (f *Docx) AddTable(
}
}

if borderColors == nil {
borderColors = new(APITableBorderColors)
}
borderColors.applyDefault()

wTableWidth := &WTableWidth{Type: "auto"}

if tableWidth > 0 {
wTableWidth = &WTableWidth{W: tableWidth}
}

tbl := &Table{
TableProperties: &WTableProperties{
Width: wTableWidth,
Expand All @@ -84,10 +87,10 @@ func (f *Docx) AddTable(
//
// unit: twips (1/20 point)
func (f *Docx) AddTableTwips(
rowHeights []int64,
colWidths []int64,
tableWidth int64,
borderColors *APITableBorderColors,
rowHeights []int64,
colWidths []int64,
tableWidth int64,
borderColors *APITableBorderColors,
) *Table {
grids := make([]*WGridCol, len(colWidths))
trs := make([]*WTableRow, len(rowHeights))
Expand Down Expand Up @@ -118,7 +121,10 @@ func (f *Docx) AddTableTwips(
}
}
}


if borderColors == nil {
borderColors = new(APITableBorderColors)
}
borderColors.applyDefault()

wTableWidth := &WTableWidth{Type: "auto"}
Expand Down Expand Up @@ -195,24 +201,13 @@ func (c *WTableCell) Shade(val, color, fill string) *WTableCell {
return c
}

//Replaces any index that is blank with "#000000"
func CheckBorderColors (borderColors [6]string) [6]string {
for i, _ := range borderColors{
if borderColors[i] == "" {
borderColors[i] = "#000000"
}
}

return borderColors
}

type APITableBorderColors struct {
Top string
Left string
Bottom string
Right string
InsideH string
InsideV string
Top string
Left string
Bottom string
Right string
InsideH string
InsideV string
}

func (tbc *APITableBorderColors) applyDefault() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {

w.AddParagraph()

tbl1 := w.AddTable(9, 9)
tbl1 := w.AddTable(9, 9, 0, nil)
for x, r := range tbl1.TableRows {
red := (x + 1) * 28
for y, c := range r.TableCells {
Expand All @@ -121,7 +121,7 @@ func main() {

w.AddParagraph()

tbl2 := w.AddTableTwips([]int64{2333, 2333, 2333}, []int64{2333, 2333}).Justification("center")
tbl2 := w.AddTableTwips([]int64{2333, 2333, 2333}, []int64{2333, 2333}, 0, nil).Justification("center")
for x, r := range tbl2.TableRows {
r.Justification("center")
for y, c := range r.TableCells {
Expand Down
2 changes: 1 addition & 1 deletion structtable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestTableStructure(t *testing.T) {

borderColors := &APITableBorderColors{
borderColors := &APITableBorderColors{
"#ff0000",
"#ff0000",
"#ff0000",
Expand Down

0 comments on commit 753783d

Please sign in to comment.