Skip to content

Commit

Permalink
fix(helpdoc): 过滤掉 xlsx 格式的 helpdoc 的第一行,并增加表头格式校验 (#404)
Browse files Browse the repository at this point in the history
* fix(helpdoc): 过滤掉 xlsx 格式的 helpdoc 的第一行

* feat(helpdoc): 增加 xlsx 格式 helpdoc 的表头验证

* feat(helpdoc): 微调表头校验报错信息
  • Loading branch information
JustAnotherID authored Nov 14, 2023
1 parent 7910d58 commit e872e57
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions dice/dice_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,20 @@ func (m *HelpManager) loadHelpDoc(group string, path string) bool {
break
}

for _, s := range f.GetSheetList() {
for index, s := range f.GetSheetList() {
rows, err := f.GetRows(s)
if err == nil {
for _, row := range rows {
// Keys Synonym Content Description Catalogue Tag
for i, row := range rows {
if i == 0 {
err := checkXlsxHeaders(row)
if err == nil {
// 跳过第一行
continue
} else {
fmt.Printf("%s sheet %d: %s\n", path, index, err)
break
}
}
if len(row) < 3 {
continue
}
Expand Down Expand Up @@ -313,6 +322,20 @@ func (m *HelpManager) loadHelpDoc(group string, path string) bool {
return false
}

// checkXlsxHeaders 验证 xlsx 格式 helpdoc 的表头是否是 Key Synonym Content Description Catalogue Tag
func checkXlsxHeaders(headers []string) error {
if len(headers) == 6 &&
headers[0] == "Key" &&
headers[1] == "Synonym" &&
headers[2] == "Content" &&
headers[3] == "Description" &&
headers[4] == "Catalogue" &&
headers[5] == "Tag" {
return nil
}
return fmt.Errorf("helpdoc表头格式错误")
}

func (dm *DiceManager) AddHelpWithDice(dice *Dice) {
m := dm.Help

Expand Down

0 comments on commit e872e57

Please sign in to comment.