diff --git a/golang_learn/data_func/go_to_excel_printArea/main.go b/golang_learn/data_func/go_to_excel_printArea/main.go new file mode 100644 index 0000000..a2ea339 --- /dev/null +++ b/golang_learn/data_func/go_to_excel_printArea/main.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "strconv" + "strings" +) + +var replaceword = []string{"_xlnm.Print_Title", "_xlnm.Print_Area"} + +func main() { + + pwd, _ := os.Getwd() + //获取文件或目录相关信息 + fileInfoList, err := ioutil.ReadDir(pwd) + if err != nil { + err = fmt.Errorf("发生异常:%s", err) + } + fmt.Println(len(fileInfoList)) + for i := range fileInfoList { + name := fileInfoList[i].Name() + if strings.HasSuffix(name, "xlsx") || strings.HasSuffix(name, "xls") { + fmt.Printf("%s 执行 %v \n", name, make(name, "new-"+name)) + } + } +} + +func make(inFilePath string, outFilePath string) bool { + f, err := os.Open(inFilePath) + if err != nil { + err = fmt.Errorf("发生异常 Open :%s", err) + return false + } + + fSrc, err := ioutil.ReadAll(f) + if err != nil { + err = fmt.Errorf("发生异常 ReadAll :%s", err) + return false + } + s := string(fSrc) + for _, w := range replaceword { + for i := 0; ; i++ { + ind := strings.Index(s, w) + if ind < 0 { + break + } + s = strings.Replace(s, w, w[:len(w)-1]+strconv.Itoa(i), 1) + } + } + _ = ioutil.WriteFile(outFilePath, []byte(s), os.ModeAppend) + return true +} diff --git a/golang_learn/data_likou/三数之和.go b/golang_learn/data_likou/三数之和.go index 47eadef..e672e16 100644 --- a/golang_learn/data_likou/三数之和.go +++ b/golang_learn/data_likou/三数之和.go @@ -58,6 +58,7 @@ a: arr2 := arr for i, ints := range arr2 { arr2[i] = ints[3:] + // TODO } return arr2