xmlDrawing.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. package excelize
  2. import "encoding/xml"
  3. // Source relationship and namespace.
  4. const (
  5. SourceRelationship = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  6. SourceRelationshipChart = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
  7. SourceRelationshipComments = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
  8. SourceRelationshipImage = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
  9. SourceRelationshipTable = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
  10. SourceRelationshipDrawingML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
  11. SourceRelationshipDrawingVML = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"
  12. SourceRelationshipHyperLink = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
  13. SourceRelationshipWorkSheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
  14. SourceRelationshipChart201506 = "http://schemas.microsoft.com/office/drawing/2015/06/chart"
  15. SourceRelationshipChart20070802 = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart"
  16. SourceRelationshipChart2014 = "http://schemas.microsoft.com/office/drawing/2014/chart"
  17. SourceRelationshipCompatibility = "http://schemas.openxmlformats.org/markup-compatibility/2006"
  18. NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main"
  19. NameSpaceDrawingMLChart = "http://schemas.openxmlformats.org/drawingml/2006/chart"
  20. NameSpaceDrawingMLSpreadSheet = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
  21. NameSpaceSpreadSheet = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
  22. NameSpaceXML = "http://www.w3.org/XML/1998/namespace"
  23. )
  24. var supportImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png"}
  25. // xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This
  26. // element specifies non-visual canvas properties. This allows for additional
  27. // information that does not affect the appearance of the picture to be stored.
  28. type xlsxCNvPr struct {
  29. ID int `xml:"id,attr"`
  30. Name string `xml:"name,attr"`
  31. Descr string `xml:"descr,attr"`
  32. Title string `xml:"title,attr,omitempty"`
  33. }
  34. // xlsxPicLocks directly maps the picLocks (Picture Locks). This element
  35. // specifies all locking properties for a graphic frame. These properties inform
  36. // the generating application about specific properties that have been
  37. // previously locked and thus should not be changed.
  38. type xlsxPicLocks struct {
  39. NoAdjustHandles bool `xml:"noAdjustHandles,attr,omitempty"`
  40. NoChangeArrowheads bool `xml:"noChangeArrowheads,attr,omitempty"`
  41. NoChangeAspect bool `xml:"noChangeAspect,attr"`
  42. NoChangeShapeType bool `xml:"noChangeShapeType,attr,omitempty"`
  43. NoCrop bool `xml:"noCrop,attr,omitempty"`
  44. NoEditPoints bool `xml:"noEditPoints,attr,omitempty"`
  45. NoGrp bool `xml:"noGrp,attr,omitempty"`
  46. NoMove bool `xml:"noMove,attr,omitempty"`
  47. NoResize bool `xml:"noResize,attr,omitempty"`
  48. NoRot bool `xml:"noRot,attr,omitempty"`
  49. NoSelect bool `xml:"noSelect,attr,omitempty"`
  50. }
  51. // xlsxBlip directly maps the blip element in the namespace
  52. // http://purl.oclc.org/ooxml/officeDoc ument/relationships - This element
  53. // specifies the existence of an image (binary large image or picture) and
  54. // contains a reference to the image data.
  55. type xlsxBlip struct {
  56. Embed string `xml:"r:embed,attr"`
  57. Cstate string `xml:"cstate,attr,omitempty"`
  58. R string `xml:"xmlns:r,attr"`
  59. }
  60. // xlsxStretch directly maps the stretch element. This element specifies that a
  61. // BLIP should be stretched to fill the target rectangle. The other option is a
  62. // tile where a BLIP is tiled to fill the available area.
  63. type xlsxStretch struct {
  64. FillRect string `xml:"a:fillRect"`
  65. }
  66. // xlsxOff directly maps the colOff and rowOff element. This element is used to
  67. // specify the column offset within a cell.
  68. type xlsxOff struct {
  69. X int `xml:"x,attr"`
  70. Y int `xml:"y,attr"`
  71. }
  72. // xlsxExt directly maps the ext element.
  73. type xlsxExt struct {
  74. Cx int `xml:"cx,attr"`
  75. Cy int `xml:"cy,attr"`
  76. }
  77. // xlsxPrstGeom directly maps the prstGeom (Preset geometry). This element
  78. // specifies when a preset geometric shape should be used instead of a custom
  79. // geometric shape. The generating application should be able to render all
  80. // preset geometries enumerated in the ST_ShapeType list.
  81. type xlsxPrstGeom struct {
  82. Prst string `xml:"prst,attr"`
  83. }
  84. // xlsxXfrm directly maps the xfrm (2D Transform for Graphic Frame). This
  85. // element specifies the transform to be applied to the corresponding graphic
  86. // frame. This transformation is applied to the graphic frame just as it would
  87. // be for a shape or group shape.
  88. type xlsxXfrm struct {
  89. Off xlsxOff `xml:"a:off"`
  90. Ext xlsxExt `xml:"a:ext"`
  91. }
  92. // xlsxCNvPicPr directly maps the cNvPicPr (Non-Visual Picture Drawing
  93. // Properties). This element specifies the non-visual properties for the picture
  94. // canvas. These properties are to be used by the generating application to
  95. // determine how certain properties are to be changed for the picture object in
  96. // question.
  97. type xlsxCNvPicPr struct {
  98. PicLocks xlsxPicLocks `xml:"a:picLocks"`
  99. }
  100. // directly maps the nvPicPr (Non-Visual Properties for a Picture). This element
  101. // specifies all non-visual properties for a picture. This element is a
  102. // container for the non-visual identification properties, shape properties and
  103. // application properties that are to be associated with a picture. This allows
  104. // for additional information that does not affect the appearance of the picture
  105. // to be stored.
  106. type xlsxNvPicPr struct {
  107. CNvPr xlsxCNvPr `xml:"xdr:cNvPr"`
  108. CNvPicPr xlsxCNvPicPr `xml:"xdr:cNvPicPr"`
  109. }
  110. // xlsxBlipFill directly maps the blipFill (Picture Fill). This element
  111. // specifies the kind of picture fill that the picture object has. Because a
  112. // picture has a picture fill already by default, it is possible to have two
  113. // fills specified for a picture object.
  114. type xlsxBlipFill struct {
  115. Blip xlsxBlip `xml:"a:blip"`
  116. Stretch xlsxStretch `xml:"a:stretch"`
  117. }
  118. // xlsxSpPr directly maps the spPr (Shape Properties). This element specifies
  119. // the visual shape properties that can be applied to a picture. These are the
  120. // same properties that are allowed to describe the visual properties of a shape
  121. // but are used here to describe the visual appearance of a picture within a
  122. // document.
  123. type xlsxSpPr struct {
  124. Xfrm xlsxXfrm `xml:"a:xfrm"`
  125. PrstGeom xlsxPrstGeom `xml:"a:prstGeom"`
  126. }
  127. // xlsxPic elements encompass the definition of pictures within the DrawingML
  128. // framework. While pictures are in many ways very similar to shapes they have
  129. // specific properties that are unique in order to optimize for picture-
  130. // specific scenarios.
  131. type xlsxPic struct {
  132. NvPicPr xlsxNvPicPr `xml:"xdr:nvPicPr"`
  133. BlipFill xlsxBlipFill `xml:"xdr:blipFill"`
  134. SpPr xlsxSpPr `xml:"xdr:spPr"`
  135. }
  136. // xlsxFrom specifies the starting anchor.
  137. type xlsxFrom struct {
  138. Col int `xml:"xdr:col"`
  139. ColOff int `xml:"xdr:colOff"`
  140. Row int `xml:"xdr:row"`
  141. RowOff int `xml:"xdr:rowOff"`
  142. }
  143. // xlsxTo directly specifies the ending anchor.
  144. type xlsxTo struct {
  145. Col int `xml:"xdr:col"`
  146. ColOff int `xml:"xdr:colOff"`
  147. Row int `xml:"xdr:row"`
  148. RowOff int `xml:"xdr:rowOff"`
  149. }
  150. // xdrClientData directly maps the clientData element. An empty element which
  151. // specifies (via attributes) certain properties related to printing and
  152. // selection of the drawing object. The fLocksWithSheet attribute (either true
  153. // or false) determines whether to disable selection when the sheet is
  154. // protected, and fPrintsWithSheet attribute (either true or false) determines
  155. // whether the object is printed when the sheet is printed.
  156. type xdrClientData struct {
  157. FLocksWithSheet bool `xml:"fLocksWithSheet,attr"`
  158. FPrintsWithSheet bool `xml:"fPrintsWithSheet,attr"`
  159. }
  160. // xdrCellAnchor directly maps the oneCellAnchor (One Cell Anchor Shape Size)
  161. // and twoCellAnchor (Two Cell Anchor Shape Size). This element specifies a two
  162. // cell anchor placeholder for a group, a shape, or a drawing element. It moves
  163. // with cells and its extents are in EMU units.
  164. type xdrCellAnchor struct {
  165. EditAs string `xml:"editAs,attr,omitempty"`
  166. From *xlsxFrom `xml:"xdr:from"`
  167. To *xlsxTo `xml:"xdr:to"`
  168. Ext *xlsxExt `xml:"xdr:ext"`
  169. Sp *xdrSp `xml:"xdr:sp"`
  170. Pic *xlsxPic `xml:"xdr:pic,omitempty"`
  171. GraphicFrame string `xml:",innerxml"`
  172. ClientData *xdrClientData `xml:"xdr:clientData"`
  173. }
  174. // xlsxWsDr directly maps the root element for a part of this content type shall
  175. // wsDr.
  176. type xlsxWsDr struct {
  177. XMLName xml.Name `xml:"xdr:wsDr"`
  178. OneCellAnchor []*xdrCellAnchor `xml:"xdr:oneCellAnchor"`
  179. TwoCellAnchor []*xdrCellAnchor `xml:"xdr:twoCellAnchor"`
  180. Xdr string `xml:"xmlns:xdr,attr"`
  181. A string `xml:"xmlns:a,attr"`
  182. }
  183. // xlsxGraphicFrame (Graphic Frame) directly maps the xdr:graphicFrame element.
  184. // This element specifies the existence of a graphics frame. This frame contains
  185. // a graphic that was generated by an external source and needs a container in
  186. // which to be displayed on the slide surface.
  187. type xlsxGraphicFrame struct {
  188. XMLName xml.Name `xml:"xdr:graphicFrame"`
  189. Macro string `xml:"macro,attr"`
  190. NvGraphicFramePr xlsxNvGraphicFramePr `xml:"xdr:nvGraphicFramePr"`
  191. Xfrm xlsxXfrm `xml:"xdr:xfrm"`
  192. Graphic *xlsxGraphic `xml:"a:graphic"`
  193. }
  194. // xlsxNvGraphicFramePr (Non-Visual Properties for a Graphic Frame) directly
  195. // maps the xdr:nvGraphicFramePr element. This element specifies all non-visual
  196. // properties for a graphic frame. This element is a container for the non-
  197. // visual identification properties, shape properties and application properties
  198. // that are to be associated with a graphic frame. This allows for additional
  199. // information that does not affect the appearance of the graphic frame to be
  200. // stored.
  201. type xlsxNvGraphicFramePr struct {
  202. CNvPr *xlsxCNvPr `xml:"xdr:cNvPr"`
  203. ChicNvGraphicFramePr string `xml:"xdr:cNvGraphicFramePr"`
  204. }
  205. // xlsxGraphic (Graphic Object) directly maps the a:graphic element. This
  206. // element specifies the existence of a single graphic object. Document authors
  207. // should refer to this element when they wish to persist a graphical object of
  208. // some kind. The specification for this graphical object is provided entirely
  209. // by the document author and referenced within the graphicData child element.
  210. type xlsxGraphic struct {
  211. GraphicData *xlsxGraphicData `xml:"a:graphicData"`
  212. }
  213. // xlsxGraphicData (Graphic Object Data) directly maps the a:graphicData
  214. // element. This element specifies the reference to a graphic object within the
  215. // document. This graphic object is provided entirely by the document authors
  216. // who choose to persist this data within the document.
  217. type xlsxGraphicData struct {
  218. URI string `xml:"uri,attr"`
  219. Chart *xlsxChart `xml:"c:chart,omitempty"`
  220. }
  221. // xlsxChart (Chart) directly maps the c:chart element.
  222. type xlsxChart struct {
  223. C string `xml:"xmlns:c,attr"`
  224. RID string `xml:"r:id,attr"`
  225. R string `xml:"xmlns:r,attr"`
  226. }
  227. // xdrSp (Shape) directly maps the xdr:sp element. This element specifies the
  228. // existence of a single shape. A shape can either be a preset or a custom
  229. // geometry, defined using the SpreadsheetDrawingML framework. In addition to a
  230. // geometry each shape can have both visual and non-visual properties attached.
  231. // Text and corresponding styling information can also be attached to a shape.
  232. // This shape is specified along with all other shapes within either the shape
  233. // tree or group shape elements.
  234. type xdrSp struct {
  235. Macro string `xml:"macro,attr"`
  236. Textlink string `xml:"textlink,attr"`
  237. NvSpPr *xdrNvSpPr `xml:"xdr:nvSpPr"`
  238. SpPr *xlsxSpPr `xml:"xdr:spPr"`
  239. Style *xdrStyle `xml:"xdr:style"`
  240. TxBody *xdrTxBody `xml:"xdr:txBody"`
  241. }
  242. // xdrNvSpPr (Non-Visual Properties for a Shape) directly maps the xdr:nvSpPr
  243. // element. This element specifies all non-visual properties for a shape. This
  244. // element is a container for the non-visual identification properties, shape
  245. // properties and application properties that are to be associated with a shape.
  246. // This allows for additional information that does not affect the appearance of
  247. // the shape to be stored.
  248. type xdrNvSpPr struct {
  249. CNvPr *xlsxCNvPr `xml:"xdr:cNvPr"`
  250. CNvSpPr *xdrCNvSpPr `xml:"xdr:cNvSpPr"`
  251. }
  252. // xdrCNvSpPr (Connection Non-Visual Shape Properties) directly maps the
  253. // xdr:cNvSpPr element. This element specifies the set of non-visual properties
  254. // for a connection shape. These properties specify all data about the
  255. // connection shape which do not affect its display within a spreadsheet.
  256. type xdrCNvSpPr struct {
  257. TxBox bool `xml:"txBox,attr"`
  258. }
  259. // xdrStyle (Shape Style) directly maps the xdr:style element. The element
  260. // specifies the style that is applied to a shape and the corresponding
  261. // references for each of the style components such as lines and fills.
  262. type xdrStyle struct {
  263. LnRef *aRef `xml:"a:lnRef"`
  264. FillRef *aRef `xml:"a:fillRef"`
  265. EffectRef *aRef `xml:"a:effectRef"`
  266. FontRef *aFontRef `xml:"a:fontRef"`
  267. }
  268. // aRef directly maps the a:lnRef, a:fillRef and a:effectRef element.
  269. type aRef struct {
  270. Idx int `xml:"idx,attr"`
  271. ScrgbClr *aScrgbClr `xml:"a:scrgbClr"`
  272. SchemeClr *attrValString `xml:"a:schemeClr"`
  273. SrgbClr *attrValString `xml:"a:srgbClr"`
  274. }
  275. // aScrgbClr (RGB Color Model - Percentage Variant) directly maps the a:scrgbClr
  276. // element. This element specifies a color using the red, green, blue RGB color
  277. // model. Each component, red, green, and blue is expressed as a percentage from
  278. // 0% to 100%. A linear gamma of 1.0 is assumed.
  279. type aScrgbClr struct {
  280. R float64 `xml:"r,attr"`
  281. G float64 `xml:"g,attr"`
  282. B float64 `xml:"b,attr"`
  283. }
  284. // aFontRef (Font Reference) directly maps the a:fontRef element. This element
  285. // represents a reference to a themed font. When used it specifies which themed
  286. // font to use along with a choice of color.
  287. type aFontRef struct {
  288. Idx string `xml:"idx,attr"`
  289. SchemeClr *attrValString `xml:"a:schemeClr"`
  290. }
  291. // xdrTxBody (Shape Text Body) directly maps the xdr:txBody element. This
  292. // element specifies the existence of text to be contained within the
  293. // corresponding shape. All visible text and visible text related properties are
  294. // contained within this element. There can be multiple paragraphs and within
  295. // paragraphs multiple runs of text.
  296. type xdrTxBody struct {
  297. BodyPr *aBodyPr `xml:"a:bodyPr"`
  298. P *aP `xml:"a:p"`
  299. }
  300. // formatPicture directly maps the format settings of the picture.
  301. type formatPicture struct {
  302. FPrintsWithSheet bool `json:"print_obj"`
  303. FLocksWithSheet bool `json:"locked"`
  304. NoChangeAspect bool `json:"lock_aspect_ratio"`
  305. OffsetX int `json:"x_offset"`
  306. OffsetY int `json:"y_offset"`
  307. XScale float64 `json:"x_scale"`
  308. YScale float64 `json:"y_scale"`
  309. }
  310. // formatShape directly maps the format settings of the shape.
  311. type formatShape struct {
  312. Type string `json:"type"`
  313. Width int `json:"width"`
  314. Height int `json:"height"`
  315. Format formatPicture `json:"format"`
  316. Text string `json:"text"`
  317. Color formatShapeColor `json:"color"`
  318. }
  319. type formatShapeColor struct {
  320. Line string `json:"line"`
  321. Fill string `json:"fill"`
  322. Effect string `json:"effect"`
  323. }