@@ -57,8 +57,8 @@ func New() *Workbook {
57
57
wb .wbRels .AddRelationship ("styles.xml" , common .StylesType )
58
58
59
59
wb .ContentTypes = common .NewContentTypes ()
60
- wb .ContentTypes .AddOverride ("/xl/workbook.xml" , "application/vnd.openxmlformats-officedocument.sml .sheet.main+xml" )
61
- wb .ContentTypes .AddOverride ("/xl/styles.xml" , "application/vnd.openxmlformats-officedocument.sml .styles+xml" )
60
+ wb .ContentTypes .AddOverride ("/xl/workbook.xml" , "application/vnd.openxmlformats-officedocument.spreadsheetml .sheet.main+xml" )
61
+ wb .ContentTypes .AddOverride ("/xl/styles.xml" , "application/vnd.openxmlformats-officedocument.spreadsheetml .styles+xml" )
62
62
63
63
wb .SharedStrings = NewSharedStrings ()
64
64
wb .ContentTypes .AddOverride ("/xl/sharedStrings.xml" , common .SharedStringsContentType )
@@ -225,17 +225,17 @@ func (wb *Workbook) AddSheet() Sheet {
225
225
ws .Dimension = sml .NewCT_SheetDimension ()
226
226
ws .Dimension .RefAttr = "A1"
227
227
wb .xws = append (wb .xws , ws )
228
-
228
+ wb . xwsRels = append ( wb . xwsRels , common . NewRelationships ())
229
229
ws .SheetData = sml .NewCT_SheetData ()
230
230
231
231
// update the references
232
- rid := wb .wbRels .AddRelationship (fmt .Sprintf ("worksheets/sheet%d.xml" , rs . SheetIdAttr ),
232
+ rid := wb .wbRels .AddRelationship (fmt .Sprintf ("worksheets/sheet%d.xml" , len ( wb . x . Sheets . Sheet ) ),
233
233
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" )
234
234
rs .IdAttr = rid .ID ()
235
235
236
236
// add the content type
237
- wb .ContentTypes .AddOverride (fmt .Sprintf ("/xl/worksheets/sheet%d.xml" , rs . SheetIdAttr ),
238
- "application/vnd.openxmlformats-officedocument.sml .worksheet+xml" )
237
+ wb .ContentTypes .AddOverride (fmt .Sprintf ("/xl/worksheets/sheet%d.xml" , len ( wb . x . Sheets . Sheet ) ),
238
+ "application/vnd.openxmlformats-officedocument.spreadsheetml .worksheet+xml" )
239
239
240
240
return Sheet {wb , rs , ws }
241
241
}
@@ -284,8 +284,9 @@ func (wb *Workbook) Save(w io.Writer) error {
284
284
}
285
285
}
286
286
for i , sheet := range wb .xws {
287
- wbs := wb .x .Sheets .Sheet [i ]
288
- zippkg .MarshalXML (z , fmt .Sprintf ("xl/worksheets/sheet%d.xml" , wbs .SheetIdAttr ), sheet )
287
+ fn := fmt .Sprintf ("xl/worksheets/sheet%d.xml" , i + 1 )
288
+ zippkg .MarshalXML (z , fn , sheet )
289
+ zippkg .MarshalXML (z , zippkg .RelationsPathFor (fn ), wb .xwsRels [i ].X ())
289
290
}
290
291
if wb .Thumbnail != nil {
291
292
tn , err := z .Create ("docProps/thumbnail.jpeg" )
@@ -296,7 +297,9 @@ func (wb *Workbook) Save(w io.Writer) error {
296
297
return err
297
298
}
298
299
}
299
- wb .WriteExtraFiles (z )
300
+ if err := wb .WriteExtraFiles (z ); err != nil {
301
+ return err
302
+ }
300
303
return z .Close ()
301
304
}
302
305
0 commit comments