From 0864d0c841d23ca82937344743004a4573fd5f6f Mon Sep 17 00:00:00 2001 From: VIVIMAN Date: Sat, 3 Sep 2022 23:02:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=90=86=E8=A7=A3?= =?UTF-8?q?=E5=86=B3excel=E4=B8=AD=E5=87=BA=E7=8E=B0=20Print=5FArea=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data_func/go_to_excel_printArea/main.go | 54 +++++++++++++++++++ golang_learn/data_likou/三数之和.go | 1 + 2 files changed, 55 insertions(+) create mode 100644 golang_learn/data_func/go_to_excel_printArea/main.go 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