forked from p30928647/excelize
looping on row col functionality
This commit is contained in:
parent
6185cd577d
commit
37c4575835
|
@ -0,0 +1,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
|
||||||
|
}
|
16
sheet.go
16
sheet.go
|
@ -185,6 +185,22 @@ func (f *File) SetActiveSheet(index int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func (f *File) GetColumnsLength(sheet string) (int, error) {
|
||||||
|
var xlsx xlsxWorksheet
|
||||||
|
name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml`
|
||||||
|
err := xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
|
||||||
|
if ( err != nil ) {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
rows := len(xlsx.SheetData.Row)
|
||||||
|
|
||||||
|
return rows, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Replace xl/workbook.xml XML tags to self-closing for compatible Office Excel 2007.
|
// Replace xl/workbook.xml XML tags to self-closing for compatible Office Excel 2007.
|
||||||
func workBookCompatibility(workbookMarshal string) string {
|
func workBookCompatibility(workbookMarshal string) string {
|
||||||
workbookMarshal = strings.Replace(workbookMarshal, `xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships:id="`, `r:id="`, -1)
|
workbookMarshal = strings.Replace(workbookMarshal, `xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships:id="`, `r:id="`, -1)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue