vmlDrawing.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "encoding/xml"
  11. // vmlDrawing directly maps the root element in the file
  12. // xl/drawings/vmlDrawing%d.vml.
  13. type vmlDrawing struct {
  14. XMLName xml.Name `xml:"xml"`
  15. XMLNSv string `xml:"xmlns:v,attr"`
  16. XMLNSo string `xml:"xmlns:o,attr"`
  17. XMLNSx string `xml:"xmlns:x,attr"`
  18. XMLNSmv string `xml:"xmlns:mv,attr"`
  19. Shapelayout *xlsxShapelayout `xml:"o:shapelayout"`
  20. Shapetype *xlsxShapetype `xml:"v:shapetype"`
  21. Shape []xlsxShape `xml:"v:shape"`
  22. }
  23. // xlsxShapelayout directly maps the shapelayout element. This element contains
  24. // child elements that store information used in the editing and layout of
  25. // shapes.
  26. type xlsxShapelayout struct {
  27. Ext string `xml:"v:ext,attr"`
  28. IDmap *xlsxIDmap `xml:"o:idmap"`
  29. }
  30. // xlsxIDmap directly maps the idmap element.
  31. type xlsxIDmap struct {
  32. Ext string `xml:"v:ext,attr"`
  33. Data int `xml:"data,attr"`
  34. }
  35. // xlsxShape directly maps the shape element.
  36. type xlsxShape struct {
  37. XMLName xml.Name `xml:"v:shape"`
  38. ID string `xml:"id,attr"`
  39. Type string `xml:"type,attr"`
  40. Style string `xml:"style,attr"`
  41. Fillcolor string `xml:"fillcolor,attr"`
  42. Insetmode string `xml:"urn:schemas-microsoft-com:office:office insetmode,attr,omitempty"`
  43. Strokecolor string `xml:"strokecolor,attr,omitempty"`
  44. Val string `xml:",innerxml"`
  45. }
  46. // xlsxShapetype directly maps the shapetype element.
  47. type xlsxShapetype struct {
  48. ID string `xml:"id,attr"`
  49. Coordsize string `xml:"coordsize,attr"`
  50. Spt int `xml:"o:spt,attr"`
  51. Path string `xml:"path,attr"`
  52. Stroke *xlsxStroke `xml:"v:stroke"`
  53. VPath *vPath `xml:"v:path"`
  54. }
  55. // xlsxStroke directly maps the stroke element.
  56. type xlsxStroke struct {
  57. Joinstyle string `xml:"joinstyle,attr"`
  58. }
  59. // vPath directly maps the v:path element.
  60. type vPath struct {
  61. Gradientshapeok string `xml:"gradientshapeok,attr,omitempty"`
  62. Connecttype string `xml:"o:connecttype,attr"`
  63. }
  64. // vFill directly maps the v:fill element. This element must be defined within a
  65. // Shape element.
  66. type vFill struct {
  67. Angle int `xml:"angle,attr,omitempty"`
  68. Color2 string `xml:"color2,attr"`
  69. Type string `xml:"type,attr,omitempty"`
  70. Fill *oFill `xml:"o:fill"`
  71. }
  72. // oFill directly maps the o:fill element.
  73. type oFill struct {
  74. Ext string `xml:"v:ext,attr"`
  75. Type string `xml:"type,attr,omitempty"`
  76. }
  77. // vShadow directly maps the v:shadow element. This element must be defined
  78. // within a Shape element. In addition, the On attribute must be set to True.
  79. type vShadow struct {
  80. On string `xml:"on,attr"`
  81. Color string `xml:"color,attr,omitempty"`
  82. Obscured string `xml:"obscured,attr"`
  83. }
  84. // vTextbox directly maps the v:textbox element. This element must be defined
  85. // within a Shape element.
  86. type vTextbox struct {
  87. Style string `xml:"style,attr"`
  88. Div *xlsxDiv `xml:"div"`
  89. }
  90. // xlsxDiv directly maps the div element.
  91. type xlsxDiv struct {
  92. Style string `xml:"style,attr"`
  93. }
  94. // xClientData (Attached Object Data) directly maps the x:ClientData element.
  95. // This element specifies data associated with objects attached to a
  96. // spreadsheet. While this element might contain any of the child elements
  97. // below, only certain combinations are meaningful. The ObjectType attribute
  98. // determines the kind of object the element represents and which subset of
  99. // child elements is appropriate. Relevant groups are identified for each child
  100. // element.
  101. type xClientData struct {
  102. ObjectType string `xml:"ObjectType,attr"`
  103. MoveWithCells string `xml:"x:MoveWithCells,omitempty"`
  104. SizeWithCells string `xml:"x:SizeWithCells,omitempty"`
  105. Anchor string `xml:"x:Anchor"`
  106. AutoFill string `xml:"x:AutoFill"`
  107. Row int `xml:"x:Row"`
  108. Column int `xml:"x:Column"`
  109. }
  110. // decodeVmlDrawing defines the structure used to parse the file
  111. // xl/drawings/vmlDrawing%d.vml.
  112. type decodeVmlDrawing struct {
  113. Shape []decodeShape `xml:"urn:schemas-microsoft-com:vml shape"`
  114. }
  115. // decodeShape defines the structure used to parse the particular shape element.
  116. type decodeShape struct {
  117. Val string `xml:",innerxml"`
  118. }
  119. // encodeShape defines the structure used to re-serialization shape element.
  120. type encodeShape struct {
  121. Fill *vFill `xml:"v:fill"`
  122. Shadow *vShadow `xml:"v:shadow"`
  123. Path *vPath `xml:"v:path"`
  124. Textbox *vTextbox `xml:"v:textbox"`
  125. ClientData *xClientData `xml:"x:ClientData"`
  126. }