-
Notifications
You must be signed in to change notification settings - Fork 0
/
excel.go
46 lines (40 loc) · 1.02 KB
/
excel.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
package gutils
import (
"github.com/aswjh/excel"
"time"
"runtime"
)
const (
xlsx = 51
xls = 56
html = 44
)
func convertFile(inputFile, outputFile string, fmt interface{}) bool {
old:=runtime.GOMAXPROCS(1)
options := excel.Option{"Visible": false, "DisplayAlerts": true}
xl, _ := excel.Open(inputFile, options)
defer xl.Quit()
time.Sleep(3000000000)
xl.SaveAs(outputFile, fmt)
runtime.GOMAXPROCS(old)
return true
}
//xlsFilePath,outXlsxPath must Absolute path
//convert xls to xlsx
func ToXlsx(xlsFilePath, outXlsxPath string) bool {
isSuc := convertFile(xlsFilePath, outXlsxPath, xlsx)
return isSuc
}
//xlsFilePath,outXlsxPath must Absolute path
//convert xlsx to xlsx
func ToXls(xlsFilePath, outXlsxPath string)bool{
isSuc := convertFile(xlsFilePath, outXlsxPath, xls)
return isSuc
}
//xlsFilePath,outXlsxPath must Absolute path
//convert xls or xlsx to html
//Equivalent to excel soft "Save As"
func ToHtml(xlsFilePath, outHtmlPath string) bool {
isSuc := convertFile(xlsFilePath, outHtmlPath, html)
return isSuc
}