xmlSharedStrings.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.10 or later.
  9. package excelize
  10. import (
  11. "encoding/xml"
  12. "strings"
  13. )
  14. // xlsxSST directly maps the sst element from the namespace
  15. // http://schemas.openxmlformats.org/spreadsheetml/2006/main. String values may
  16. // be stored directly inside spreadsheet cell elements; however, storing the
  17. // same value inside multiple cell elements can result in very large worksheet
  18. // Parts, possibly resulting in performance degradation. The Shared String Table
  19. // is an indexed list of string values, shared across the workbook, which allows
  20. // implementations to store values only once.
  21. type xlsxSST struct {
  22. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"`
  23. Count int `xml:"count,attr"`
  24. UniqueCount int `xml:"uniqueCount,attr"`
  25. SI []xlsxSI `xml:"si"`
  26. }
  27. // xlsxSI directly maps the si element from the namespace
  28. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  29. // not checked this for completeness - it does as much as I need.
  30. type xlsxSI struct {
  31. T string `xml:"t"`
  32. R []xlsxR `xml:"r"`
  33. }
  34. func (x xlsxSI) String() string {
  35. if len(x.R) > 0 {
  36. var rows strings.Builder
  37. for _, s := range x.R {
  38. rows.WriteString(s.T)
  39. }
  40. return rows.String()
  41. }
  42. return x.T
  43. }
  44. // xlsxR directly maps the r element from the namespace
  45. // http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
  46. // not checked this for completeness - it does as much as I need.
  47. type xlsxR struct {
  48. RPr *xlsxRPr `xml:"rPr"`
  49. T string `xml:"t"`
  50. }
  51. // xlsxRPr (Run Properties) specifies a set of run properties which shall be
  52. // applied to the contents of the parent run after all style formatting has been
  53. // applied to the text. These properties are defined as direct formatting, since
  54. // they are directly applied to the run and supersede any formatting from
  55. // styles.
  56. type xlsxRPr struct {
  57. B string `xml:"b,omitempty"`
  58. Sz *attrValFloat `xml:"sz"`
  59. Color *xlsxColor `xml:"color"`
  60. RFont *attrValString `xml:"rFont"`
  61. Family *attrValInt `xml:"family"`
  62. }