picture.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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 (
  11. "bytes"
  12. "encoding/json"
  13. "encoding/xml"
  14. "errors"
  15. "fmt"
  16. "image"
  17. "io"
  18. "io/ioutil"
  19. "os"
  20. "path"
  21. "path/filepath"
  22. "strconv"
  23. "strings"
  24. )
  25. // parseFormatPictureSet provides a function to parse the format settings of
  26. // the picture with default value.
  27. func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
  28. format := formatPicture{
  29. FPrintsWithSheet: true,
  30. FLocksWithSheet: false,
  31. NoChangeAspect: false,
  32. OffsetX: 0,
  33. OffsetY: 0,
  34. XScale: 1.0,
  35. YScale: 1.0,
  36. }
  37. err := json.Unmarshal(parseFormatSet(formatSet), &format)
  38. return &format, err
  39. }
  40. // AddPicture provides the method to add picture in a sheet by given picture
  41. // format set (such as offset, scale, aspect ratio setting and print settings)
  42. // and file path. For example:
  43. //
  44. // package main
  45. //
  46. // import (
  47. // "fmt"
  48. // _ "image/gif"
  49. // _ "image/jpeg"
  50. // _ "image/png"
  51. //
  52. // "github.com/360EntSecGroup-Skylar/excelize"
  53. // )
  54. //
  55. // func main() {
  56. // f := excelize.NewFile()
  57. // // Insert a picture.
  58. // err := f.AddPicture("Sheet1", "A2", "./image1.jpg", "")
  59. // if err != nil {
  60. // fmt.Println(err)
  61. // }
  62. // // Insert a picture scaling in the cell with location hyperlink.
  63. // err = f.AddPicture("Sheet1", "D2", "./image1.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`)
  64. // if err != nil {
  65. // fmt.Println(err)
  66. // }
  67. // // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
  68. // err = f.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`)
  69. // if err != nil {
  70. // fmt.Println(err)
  71. // }
  72. // err = f.SaveAs("./Book1.xlsx")
  73. // if err != nil {
  74. // fmt.Println(err)
  75. // }
  76. // }
  77. //
  78. // LinkType defines two types of hyperlink "External" for web site or
  79. // "Location" for moving to one of cell in this workbook. When the
  80. // "hyperlink_type" is "Location", coordinates need to start with "#".
  81. //
  82. // Positioning defines two types of the position of a picture in an Excel
  83. // spreadsheet, "oneCell" (Move but don't size with cells) or "absolute"
  84. // (Don't move or size with cells). If you don't set this parameter, default
  85. // positioning is move and size with cells.
  86. func (f *File) AddPicture(sheet, cell, picture, format string) error {
  87. var err error
  88. // Check picture exists first.
  89. if _, err = os.Stat(picture); os.IsNotExist(err) {
  90. return err
  91. }
  92. ext, ok := supportImageTypes[path.Ext(picture)]
  93. if !ok {
  94. return errors.New("unsupported image extension")
  95. }
  96. file, _ := ioutil.ReadFile(picture)
  97. _, name := filepath.Split(picture)
  98. return f.AddPictureFromBytes(sheet, cell, format, name, ext, file)
  99. }
  100. // AddPictureFromBytes provides the method to add picture in a sheet by given
  101. // picture format set (such as offset, scale, aspect ratio setting and print
  102. // settings), file base name, extension name and file bytes. For example:
  103. //
  104. // package main
  105. //
  106. // import (
  107. // "fmt"
  108. // _ "image/jpeg"
  109. // "io/ioutil"
  110. //
  111. // "github.com/360EntSecGroup-Skylar/excelize"
  112. // )
  113. //
  114. // func main() {
  115. // f := excelize.NewFile()
  116. //
  117. // file, err := ioutil.ReadFile("./image1.jpg")
  118. // if err != nil {
  119. // fmt.Println(err)
  120. // }
  121. // err = f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file)
  122. // if err != nil {
  123. // fmt.Println(err)
  124. // }
  125. // err = f.SaveAs("./Book1.xlsx")
  126. // if err != nil {
  127. // fmt.Println(err)
  128. // }
  129. // }
  130. //
  131. func (f *File) AddPictureFromBytes(sheet, cell, format, name, extension string, file []byte) error {
  132. var drawingHyperlinkRID int
  133. var hyperlinkType string
  134. ext, ok := supportImageTypes[extension]
  135. if !ok {
  136. return errors.New("unsupported image extension")
  137. }
  138. formatSet, err := parseFormatPictureSet(format)
  139. if err != nil {
  140. return err
  141. }
  142. img, _, err := image.DecodeConfig(bytes.NewReader(file))
  143. if err != nil {
  144. return err
  145. }
  146. // Read sheet data.
  147. xlsx, err := f.workSheetReader(sheet)
  148. if err != nil {
  149. return err
  150. }
  151. // Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
  152. drawingID := f.countDrawings() + 1
  153. drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
  154. drawingID, drawingXML = f.prepareDrawing(xlsx, drawingID, sheet, drawingXML)
  155. drawingRels := "xl/drawings/_rels/drawing" + strconv.Itoa(drawingID) + ".xml.rels"
  156. mediaStr := ".." + strings.TrimPrefix(f.addMedia(file, ext), "xl")
  157. drawingRID := f.addRels(drawingRels, SourceRelationshipImage, mediaStr, hyperlinkType)
  158. // Add picture with hyperlink.
  159. if formatSet.Hyperlink != "" && formatSet.HyperlinkType != "" {
  160. if formatSet.HyperlinkType == "External" {
  161. hyperlinkType = formatSet.HyperlinkType
  162. }
  163. drawingHyperlinkRID = f.addRels(drawingRels, SourceRelationshipHyperLink, formatSet.Hyperlink, hyperlinkType)
  164. }
  165. err = f.addDrawingPicture(sheet, drawingXML, cell, name, img.Width, img.Height, drawingRID, drawingHyperlinkRID, formatSet)
  166. if err != nil {
  167. return err
  168. }
  169. f.addContentTypePart(drawingID, "drawings")
  170. return err
  171. }
  172. // deleteSheetRelationships provides a function to delete relationships in
  173. // xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and
  174. // relationship index.
  175. func (f *File) deleteSheetRelationships(sheet, rID string) {
  176. name, ok := f.sheetMap[trimSheetName(sheet)]
  177. if !ok {
  178. name = strings.ToLower(sheet) + ".xml"
  179. }
  180. var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
  181. sheetRels := f.relsReader(rels)
  182. if sheetRels == nil {
  183. sheetRels = &xlsxRelationships{}
  184. }
  185. for k, v := range sheetRels.Relationships {
  186. if v.ID == rID {
  187. sheetRels.Relationships = append(sheetRels.Relationships[:k], sheetRels.Relationships[k+1:]...)
  188. }
  189. }
  190. f.Relationships[rels] = sheetRels
  191. }
  192. // addSheetLegacyDrawing provides a function to add legacy drawing element to
  193. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
  194. func (f *File) addSheetLegacyDrawing(sheet string, rID int) {
  195. xlsx, _ := f.workSheetReader(sheet)
  196. xlsx.LegacyDrawing = &xlsxLegacyDrawing{
  197. RID: "rId" + strconv.Itoa(rID),
  198. }
  199. }
  200. // addSheetDrawing provides a function to add drawing element to
  201. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
  202. func (f *File) addSheetDrawing(sheet string, rID int) {
  203. xlsx, _ := f.workSheetReader(sheet)
  204. xlsx.Drawing = &xlsxDrawing{
  205. RID: "rId" + strconv.Itoa(rID),
  206. }
  207. }
  208. // addSheetPicture provides a function to add picture element to
  209. // xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
  210. func (f *File) addSheetPicture(sheet string, rID int) {
  211. xlsx, _ := f.workSheetReader(sheet)
  212. xlsx.Picture = &xlsxPicture{
  213. RID: "rId" + strconv.Itoa(rID),
  214. }
  215. }
  216. // countDrawings provides a function to get drawing files count storage in the
  217. // folder xl/drawings.
  218. func (f *File) countDrawings() int {
  219. c1, c2 := 0, 0
  220. for k := range f.XLSX {
  221. if strings.Contains(k, "xl/drawings/drawing") {
  222. c1++
  223. }
  224. }
  225. for rel := range f.Drawings {
  226. if strings.Contains(rel, "xl/drawings/drawing") {
  227. c2++
  228. }
  229. }
  230. if c1 < c2 {
  231. return c2
  232. }
  233. return c1
  234. }
  235. // addDrawingPicture provides a function to add picture by given sheet,
  236. // drawingXML, cell, file name, width, height relationship index and format
  237. // sets.
  238. func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, height, rID, hyperlinkRID int, formatSet *formatPicture) error {
  239. col, row, err := CellNameToCoordinates(cell)
  240. if err != nil {
  241. return err
  242. }
  243. width = int(float64(width) * formatSet.XScale)
  244. height = int(float64(height) * formatSet.YScale)
  245. col--
  246. row--
  247. colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 :=
  248. f.positionObjectPixels(sheet, col, row, formatSet.OffsetX, formatSet.OffsetY, width, height)
  249. content, cNvPrID := f.drawingParser(drawingXML)
  250. twoCellAnchor := xdrCellAnchor{}
  251. twoCellAnchor.EditAs = formatSet.Positioning
  252. from := xlsxFrom{}
  253. from.Col = colStart
  254. from.ColOff = formatSet.OffsetX * EMU
  255. from.Row = rowStart
  256. from.RowOff = formatSet.OffsetY * EMU
  257. to := xlsxTo{}
  258. to.Col = colEnd
  259. to.ColOff = x2 * EMU
  260. to.Row = rowEnd
  261. to.RowOff = y2 * EMU
  262. twoCellAnchor.From = &from
  263. twoCellAnchor.To = &to
  264. pic := xlsxPic{}
  265. pic.NvPicPr.CNvPicPr.PicLocks.NoChangeAspect = formatSet.NoChangeAspect
  266. pic.NvPicPr.CNvPr.ID = cNvPrID
  267. pic.NvPicPr.CNvPr.Descr = file
  268. pic.NvPicPr.CNvPr.Name = "Picture " + strconv.Itoa(cNvPrID)
  269. if hyperlinkRID != 0 {
  270. pic.NvPicPr.CNvPr.HlinkClick = &xlsxHlinkClick{
  271. R: SourceRelationship,
  272. RID: "rId" + strconv.Itoa(hyperlinkRID),
  273. }
  274. }
  275. pic.BlipFill.Blip.R = SourceRelationship
  276. pic.BlipFill.Blip.Embed = "rId" + strconv.Itoa(rID)
  277. pic.SpPr.PrstGeom.Prst = "rect"
  278. twoCellAnchor.Pic = &pic
  279. twoCellAnchor.ClientData = &xdrClientData{
  280. FLocksWithSheet: formatSet.FLocksWithSheet,
  281. FPrintsWithSheet: formatSet.FPrintsWithSheet,
  282. }
  283. content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor)
  284. f.Drawings[drawingXML] = content
  285. return err
  286. }
  287. // countMedia provides a function to get media files count storage in the
  288. // folder xl/media/image.
  289. func (f *File) countMedia() int {
  290. count := 0
  291. for k := range f.XLSX {
  292. if strings.Contains(k, "xl/media/image") {
  293. count++
  294. }
  295. }
  296. return count
  297. }
  298. // addMedia provides a function to add a picture into folder xl/media/image by
  299. // given file and extension name. Duplicate images are only actually stored once
  300. // and drawings that use it will reference the same image.
  301. func (f *File) addMedia(file []byte, ext string) string {
  302. count := f.countMedia()
  303. for name, existing := range f.XLSX {
  304. if !strings.HasPrefix(name, "xl/media/image") {
  305. continue
  306. }
  307. if bytes.Equal(file, existing) {
  308. return name
  309. }
  310. }
  311. media := "xl/media/image" + strconv.Itoa(count+1) + ext
  312. f.XLSX[media] = file
  313. return media
  314. }
  315. // setContentTypePartImageExtensions provides a function to set the content
  316. // type for relationship parts and the Main Document part.
  317. func (f *File) setContentTypePartImageExtensions() {
  318. var imageTypes = map[string]bool{"jpeg": false, "png": false, "gif": false, "tiff": false}
  319. content := f.contentTypesReader()
  320. for _, v := range content.Defaults {
  321. _, ok := imageTypes[v.Extension]
  322. if ok {
  323. imageTypes[v.Extension] = true
  324. }
  325. }
  326. for k, v := range imageTypes {
  327. if !v {
  328. content.Defaults = append(content.Defaults, xlsxDefault{
  329. Extension: k,
  330. ContentType: "image/" + k,
  331. })
  332. }
  333. }
  334. }
  335. // setContentTypePartVMLExtensions provides a function to set the content type
  336. // for relationship parts and the Main Document part.
  337. func (f *File) setContentTypePartVMLExtensions() {
  338. vml := false
  339. content := f.contentTypesReader()
  340. for _, v := range content.Defaults {
  341. if v.Extension == "vml" {
  342. vml = true
  343. }
  344. }
  345. if !vml {
  346. content.Defaults = append(content.Defaults, xlsxDefault{
  347. Extension: "vml",
  348. ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing",
  349. })
  350. }
  351. }
  352. // addContentTypePart provides a function to add content type part
  353. // relationships in the file [Content_Types].xml by given index.
  354. func (f *File) addContentTypePart(index int, contentType string) {
  355. setContentType := map[string]func(){
  356. "comments": f.setContentTypePartVMLExtensions,
  357. "drawings": f.setContentTypePartImageExtensions,
  358. }
  359. partNames := map[string]string{
  360. "chart": "/xl/charts/chart" + strconv.Itoa(index) + ".xml",
  361. "comments": "/xl/comments" + strconv.Itoa(index) + ".xml",
  362. "drawings": "/xl/drawings/drawing" + strconv.Itoa(index) + ".xml",
  363. "table": "/xl/tables/table" + strconv.Itoa(index) + ".xml",
  364. "pivotTable": "/xl/pivotTables/pivotTable" + strconv.Itoa(index) + ".xml",
  365. "pivotCache": "/xl/pivotCache/pivotCacheDefinition" + strconv.Itoa(index) + ".xml",
  366. }
  367. contentTypes := map[string]string{
  368. "chart": "application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
  369. "comments": "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
  370. "drawings": "application/vnd.openxmlformats-officedocument.drawing+xml",
  371. "table": "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
  372. "pivotTable": "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
  373. "pivotCache": "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
  374. }
  375. s, ok := setContentType[contentType]
  376. if ok {
  377. s()
  378. }
  379. content := f.contentTypesReader()
  380. for _, v := range content.Overrides {
  381. if v.PartName == partNames[contentType] {
  382. return
  383. }
  384. }
  385. content.Overrides = append(content.Overrides, xlsxOverride{
  386. PartName: partNames[contentType],
  387. ContentType: contentTypes[contentType],
  388. })
  389. }
  390. // getSheetRelationshipsTargetByID provides a function to get Target attribute
  391. // value in xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and
  392. // relationship index.
  393. func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
  394. name, ok := f.sheetMap[trimSheetName(sheet)]
  395. if !ok {
  396. name = strings.ToLower(sheet) + ".xml"
  397. }
  398. var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
  399. sheetRels := f.relsReader(rels)
  400. if sheetRels == nil {
  401. sheetRels = &xlsxRelationships{}
  402. }
  403. for _, v := range sheetRels.Relationships {
  404. if v.ID == rID {
  405. return v.Target
  406. }
  407. }
  408. return ""
  409. }
  410. // GetPicture provides a function to get picture base name and raw content
  411. // embed in XLSX by given worksheet and cell name. This function returns the
  412. // file name in XLSX and file contents as []byte data types. For example:
  413. //
  414. // f, err := excelize.OpenFile("./Book1.xlsx")
  415. // if err != nil {
  416. // fmt.Println(err)
  417. // return
  418. // }
  419. // file, raw, err := f.GetPicture("Sheet1", "A2")
  420. // if err != nil {
  421. // fmt.Println(err)
  422. // return
  423. // }
  424. // err = ioutil.WriteFile(file, raw, 0644)
  425. // if err != nil {
  426. // fmt.Println(err)
  427. // }
  428. //
  429. func (f *File) GetPicture(sheet, cell string) (string, []byte, error) {
  430. col, row, err := CellNameToCoordinates(cell)
  431. if err != nil {
  432. return "", nil, err
  433. }
  434. col--
  435. row--
  436. xlsx, err := f.workSheetReader(sheet)
  437. if err != nil {
  438. return "", nil, err
  439. }
  440. if xlsx.Drawing == nil {
  441. return "", nil, err
  442. }
  443. target := f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID)
  444. drawingXML := strings.Replace(target, "..", "xl", -1)
  445. _, ok := f.XLSX[drawingXML]
  446. if !ok {
  447. return "", nil, err
  448. }
  449. drawingRelationships := strings.Replace(
  450. strings.Replace(target, "../drawings", "xl/drawings/_rels", -1), ".xml", ".xml.rels", -1)
  451. return f.getPicture(row, col, drawingXML, drawingRelationships)
  452. }
  453. // getPicture provides a function to get picture base name and raw content
  454. // embed in XLSX by given coordinates and drawing relationships.
  455. func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string) (ret string, buf []byte, err error) {
  456. var (
  457. wsDr *xlsxWsDr
  458. ok bool
  459. deWsDr *decodeWsDr
  460. drawRel *xlsxRelationship
  461. deTwoCellAnchor *decodeTwoCellAnchor
  462. )
  463. wsDr, _ = f.drawingParser(drawingXML)
  464. if ret, buf = f.getPictureFromWsDr(row, col, drawingRelationships, wsDr); len(buf) > 0 {
  465. return
  466. }
  467. deWsDr = new(decodeWsDr)
  468. if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(drawingXML)))).
  469. Decode(deWsDr); err != nil && err != io.EOF {
  470. err = fmt.Errorf("xml decode error: %s", err)
  471. return
  472. }
  473. err = nil
  474. for _, anchor := range deWsDr.TwoCellAnchor {
  475. deTwoCellAnchor = new(decodeTwoCellAnchor)
  476. if err = f.xmlNewDecoder(bytes.NewReader([]byte("<decodeTwoCellAnchor>" + anchor.Content + "</decodeTwoCellAnchor>"))).
  477. Decode(deTwoCellAnchor); err != nil && err != io.EOF {
  478. err = fmt.Errorf("xml decode error: %s", err)
  479. return
  480. }
  481. if err = nil; deTwoCellAnchor.From != nil && deTwoCellAnchor.Pic != nil {
  482. if deTwoCellAnchor.From.Col == col && deTwoCellAnchor.From.Row == row {
  483. drawRel = f.getDrawingRelationships(drawingRelationships, deTwoCellAnchor.Pic.BlipFill.Blip.Embed)
  484. if _, ok = supportImageTypes[filepath.Ext(drawRel.Target)]; ok {
  485. ret, buf = filepath.Base(drawRel.Target), f.XLSX[strings.Replace(drawRel.Target, "..", "xl", -1)]
  486. return
  487. }
  488. }
  489. }
  490. }
  491. return
  492. }
  493. // getPictureFromWsDr provides a function to get picture base name and raw
  494. // content in worksheet drawing by given coordinates and drawing
  495. // relationships.
  496. func (f *File) getPictureFromWsDr(row, col int, drawingRelationships string, wsDr *xlsxWsDr) (ret string, buf []byte) {
  497. var (
  498. ok bool
  499. anchor *xdrCellAnchor
  500. drawRel *xlsxRelationship
  501. )
  502. for _, anchor = range wsDr.TwoCellAnchor {
  503. if anchor.From != nil && anchor.Pic != nil {
  504. if anchor.From.Col == col && anchor.From.Row == row {
  505. drawRel = f.getDrawingRelationships(drawingRelationships,
  506. anchor.Pic.BlipFill.Blip.Embed)
  507. if _, ok = supportImageTypes[filepath.Ext(drawRel.Target)]; ok {
  508. ret, buf = filepath.Base(drawRel.Target), f.XLSX[strings.Replace(drawRel.Target, "..", "xl", -1)]
  509. return
  510. }
  511. }
  512. }
  513. }
  514. return
  515. }
  516. // getDrawingRelationships provides a function to get drawing relationships
  517. // from xl/drawings/_rels/drawing%s.xml.rels by given file name and
  518. // relationship ID.
  519. func (f *File) getDrawingRelationships(rels, rID string) *xlsxRelationship {
  520. if drawingRels := f.relsReader(rels); drawingRels != nil {
  521. for _, v := range drawingRels.Relationships {
  522. if v.ID == rID {
  523. return &v
  524. }
  525. }
  526. }
  527. return nil
  528. }
  529. // drawingsWriter provides a function to save xl/drawings/drawing%d.xml after
  530. // serialize structure.
  531. func (f *File) drawingsWriter() {
  532. for path, d := range f.Drawings {
  533. if d != nil {
  534. v, _ := xml.Marshal(d)
  535. f.saveFileList(path, v)
  536. }
  537. }
  538. }