mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-18 08:24:11 +08:00
fix: tidy formats
This commit is contained in:
47
apitable.go
47
apitable.go
@@ -28,9 +28,9 @@ import (
|
|||||||
//
|
//
|
||||||
// unit: twips (1/20 point)
|
// unit: twips (1/20 point)
|
||||||
func (f *Docx) AddTable(
|
func (f *Docx) AddTable(
|
||||||
row int,
|
row int,
|
||||||
col int,
|
col int,
|
||||||
tableWidth int64,
|
tableWidth int64,
|
||||||
borderColors *APITableBorderColors,
|
borderColors *APITableBorderColors,
|
||||||
) *Table {
|
) *Table {
|
||||||
trs := make([]*WTableRow, row)
|
trs := make([]*WTableRow, row)
|
||||||
@@ -50,6 +50,9 @@ func (f *Docx) AddTable(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if borderColors == nil {
|
||||||
|
borderColors = new(APITableBorderColors)
|
||||||
|
}
|
||||||
borderColors.applyDefault()
|
borderColors.applyDefault()
|
||||||
|
|
||||||
wTableWidth := &WTableWidth{Type: "auto"}
|
wTableWidth := &WTableWidth{Type: "auto"}
|
||||||
@@ -57,7 +60,7 @@ func (f *Docx) AddTable(
|
|||||||
if tableWidth > 0 {
|
if tableWidth > 0 {
|
||||||
wTableWidth = &WTableWidth{W: tableWidth}
|
wTableWidth = &WTableWidth{W: tableWidth}
|
||||||
}
|
}
|
||||||
|
|
||||||
tbl := &Table{
|
tbl := &Table{
|
||||||
TableProperties: &WTableProperties{
|
TableProperties: &WTableProperties{
|
||||||
Width: wTableWidth,
|
Width: wTableWidth,
|
||||||
@@ -84,10 +87,10 @@ func (f *Docx) AddTable(
|
|||||||
//
|
//
|
||||||
// unit: twips (1/20 point)
|
// unit: twips (1/20 point)
|
||||||
func (f *Docx) AddTableTwips(
|
func (f *Docx) AddTableTwips(
|
||||||
rowHeights []int64,
|
rowHeights []int64,
|
||||||
colWidths []int64,
|
colWidths []int64,
|
||||||
tableWidth int64,
|
tableWidth int64,
|
||||||
borderColors *APITableBorderColors,
|
borderColors *APITableBorderColors,
|
||||||
) *Table {
|
) *Table {
|
||||||
grids := make([]*WGridCol, len(colWidths))
|
grids := make([]*WGridCol, len(colWidths))
|
||||||
trs := make([]*WTableRow, len(rowHeights))
|
trs := make([]*WTableRow, len(rowHeights))
|
||||||
@@ -118,7 +121,10 @@ func (f *Docx) AddTableTwips(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if borderColors == nil {
|
||||||
|
borderColors = new(APITableBorderColors)
|
||||||
|
}
|
||||||
borderColors.applyDefault()
|
borderColors.applyDefault()
|
||||||
|
|
||||||
wTableWidth := &WTableWidth{Type: "auto"}
|
wTableWidth := &WTableWidth{Type: "auto"}
|
||||||
@@ -195,24 +201,13 @@ func (c *WTableCell) Shade(val, color, fill string) *WTableCell {
|
|||||||
return c
|
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 {
|
type APITableBorderColors struct {
|
||||||
Top string
|
Top string
|
||||||
Left string
|
Left string
|
||||||
Bottom string
|
Bottom string
|
||||||
Right string
|
Right string
|
||||||
InsideH string
|
InsideH string
|
||||||
InsideV string
|
InsideV string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tbc *APITableBorderColors) applyDefault() {
|
func (tbc *APITableBorderColors) applyDefault() {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func main() {
|
|||||||
|
|
||||||
w.AddParagraph()
|
w.AddParagraph()
|
||||||
|
|
||||||
tbl1 := w.AddTable(9, 9)
|
tbl1 := w.AddTable(9, 9, 0, nil)
|
||||||
for x, r := range tbl1.TableRows {
|
for x, r := range tbl1.TableRows {
|
||||||
red := (x + 1) * 28
|
red := (x + 1) * 28
|
||||||
for y, c := range r.TableCells {
|
for y, c := range r.TableCells {
|
||||||
@@ -121,7 +121,7 @@ func main() {
|
|||||||
|
|
||||||
w.AddParagraph()
|
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 {
|
for x, r := range tbl2.TableRows {
|
||||||
r.Justification("center")
|
r.Justification("center")
|
||||||
for y, c := range r.TableCells {
|
for y, c := range r.TableCells {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
func TestTableStructure(t *testing.T) {
|
func TestTableStructure(t *testing.T) {
|
||||||
|
|
||||||
borderColors := &APITableBorderColors{
|
borderColors := &APITableBorderColors{
|
||||||
"#ff0000",
|
"#ff0000",
|
||||||
"#ff0000",
|
"#ff0000",
|
||||||
"#ff0000",
|
"#ff0000",
|
||||||
|
|||||||
Reference in New Issue
Block a user