瀏覽代碼

多余的数据行直接跳出

xyxie 1 年之前
父節點
當前提交
de5361542f
共有 1 個文件被更改,包括 32 次插入0 次删除
  1. 32 0
      services/base_from_yongyi_v2/daily.go

+ 32 - 0
services/base_from_yongyi_v2/daily.go

@@ -40,8 +40,12 @@ func HandleYongyiExcelDaily1(f *excelize.File, sheetName string) (indexList []*m
 		err = fmt.Errorf("获取合并单元格失败, sheetName: %s", sheetName)
 		return
 	}
+	stopFlag := false
 	for i, row := range rows {
 		fmt.Printf("当前第%d行 \n", i)
+		if stopFlag {
+			break
+		}
 		currentMergeCells, mergeOk := mergeCellMap[i]
 
 		// 首行,表示时间
@@ -88,6 +92,10 @@ func HandleYongyiExcelDaily1(f *excelize.File, sheetName string) (indexList []*m
 				text = strings.TrimSpace(text)
 				fmt.Printf("当前第%d列 \n", k)
 				if k == 0 {
+					if text == "" {
+						stopFlag = true
+						break
+					}
 					province = text
 					continue
 				} else if k == 1 {
@@ -194,8 +202,12 @@ func HandleYongyiExcelDaily2(f *excelize.File, sheetName string) (indexList []*m
 		err = fmt.Errorf("获取合并单元格失败, sheetName: %s", sheetName)
 		return
 	}
+	stopFlag := false
 	for i, row := range rows {
 		fmt.Printf("当前第%d行 \n", i)
+		if stopFlag {
+			break
+		}
 		currentMergeCells, mergeOk := mergeCellMap[i]
 
 		// 首行,表示时间
@@ -242,6 +254,10 @@ func HandleYongyiExcelDaily2(f *excelize.File, sheetName string) (indexList []*m
 				text = strings.TrimSpace(text)
 				fmt.Printf("当前第%d列 \n", k)
 				if k == 0 {
+					if text == "" { // 第一列为空
+						stopFlag = true
+						break
+					}
 					province = text
 					continue
 				} else {
@@ -348,8 +364,12 @@ func HandleYongyiExcelDaily3(f *excelize.File, sheetName string) (indexList []*m
 	// 指标名称
 	indexMap := make(map[string]*models.YongyiExcelIndex)
 
+	stopFlag := false
 	for i, row := range rows {
 		fmt.Printf("当前第%d行 \n", i)
+		if stopFlag {
+			break
+		}
 		// 首行,表示时间
 		if i == 0 {
 			for k, text := range row {
@@ -366,6 +386,10 @@ func HandleYongyiExcelDaily3(f *excelize.File, sheetName string) (indexList []*m
 				text = strings.TrimSpace(text)
 				fmt.Printf("当前第%d列 \n", k)
 				if k == 0 {
+					if text == "" { // 第一列为空
+						stopFlag = true
+						break
+					}
 					var dateT time.Time
 					dateT, e = time.ParseInLocation("01-2-06", text, time.Local)
 					if e != nil {
@@ -461,8 +485,12 @@ func HandleYongyiExcelDaily4(f *excelize.File, sheetName string) (indexList []*m
 	// 指标名称
 	indexMap := make(map[string]*models.YongyiExcelIndex)
 
+	stopFlag := false
 	for i, row := range rows {
 		fmt.Printf("当前第%d行 \n", i)
+		if stopFlag {
+			break
+		}
 		// 首行,表示时间
 		if i == 0 {
 			for k, text := range row {
@@ -501,6 +529,10 @@ func HandleYongyiExcelDaily4(f *excelize.File, sheetName string) (indexList []*m
 				text = strings.TrimSpace(text)
 				fmt.Printf("当前第%d列 \n", k)
 				if k == 0 {
+					if text == "" { // 第一列为空
+						stopFlag = true
+						break
+					}
 					province = text
 					continue
 				} else {