sharedstrings.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package xlsx
  2. // XLSXSST directly maps the sst element from the namespace
  3. // http://schemas.openxmlformats.org/spreadsheetml/2006/main currently
  4. // I have not checked this for completeness - it does as much as need.
  5. type XLSXSST struct {
  6. Count string `xml:"attr"`
  7. UniqueCount string `xml:"attr"`
  8. SI []XLSXSI
  9. }
  10. // XLSXSI directly maps the si element from the namespace
  11. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  12. // currently I have not checked this for completeness - it does as
  13. // much as I need.
  14. type XLSXSI struct {
  15. T XLSXT
  16. }
  17. // XLSXT directly maps the t element from the namespace
  18. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  19. // currently I have not checked this for completeness - it does as
  20. // much as I need.
  21. type XLSXT struct {
  22. Data string `xml:"chardata"`
  23. }
  24. // MakeSharedStringRefTable() takes an XLSXSST struct and converts
  25. // it's contents to an slice of strings used to refer to string values
  26. // by numeric index - this is the model used within XLSX worksheet (a
  27. // numeric reference is stored to a shared cell value).
  28. func MakeSharedStringRefTable(source *XLSXSST) []string {
  29. reftable := make([]string, len(source.SI))
  30. for i, si := range source.SI {
  31. reftable[i] = si.T.Data
  32. }
  33. return reftable
  34. }
  35. // ResolveSharedString() looks up a string value by numeric index from
  36. // a provided reference table (just a slice of strings in the correct
  37. // order). This function only exists to provide clarity or purpose
  38. // via it's name.
  39. func ResolveSharedString(reftable []string, index int) string {
  40. return reftable[index]
  41. }