forked from qax-os/excelize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Optimisation code use fmt package - Update README - Remove useless function
- Loading branch information
Showing
7 changed files
with
94 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package excelize | ||
|
||
import ( | ||
"encoding/xml" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Get value from cell by given sheet index and axis in XLSX file | ||
func GetCellValue(file []FileList, sheet string, axis string) string { | ||
axis = strings.ToUpper(axis) | ||
var xlsx xlsxWorksheet | ||
row := getRowIndex(axis) | ||
xAxis := row - 1 | ||
name := `xl/worksheets/` + strings.ToLower(sheet) + `.xml` | ||
xml.Unmarshal([]byte(readXml(file, name)), &xlsx) | ||
rows := len(xlsx.SheetData.Row) | ||
if rows <= xAxis { | ||
return `` | ||
} | ||
for _, v := range xlsx.SheetData.Row[xAxis].C { | ||
if xlsx.SheetData.Row[xAxis].R == row { | ||
if axis == v.R { | ||
switch v.T { | ||
case "s": | ||
shardStrings := xlsxSST{} | ||
xlsxSI := 0 | ||
xlsxSI, _ = strconv.Atoi(v.V) | ||
xml.Unmarshal([]byte(readXml(file, `xl/sharedStrings.xml`)), &shardStrings) | ||
return shardStrings.SI[xlsxSI].T | ||
case "str": | ||
return v.V | ||
default: | ||
return v.V | ||
} | ||
} | ||
} | ||
} | ||
return `` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package excelize | ||
|
||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
// xlsxSST directly maps the sst element from the namespace | ||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main currently | ||
// I have not checked this for completeness - it does as much as I need. | ||
type xlsxSST struct { | ||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"` | ||
Count int `xml:"count,attr"` | ||
UniqueCount int `xml:"uniqueCount,attr"` | ||
SI []xlsxSI `xml:"si"` | ||
} | ||
|
||
// xlsxSI directly maps the si element from the namespace | ||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - | ||
// currently I have not checked this for completeness - it does as | ||
// much as I need. | ||
type xlsxSI struct { | ||
T string `xml:"t"` | ||
R []xlsxR `xml:"r"` | ||
} | ||
|
||
// xlsxR directly maps the r element from the namespace | ||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - | ||
// currently I have not checked this for completeness - it does as | ||
// much as I need. | ||
type xlsxR struct { | ||
T string `xml:"t"` | ||
} |