excel.go
993 字节
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
48
49
50
package excel
import (
"io"
"path/filepath"
)
type Importer struct {
RowBegin int //第几行开始
ColumnBegin int //第几列开始,
ColumnEnd int //第几列结束,
Sheet string //获取的表格
reader Reader
FileName string
}
func (excelImport Importer) OpenExcelFromIoReader(r io.ReadSeeker) ([][]string, error) {
return excelImport.reader.Read(&excelImport, r)
}
func (excelImport Importer) Reader() Reader {
return excelImport.reader
}
func NewExcelImport(reader Reader) *Importer {
return &Importer{
RowBegin: 1,
ColumnBegin: 1,
Sheet: "Sheet1",
reader: reader,
}
}
func NewExcelImportByFile(fileName string) *Importer {
ext := filepath.Ext(fileName)
var reader Reader
if ext == ".xls" {
reader = &XLSReader{}
} else if ext == ".csv" {
reader = &CSVReader{}
} else {
reader = &XLXSReader{}
}
return &Importer{
RowBegin: 1,
ColumnBegin: 1,
Sheet: "Sheet1",
reader: reader,
}
}