Browse Source

测试

master
viviman 4 years ago
parent
commit
10418afb7d
  1. 28
      golang_learn/data_office/get_excel_velidation/config.yaml
  2. 25
      golang_learn/data_office/get_excel_velidation/使用配置文件添加校验规则.go

28
golang_learn/data_office/get_excel_velidation/config.yaml

@ -1,7 +1,17 @@
文件: E:\b.xlsx
另存为: E:\b_new.xlsx
页签: 第二页
开始行: 2
开始列:
截至行: 200
开始列: # 均从 A B C 的顺序排列,无限制,仅需要 补充写 0 即可
- A
- B
- C
- D
- E
- F
- G
长度:
- 0,20 # A
- 0,2 # B
- 0,1 # C
@ -9,3 +19,19 @@
- 3,6 # E
- 2,7 # F
- 1,8 # G
类型:
- 字符串 # A
- 文本 # B
- 列表 # C
- 时间 # D
- 金额 # E
- 百分值 # F
- 日期 # G
范围:
- 0 # A
- 0 # B
- 1, 2, 3 # C 仅限 1 2 3
- 0, 120609 # D 仅限 hhddmm (开始, 截至)
- 0 # E
- 0 # F
- 20200306, 20210306 # G 仅限 yyyyMMdd (开始, 截至)

25
golang_learn/data_office/get_excel_velidation/使用配置文件添加校验规则.go

@ -16,20 +16,31 @@ func main() {
}
pathFile := config.Book
savePath := config.Save
sheetName := config.Sheet
glog.Info("打开文件文件:", pathFile)
cellNum := config.CellNum
long := config.Longs
types := config.Types
ranges := config.Ranges
glog.Info("配置文件:", pathFile, savePath, sheetName, cellNum, long, types, ranges)
xlsx, err := excelize.OpenFile(pathFile)
if err != nil {
glog.Error("打开文件失败!")
return
}
glog.Info("开始-读取文件内容获取异常单元格列表...")
cells, err := readExcel2(xlsx, sheetName)
dvRange := excelize.NewDataValidation(true)
dvRange.Sqref = "A1:B2"
dvRange.SetRange(10, 20, excelize.DataValidationTypeWhole, excelize.DataValidationOperatorBetween)
dvRange.SetError(excelize.DataValidationErrorStyleStop, "发现错误", "您输入的内容不符合规范")
xlsx.AddDataValidation(sheetName, dvRange)
err = xlsx.SaveAs(savePath)
if err != nil {
glog.Info("发生异常:", err)
return
}
for _, s := range cells {
for _, s := range cellNum {
glog.Info("xxx:", s)
}
@ -96,9 +107,13 @@ func initFunc2() *Config2 {
type Config2 struct {
Book string `yaml:"文件"`
Save string `yaml:"另存为"`
Sheet string `yaml:"页签"`
RowNum string `yaml:"开始行"`
RowNum int `yaml:"开始行"`
CellNum []string `yaml:"开始列"`
Longs []string `yaml:"长度"`
Types []string `yaml:"类型"`
Ranges []string `yaml:"范围"`
}
/**

Loading…
Cancel
Save