xmlDrawing.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package excelize
  2. // Source relationship and namespace.
  3. const (
  4. SourceRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  5. SourceRelationshipImage = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
  6. SourceRelationshipDrawingML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
  7. SourceRelationshipHyperLink = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
  8. SourceRelationshipWorkSheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
  9. NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main"
  10. NameSpaceSpreadSheetDrawing = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
  11. NameSpaceXML = "http://www.w3.org/XML/1998/namespace"
  12. )
  13. var supportImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png"}
  14. // xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This
  15. // element specifies non-visual canvas properties. This allows for additional
  16. // information that does not affect the appearance of the picture to be stored.
  17. type xlsxCNvPr struct {
  18. ID int `xml:"id,attr"`
  19. Name string `xml:"name,attr"`
  20. Descr string `xml:"descr,attr"`
  21. Title string `xml:"title,attr,omitempty"`
  22. }
  23. // xlsxPicLocks directly maps the picLocks (Picture Locks). This element
  24. // specifies all locking properties for a graphic frame. These properties inform
  25. // the generating application about specific properties that have been
  26. // previously locked and thus should not be changed.
  27. type xlsxPicLocks struct {
  28. NoAdjustHandles bool `xml:"noAdjustHandles,attr,omitempty"`
  29. NoChangeArrowheads bool `xml:"noChangeArrowheads,attr,omitempty"`
  30. NoChangeAspect bool `xml:"noChangeAspect,attr"`
  31. NoChangeShapeType bool `xml:"noChangeShapeType,attr,omitempty"`
  32. NoCrop bool `xml:"noCrop,attr,omitempty"`
  33. NoEditPoints bool `xml:"noEditPoints,attr,omitempty"`
  34. NoGrp bool `xml:"noGrp,attr,omitempty"`
  35. NoMove bool `xml:"noMove,attr,omitempty"`
  36. NoResize bool `xml:"noResize,attr,omitempty"`
  37. NoRot bool `xml:"noRot,attr,omitempty"`
  38. NoSelect bool `xml:"noSelect,attr,omitempty"`
  39. }
  40. // xlsxBlip directly maps the blip element in the namespace
  41. // http://purl.oclc.org/ooxml/officeDoc ument/relationships - This element
  42. // specifies the existence of an image (binary large image or picture) and
  43. // contains a reference to the image data.
  44. type xlsxBlip struct {
  45. Embed string `xml:"r:embed,attr"`
  46. Cstate string `xml:"cstate,attr,omitempty"`
  47. R string `xml:"xmlns:r,attr"`
  48. }
  49. // xlsxStretch directly maps the stretch element. This element specifies that a
  50. // BLIP should be stretched to fill the target rectangle. The other option is a
  51. // tile where a BLIP is tiled to fill the available area.
  52. type xlsxStretch struct {
  53. FillRect string `xml:"a:fillRect"`
  54. }
  55. // xlsxOff directly maps the colOff and rowOff element. This element is used to
  56. // specify the column offset within a cell.
  57. type xlsxOff struct {
  58. X int `xml:"x,attr"`
  59. Y int `xml:"y,attr"`
  60. }
  61. // xlsxExt directly maps the ext element.
  62. type xlsxExt struct {
  63. Cx int `xml:"cx,attr"`
  64. Cy int `xml:"cy,attr"`
  65. }
  66. // xlsxPrstGeom directly maps the prstGeom (Preset geometry). This element
  67. // specifies when a preset geometric shape should be used instead of a custom
  68. // geometric shape. The generating application should be able to render all
  69. // preset geometries enumerated in the ST_ShapeType list.
  70. type xlsxPrstGeom struct {
  71. Prst string `xml:"prst,attr"`
  72. }
  73. // xlsxXfrm directly maps the xfrm (2D Transform for Graphic Frame). This
  74. // element specifies the transform to be applied to the corresponding graphic
  75. // frame. This transformation is applied to the graphic frame just as it would
  76. // be for a shape or group shape.
  77. type xlsxXfrm struct {
  78. Off xlsxOff `xml:"a:off"`
  79. Ext xlsxExt `xml:"a:ext"`
  80. }
  81. // xlsxCNvPicPr directly maps the cNvPicPr (Non-Visual Picture Drawing
  82. // Properties). This element specifies the non-visual properties for the picture
  83. // canvas. These properties are to be used by the generating application to
  84. // determine how certain properties are to be changed for the picture object in
  85. // question.
  86. type xlsxCNvPicPr struct {
  87. PicLocks xlsxPicLocks `xml:"a:picLocks"`
  88. }
  89. // directly maps the nvPicPr (Non-Visual Properties for a Picture). This element
  90. // specifies all non-visual properties for a picture. This element is a
  91. // container for the non-visual identification properties, shape properties and
  92. // application properties that are to be associated with a picture. This allows
  93. // for additional information that does not affect the appearance of the picture
  94. // to be stored.
  95. type xlsxNvPicPr struct {
  96. CNvPr xlsxCNvPr `xml:"xdr:cNvPr"`
  97. CNvPicPr xlsxCNvPicPr `xml:"xdr:cNvPicPr"`
  98. }
  99. // xlsxBlipFill directly maps the blipFill (Picture Fill). This element
  100. // specifies the kind of picture fill that the picture object has. Because a
  101. // picture has a picture fill already by default, it is possible to have two
  102. // fills specified for a picture object.
  103. type xlsxBlipFill struct {
  104. Blip xlsxBlip `xml:"a:blip"`
  105. Stretch xlsxStretch `xml:"a:stretch"`
  106. }
  107. // xlsxSpPr directly maps the spPr (Shape Properties). This element specifies
  108. // the visual shape properties that can be applied to a picture. These are the
  109. // same properties that are allowed to describe the visual properties of a shape
  110. // but are used here to describe the visual appearance of a picture within a
  111. // document.
  112. type xlsxSpPr struct {
  113. Xfrm xlsxXfrm `xml:"a:xfrm"`
  114. PrstGeom xlsxPrstGeom `xml:"a:prstGeom"`
  115. }
  116. // xlsxPic elements encompass the definition of pictures within the DrawingML
  117. // framework. While pictures are in many ways very similar to shapes they have
  118. // specific properties that are unique in order to optimize for picture-
  119. // specific scenarios.
  120. type xlsxPic struct {
  121. NvPicPr xlsxNvPicPr `xml:"xdr:nvPicPr"`
  122. BlipFill xlsxBlipFill `xml:"xdr:blipFill"`
  123. SpPr xlsxSpPr `xml:"xdr:spPr"`
  124. }
  125. // xlsxFrom specifies the starting anchor.
  126. type xlsxFrom struct {
  127. Col int `xml:"xdr:col"`
  128. ColOff int `xml:"xdr:colOff"`
  129. Row int `xml:"xdr:row"`
  130. RowOff int `xml:"xdr:rowOff"`
  131. }
  132. // xlsxTo directly specifies the ending anchor.
  133. type xlsxTo struct {
  134. Col int `xml:"xdr:col"`
  135. ColOff int `xml:"xdr:colOff"`
  136. Row int `xml:"xdr:row"`
  137. RowOff int `xml:"xdr:rowOff"`
  138. }
  139. // xlsxClientData directly maps the clientData element. An empty element which
  140. // specifies (via attributes) certain properties related to printing and
  141. // selection of the drawing object. The fLocksWithSheet attribute (either true
  142. // or false) determines whether to disable selection when the sheet is
  143. // protected, and fPrintsWithSheet attribute (either true or false) determines
  144. // whether the object is printed when the sheet is printed.
  145. type xlsxClientData struct {
  146. FLocksWithSheet bool `xml:"fLocksWithSheet,attr"`
  147. FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"`
  148. }
  149. // xlsxCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size)
  150. // and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two
  151. // cell anchor placeholder for a group, a shape, or a drawing element. It moves
  152. // with cells and its extents are in EMU units.
  153. type xlsxCellAnchor struct {
  154. EditAs string `xml:"editAs,attr,omitempty"`
  155. From *xlsxFrom `xml:"xdr:from"`
  156. To *xlsxTo `xml:"xdr:to"`
  157. Pic *xlsxPic `xml:"xdr:pic,omitempty"`
  158. GraphicFrame string `xml:",innerxml"`
  159. ClientData *xlsxClientData `xml:"xdr:clientData"`
  160. }
  161. // xlsxWsDr directly maps the root element for a part of this content type shall
  162. // wsDr.
  163. type xlsxWsDr struct {
  164. OneCellAnchor []*xlsxCellAnchor `xml:"xdr:oneCellAnchor"`
  165. TwoCellAnchor []*xlsxCellAnchor `xml:"xdr:twoCellAnchor"`
  166. Xdr string `xml:"xmlns:xdr,attr"`
  167. A string `xml:"xmlns:a,attr"`
  168. }
  169. // encodeWsDr directly maps the element xdr:wsDr.
  170. type encodeWsDr struct {
  171. WsDr xlsxWsDr `xml:"xdr:wsDr"`
  172. }
  173. // formatPicture directly maps the format settings of the picture.
  174. type formatPicture struct {
  175. FPrintsWithSheet bool `json:"print_obj"`
  176. FLocksWithSheet bool `json:"locked"`
  177. NoChangeAspect bool `json:"lock_aspect_ratio"`
  178. OffsetX int `json:"x_offset"`
  179. OffsetY int `json:"y_offset"`
  180. XScale float64 `json:"x_scale"`
  181. YScale float64 `json:"y_scale"`
  182. }