xmlDrawing.go 17 KB

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