Browse Source

Merge branch 'bzq1/excel_download_style_cf' of eta_server/eta_api into debug

baoziqiang 6 months ago
parent
commit
2105fae3ed
1 changed files with 14 additions and 13 deletions
  1. 14 13
      services/excel/lucky_sheet.go

+ 14 - 13
services/excel/lucky_sheet.go

@@ -8,6 +8,7 @@ import (
 	"fmt"
 	"os"
 	"reflect"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
@@ -1423,22 +1424,22 @@ func getExcelizeAlignmentConf(cellInfo LuckySheetDataValue) *excelize.Alignment
 
 // getColor 获取hex颜色
 func getColor(bgStr string) string {
-	if strings.Contains(bgStr, "(") {
-		arr := strings.Split(bgStr, ",")
-		if len(arr) != 3 {
+	isRgb := strings.HasPrefix(bgStr, "rgb")
+	re := regexp.MustCompile(`\(([^)]+)\)`)
+	matches := re.FindStringSubmatch(bgStr)
+	if len(matches) != 2 {
+		return bgStr
+	}
+	if isRgb {
+		arr := strings.Split(matches[1], ",")
+		if len(arr) < 3 {
 			return bgStr
 		}
-
-		// 第一位
-		tmpFirstArr := strings.Split(arr[0], "(")
-		arr[0] = tmpFirstArr[len(tmpFirstArr)-1]
-
-		// 最后一位
-		tmpLastArr := strings.Split(arr[2], ")")
-		arr[2] = tmpLastArr[0]
-
 		rgbArr := make([]int64, 0)
-		for _, v := range arr {
+		for i, v := range arr {
+			if i >= 3 {
+				continue
+			}
 			tmpInt, err := strconv.Atoi(utils.TrimStr(v))
 			if err != nil {
 				return bgStr