Browse Source

增加处理解决excel中出现 Print_Area 问题

master
VIVIMAN 2 years ago
parent
commit
0864d0c841
  1. 54
      golang_learn/data_func/go_to_excel_printArea/main.go
  2. 1
      golang_learn/data_likou/三数之和.go

54
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
}

1
golang_learn/data_likou/三数之和.go

@ -58,6 +58,7 @@ a:
arr2 := arr
for i, ints := range arr2 {
arr2[i] = ints[3:]
// TODO
}
return arr2

Loading…
Cancel
Save