Skip to content

Commit

Permalink
- Set name of table support in AddTable(), relate issue qax-os#216;
Browse files Browse the repository at this point in the history
- godoc and go test has been updated
  • Loading branch information
xuri committed May 4, 2018
1 parent 200437d commit 934ecec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func TestAddTable(t *testing.T) {
t.Log(err)
}
xlsx.AddTable("Sheet1", "B26", "A21", ``)
xlsx.AddTable("Sheet2", "A2", "B5", `{"table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
xlsx.AddTable("Sheet2", "A2", "B5", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
xlsx.AddTable("Sheet2", "F1", "F1", `{"table_style":"TableStyleMedium8"}`)
err = xlsx.Save()
if err != nil {
Expand Down
13 changes: 9 additions & 4 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ func parseFormatTableSet(formatSet string) *formatTable {
//
// Create a table of F2:H6 on Sheet2 with format set:
//
// xlsx.AddTable("Sheet2", "F2", "H6", `{"table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
// xlsx.AddTable("Sheet2", "F2", "H6", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`)
//
// Note that the table at least two lines include string type header. The two
// chart coordinate areas can not have an intersection.
// Note that the table at least two lines include string type header. Multiple
// tables coordinate areas can't have an intersection.
//
// table_name: The name of the table, in the same worksheet name of the table should be unique
//
// table_style: The built-in table style names
//
Expand Down Expand Up @@ -122,7 +124,10 @@ func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis,
Name: name,
})
}
name := "Table" + strconv.Itoa(i)
name := formatSet.TableName
if name == "" {
name = "Table" + strconv.Itoa(i)
}
t := xlsxTable{
XMLNS: NameSpaceSpreadSheet,
ID: i,
Expand Down
1 change: 1 addition & 0 deletions xmlTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type xlsxTableStyleInfo struct {

// formatTable directly maps the format settings of the table.
type formatTable struct {
TableName string `json:"table_name"`
TableStyle string `json:"table_style"`
ShowFirstColumn bool `json:"show_first_column"`
ShowLastColumn bool `json:"show_last_column"`
Expand Down

0 comments on commit 934ecec

Please sign in to comment.