xmlSharedStrings.go 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2016 - 2023 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 and
  6. // read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
  7. // writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
  8. // Supports complex components by high compatibility, and provided streaming
  9. // API for generating or reading data from a worksheet with huge amounts of
  10. // data. This library needs Go version 1.16 or later.
  11. package excelize
  12. import "encoding/xml"
  13. // xlsxSST directly maps the sst element from the namespace
  14. // http://schemas.openxmlformats.org/spreadsheetml/2006/main. String values may
  15. // be stored directly inside spreadsheet cell elements; however, storing the
  16. // same value inside multiple cell elements can result in very large worksheet
  17. // Parts, possibly resulting in performance degradation. The Shared String Table
  18. // is an indexed list of string values, shared across the workbook, which allows
  19. // implementations to store values only once.
  20. type xlsxSST struct {
  21. XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"`
  22. Count int `xml:"count,attr"`
  23. UniqueCount int `xml:"uniqueCount,attr"`
  24. SI []xlsxSI `xml:"si"`
  25. }
  26. // xlsxSI (String Item) is the representation of an individual string in the
  27. // Shared String table. If the string is just a simple string with formatting
  28. // applied at the cell level, then the String Item (si) should contain a
  29. // single text element used to express the string. However, if the string in
  30. // the cell is more complex - i.e., has formatting applied at the character
  31. // level - then the string item shall consist of multiple rich text runs which
  32. // collectively are used to express the string.
  33. type xlsxSI struct {
  34. T *xlsxT `xml:"t,omitempty"`
  35. R []xlsxR `xml:"r"`
  36. RPh []*xlsxPhoneticRun `xml:"rPh"`
  37. PhoneticPr *xlsxPhoneticPr `xml:"phoneticPr"`
  38. }
  39. // xlsxR represents a run of rich text. A rich text run is a region of text
  40. // that share a common set of properties, such as formatting properties. The
  41. // properties are defined in the rPr element, and the text displayed to the
  42. // user is defined in the Text (t) element.
  43. type xlsxR struct {
  44. XMLName xml.Name `xml:"r"`
  45. RPr *xlsxRPr `xml:"rPr"`
  46. T *xlsxT `xml:"t"`
  47. }
  48. // xlsxT directly maps the t element in the run properties.
  49. type xlsxT struct {
  50. XMLName xml.Name `xml:"t"`
  51. Space xml.Attr `xml:"space,attr,omitempty"`
  52. Val string `xml:",chardata"`
  53. }
  54. // xlsxRPr (Run Properties) specifies a set of run properties which shall be
  55. // applied to the contents of the parent run after all style formatting has been
  56. // applied to the text. These properties are defined as direct formatting, since
  57. // they are directly applied to the run and supersede any formatting from
  58. // styles.
  59. type xlsxRPr struct {
  60. RFont *attrValString `xml:"rFont"`
  61. Charset *attrValInt `xml:"charset"`
  62. Family *attrValInt `xml:"family"`
  63. B *string `xml:"b"`
  64. I *string `xml:"i"`
  65. Strike *string `xml:"strike"`
  66. Outline *string `xml:"outline"`
  67. Shadow *string `xml:"shadow"`
  68. Condense *string `xml:"condense"`
  69. Extend *string `xml:"extend"`
  70. Color *xlsxColor `xml:"color"`
  71. Sz *attrValFloat `xml:"sz"`
  72. U *attrValString `xml:"u"`
  73. VertAlign *attrValString `xml:"vertAlign"`
  74. Scheme *attrValString `xml:"scheme"`
  75. }
  76. // RichTextRun directly maps the settings of the rich text run.
  77. type RichTextRun struct {
  78. Font *Font
  79. Text string
  80. }