excel.go 993 字节
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,
	}
}