-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (43 loc) · 939 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/base64"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"os"
"sync"
"time"
)
var wg sync.WaitGroup //定义一个同步等待的组
func main() {
startTime := time.Now()
f, err := excelize.OpenFile("base64.xlsx")
if err != nil {
fmt.Println(err)
return
}
const PICPATH = "pics"
os.Mkdir(PICPATH, os.ModePerm)
rows := f.GetRows("Sheet1")
for i, v := range rows {
if i == 0 {
continue
}
base64code := v[2]
filename := v[0] + "." + v[1]
dist, _ := base64.StdEncoding.DecodeString(base64code)
wg.Add(1)
go writePic(PICPATH, filename, dist)
}
wg.Wait()
elapsed := time.Since(startTime)
fmt.Println("耗时", elapsed)
fmt.Println("按回车键退出")
fmt.Scanln()
}
func writePic(PICPATH string, filename string, dist []byte) {
//写入新文件
f, _ := os.OpenFile(PICPATH+"/"+filename, os.O_RDWR|os.O_CREATE, os.ModePerm)
f.Write(dist)
f.Close()
wg.Done()
}