@@ -122,31 +122,34 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
122
122
row , _ := strconv .Atoi (strings .Map (intOnlyMapF , cell ))
123
123
xAxis := row - 1
124
124
yAxis := TitleToNumber (col )
125
- vml := vmlDrawing {
126
- XMLNSv : "urn:schemas-microsoft-com:vml" ,
127
- XMLNSo : "urn:schemas-microsoft-com:office:office" ,
128
- XMLNSx : "urn:schemas-microsoft-com:office:excel" ,
129
- XMLNSmv : "http://macVmlSchemaUri" ,
130
- Shapelayout : & xlsxShapelayout {
131
- Ext : "edit" ,
132
- IDmap : & xlsxIDmap {
133
- Ext : "edit" ,
134
- Data : commentID ,
135
- },
136
- },
137
- Shapetype : & xlsxShapetype {
138
- ID : "_x0000_t202" ,
139
- Coordsize : "21600,21600" ,
140
- Spt : 202 ,
141
- Path : "m0,0l0,21600,21600,21600,21600,0xe" ,
142
- Stroke : & xlsxStroke {
143
- Joinstyle : "miter" ,
125
+ vml := f .VMLDrawing [drawingVML ]
126
+ if vml == nil {
127
+ vml = & vmlDrawing {
128
+ XMLNSv : "urn:schemas-microsoft-com:vml" ,
129
+ XMLNSo : "urn:schemas-microsoft-com:office:office" ,
130
+ XMLNSx : "urn:schemas-microsoft-com:office:excel" ,
131
+ XMLNSmv : "http://macVmlSchemaUri" ,
132
+ Shapelayout : & xlsxShapelayout {
133
+ Ext : "edit" ,
134
+ IDmap : & xlsxIDmap {
135
+ Ext : "edit" ,
136
+ Data : commentID ,
137
+ },
144
138
},
145
- VPath : & vPath {
146
- Gradientshapeok : "t" ,
147
- Connecttype : "miter" ,
139
+ Shapetype : & xlsxShapetype {
140
+ ID : "_x0000_t202" ,
141
+ Coordsize : "21600,21600" ,
142
+ Spt : 202 ,
143
+ Path : "m0,0l0,21600,21600,21600,21600,0xe" ,
144
+ Stroke : & xlsxStroke {
145
+ Joinstyle : "miter" ,
146
+ },
147
+ VPath : & vPath {
148
+ Gradientshapeok : "t" ,
149
+ Connecttype : "miter" ,
150
+ },
148
151
},
149
- },
152
+ }
150
153
}
151
154
sp := encodeShape {
152
155
Fill : & vFill {
@@ -191,10 +194,8 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
191
194
Strokecolor : "#edeaa1" ,
192
195
Val : string (s [13 : len (s )- 14 ]),
193
196
}
194
- c , ok := f .XLSX [drawingVML ]
195
- if ok {
196
- d := decodeVmlDrawing {}
197
- _ = xml .Unmarshal (namespaceStrictToTransitional (c ), & d )
197
+ d := f .decodeVMLDrawingReader (drawingVML )
198
+ if d != nil {
198
199
for _ , v := range d .Shape {
199
200
s := xlsxShape {
200
201
ID : "_x0000_s1025" ,
@@ -208,8 +209,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
208
209
}
209
210
}
210
211
vml .Shape = append (vml .Shape , shape )
211
- v , _ := xml .Marshal (vml )
212
- f .XLSX [drawingVML ] = v
212
+ f .VMLDrawing [drawingVML ] = vml
213
213
}
214
214
215
215
// addComment provides a function to create chart as xl/comments%d.xml by
@@ -223,12 +223,15 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
223
223
if len (t ) > 32512 {
224
224
t = t [0 :32512 ]
225
225
}
226
- comments := xlsxComments {
227
- Authors : []xlsxAuthor {
228
- {
229
- Author : formatSet .Author ,
226
+ comments := f .commentsReader (commentsXML )
227
+ if comments == nil {
228
+ comments = & xlsxComments {
229
+ Authors : []xlsxAuthor {
230
+ {
231
+ Author : formatSet .Author ,
232
+ },
230
233
},
231
- },
234
+ }
232
235
}
233
236
cmt := xlsxComment {
234
237
Ref : cell ,
@@ -261,15 +264,8 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
261
264
},
262
265
},
263
266
}
264
- c , ok := f .XLSX [commentsXML ]
265
- if ok {
266
- d := xlsxComments {}
267
- _ = xml .Unmarshal (namespaceStrictToTransitional (c ), & d )
268
- comments .CommentList .Comment = append (comments .CommentList .Comment , d .CommentList .Comment ... )
269
- }
270
267
comments .CommentList .Comment = append (comments .CommentList .Comment , cmt )
271
- v , _ := xml .Marshal (comments )
272
- f .saveFileList (commentsXML , v )
268
+ f .Comments [commentsXML ] = comments
273
269
}
274
270
275
271
// countComments provides a function to get comments files count storage in
@@ -283,3 +279,53 @@ func (f *File) countComments() int {
283
279
}
284
280
return count
285
281
}
282
+
283
+ // decodeVMLDrawingReader provides a function to get the pointer to the
284
+ // structure after deserialization of xl/drawings/vmlDrawing%d.xml.
285
+ func (f * File ) decodeVMLDrawingReader (path string ) * decodeVmlDrawing {
286
+ if f .DecodeVMLDrawing [path ] == nil {
287
+ c , ok := f .XLSX [path ]
288
+ if ok {
289
+ d := decodeVmlDrawing {}
290
+ _ = xml .Unmarshal (namespaceStrictToTransitional (c ), & d )
291
+ f .DecodeVMLDrawing [path ] = & d
292
+ }
293
+ }
294
+ return f .DecodeVMLDrawing [path ]
295
+ }
296
+
297
+ // vmlDrawingWriter provides a function to save xl/drawings/vmlDrawing%d.xml.
298
+ // after serialize structure.
299
+ func (f * File ) vmlDrawingWriter () {
300
+ for path , vml := range f .VMLDrawing {
301
+ if vml != nil {
302
+ v , _ := xml .Marshal (vml )
303
+ f .XLSX [path ] = v
304
+ }
305
+ }
306
+ }
307
+
308
+ // commentsReader provides a function to get the pointer to the structure
309
+ // after deserialization of xl/comments%d.xml.
310
+ func (f * File ) commentsReader (path string ) * xlsxComments {
311
+ if f .Comments [path ] == nil {
312
+ content , ok := f .XLSX [path ]
313
+ if ok {
314
+ c := xlsxComments {}
315
+ _ = xml .Unmarshal (namespaceStrictToTransitional (content ), & c )
316
+ f .Comments [path ] = & c
317
+ }
318
+ }
319
+ return f .Comments [path ]
320
+ }
321
+
322
+ // commentsWriter provides a function to save xl/comments%d.xml after
323
+ // serialize structure.
324
+ func (f * File ) commentsWriter () {
325
+ for path , c := range f .Comments {
326
+ if c != nil {
327
+ v , _ := xml .Marshal (c )
328
+ f .saveFileList (path , v )
329
+ }
330
+ }
331
+ }
0 commit comments