diff --git a/apipara.go b/apipara.go
index 4ac1b89..09a6663 100644
--- a/apipara.go
+++ b/apipara.go
@@ -69,3 +69,11 @@ func (p *Paragraph) AddPageBreaks() *Run {
p.Children = append(p.Children, run)
return run
}
+
+func (p *Paragraph) AddStyle(val string) *Paragraph {
+ if p.Properties == nil {
+ p.Properties = &ParagraphProperties{}
+ }
+ p.Properties.Style = &Style{Val: val}
+ return p
+}
diff --git a/apirun.go b/apirun.go
index beb0774..3a88511 100644
--- a/apirun.go
+++ b/apirun.go
@@ -83,6 +83,15 @@ func (r *Run) Highlight(val string) *Run {
return r
}
+func (r *Run) Strike(val bool) *Run {
+ trueFalseStr := "false"
+ if val {
+ trueFalseStr = "true"
+ }
+ r.RunProperties.Strike = &Strike{Val: trueFalseStr}
+ return r
+}
+
// AddTab add a tab in front of the run
func (r *Run) AddTab() *Run {
r.Children = append(r.Children, &Tab{})
diff --git a/apitable.go b/apitable.go
index eede711..de527e7 100644
--- a/apitable.go
+++ b/apitable.go
@@ -20,10 +20,19 @@
package docx
+import (
+ "reflect"
+)
+
// AddTable add a new table to body by col*row
//
// unit: twips (1/20 point)
-func (f *Docx) AddTable(row int, col int) *Table {
+func (f *Docx) AddTable(
+ row int,
+ col int,
+ tableWidth int64,
+ borderColors *APITableBorderColors,
+) *Table {
trs := make([]*WTableRow, row)
for i := 0; i < row; i++ {
cells := make([]*WTableCell, col)
@@ -40,16 +49,25 @@ func (f *Docx) AddTable(row int, col int) *Table {
TableCells: cells,
}
}
+
+ borderColors.applyDefault()
+
+ wTableWidth := &WTableWidth{Type: "auto"}
+
+ if tableWidth > 0 {
+ wTableWidth = &WTableWidth{W: tableWidth}
+ }
+
tbl := &Table{
TableProperties: &WTableProperties{
- Width: &WTableWidth{Type: "auto"},
+ Width: wTableWidth,
TableBorders: &WTableBorders{
- Top: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- Left: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- Bottom: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- Right: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- InsideH: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- InsideV: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
+ Top: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Top},
+ Left: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Left},
+ Bottom: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Bottom},
+ Right: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Right},
+ InsideH: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.InsideH},
+ InsideV: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.InsideV},
},
Look: &WTableLook{
Val: "0000",
@@ -65,7 +83,12 @@ func (f *Docx) AddTable(row int, col int) *Table {
// AddTableTwips add a new table to body by height and width
//
// unit: twips (1/20 point)
-func (f *Docx) AddTableTwips(rowHeights []int64, colWidths []int64) *Table {
+func (f *Docx) AddTableTwips(
+ rowHeights []int64,
+ colWidths []int64,
+ tableWidth int64,
+ borderColors *APITableBorderColors,
+) *Table {
grids := make([]*WGridCol, len(colWidths))
trs := make([]*WTableRow, len(rowHeights))
for i, w := range colWidths {
@@ -95,16 +118,25 @@ func (f *Docx) AddTableTwips(rowHeights []int64, colWidths []int64) *Table {
}
}
}
+
+ borderColors.applyDefault()
+
+ wTableWidth := &WTableWidth{Type: "auto"}
+
+ if tableWidth > 0 {
+ wTableWidth = &WTableWidth{W: tableWidth}
+ }
+
tbl := &Table{
TableProperties: &WTableProperties{
- Width: &WTableWidth{Type: "auto"},
+ Width: wTableWidth,
TableBorders: &WTableBorders{
- Top: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- Left: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- Bottom: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- Right: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- InsideH: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
- InsideV: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: "000000"},
+ Top: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Top},
+ Left: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Left},
+ Bottom: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Bottom},
+ Right: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.Right},
+ InsideH: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.InsideH},
+ InsideV: &WTableBorder{Val: "single", Size: 4, Space: 0, Color: borderColors.InsideV},
},
Look: &WTableLook{
Val: "0000",
@@ -162,3 +194,39 @@ 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
+}
+
+func (tbc *APITableBorderColors) applyDefault() {
+
+ tbcR := reflect.ValueOf(tbc).Elem()
+
+ for i := 0; i < tbcR.NumField(); i++ {
+
+ if tbcR.Field(i).IsZero() {
+
+ tbcR.Field(i).SetString("#000000")
+
+ }
+
+ }
+
+}
diff --git a/structtable_test.go b/structtable_test.go
index 373642b..54536c9 100644
--- a/structtable_test.go
+++ b/structtable_test.go
@@ -29,12 +29,22 @@ import (
)
func TestTableStructure(t *testing.T) {
+
+ borderColors := &APITableBorderColors{
+ "#ff0000",
+ "#ff0000",
+ "#ff0000",
+ "#ff0000",
+ "#ff0000",
+ "",
+ }
+
w := New().WithDefaultTheme()
// add new paragraph
para1 := w.AddParagraph()
// add text
para1.AddText("table")
- tab1 := w.AddTable(4, 3).Justification("center")
+ tab1 := w.AddTable(4, 3, 1000, borderColors).Justification("center")
tab1.TableProperties.Position = &WTablePositioningProperties{LeftFromText: 2333}
para2 := tab1.TableRows[3].Justification("center").TableCells[2].Shade("clear", "auto", "E7E6E6").AddParagraph()
r, err := para2.AddAnchorDrawingFrom("testdata/fumiama.JPG")
diff --git a/xml/default/word/fontTable.xml b/xml/default/word/fontTable.xml
old mode 100755
new mode 100644
index a53ce5d..8ffd499
--- a/xml/default/word/fontTable.xml
+++ b/xml/default/word/fontTable.xml
@@ -38,4 +38,4 @@
-
\ No newline at end of file
+
diff --git a/xml/default/word/styles.xml b/xml/default/word/styles.xml
index 714439c..42a6f84 100644
--- a/xml/default/word/styles.xml
+++ b/xml/default/word/styles.xml
@@ -461,4 +461,4 @@
-
\ No newline at end of file
+