sharedstrings.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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:"count,attr"`
  7. UniqueCount string `xml:"uniqueCount,attr"`
  8. SI []xlsxSI `xml:"si"`
  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 string `xml:"t"`
  16. R []xlsxR `xml:"r"`
  17. }
  18. // xlsxR directly maps the r element from the namespace
  19. // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  20. // currently I have not checked this for completeness - it does as
  21. // much as I need.
  22. type xlsxR struct {
  23. T string `xml:"t"`
  24. }
  25. // // xlsxT directly maps the t element from the namespace
  26. // // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
  27. // // currently I have not checked this for completeness - it does as
  28. // // much as I need.
  29. // type xlsxT struct {
  30. // Data string `xml:"chardata"`
  31. // }
  32. // MakeSharedStringRefTable() takes an xlsxSST struct and converts
  33. // it's contents to an slice of strings used to refer to string values
  34. // by numeric index - this is the model used within XLSX worksheet (a
  35. // numeric reference is stored to a shared cell value).
  36. func MakeSharedStringRefTable(source *xlsxSST) []string {
  37. reftable := make([]string, len(source.SI))
  38. for i, si := range source.SI {
  39. if len(si.R) > 0 {
  40. for j := 0; j < len(si.R); j++ {
  41. reftable[i] = reftable[i] + si.R[j].T
  42. }
  43. } else {
  44. reftable[i] = si.T
  45. }
  46. }
  47. return reftable
  48. }
  49. // ResolveSharedString() looks up a string value by numeric index from
  50. // a provided reference table (just a slice of strings in the correct
  51. // order). This function only exists to provide clarity or purpose
  52. // via it's name.
  53. func ResolveSharedString(reftable []string, index int) string {
  54. return reftable[index]
  55. }