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 excelize
import (
"encoding/xml"
"strings"
"strconv"
)
// GetRows return all the rows in a sheet
func (f *File) GetRows(sheet string) ([]xlsxRow, error) {
var xlsx xlsxWorksheet
name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
err := xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
if ( err != nil ) {
return nil, err
}
rows := xlsx.SheetData.Row
return rows, nil
}
// readXMLSST read xmlSST simple function
func readXMLSST(f *File) (xlsxSST, error) {
shardStrings := xlsxSST{}
err := xml.Unmarshal([]byte(f.readXML(`xl/sharedStrings.xml`)), &shardStrings)
return shardStrings, err
}
// GetValueFrom return a value from a column/row cell,
// this function is inteded to be used with for range on rows
// an argument with the xlsx opened file
func (self* xlsxC) GetValueFrom(f *File) (string, error) {
switch self.T {
case "s":
xlsxSI := 0
xlsxSI, _ = strconv.Atoi(self.V)
d, err := readXMLSST(f)
if ( err != nil ) {
return "", err
}
return d.SI[xlsxSI].T, nil
case "str":
return self.V, nil
default:
return self.V, nil
} // switch
}
|