@@ -1277,31 +1277,62 @@ func (f *File) extractNumFmt(xf xlsxXf, s *xlsxStyleSheet, style *Style) {
1277
1277
// extractAlignment provides a function to extract alignment format by
1278
1278
// given style definition.
1279
1279
func (f * File ) extractAlignment (xf xlsxXf , s * xlsxStyleSheet , style * Style ) {
1280
- style .Alignment = & Alignment {
1281
- Horizontal : xf .Alignment .Horizontal ,
1282
- Indent : xf .Alignment .Indent ,
1283
- JustifyLastLine : xf .Alignment .JustifyLastLine ,
1284
- ReadingOrder : xf .Alignment .ReadingOrder ,
1285
- RelativeIndent : xf .Alignment .RelativeIndent ,
1286
- ShrinkToFit : xf .Alignment .ShrinkToFit ,
1287
- TextRotation : xf .Alignment .TextRotation ,
1288
- Vertical : xf .Alignment .Vertical ,
1289
- WrapText : xf .Alignment .WrapText ,
1280
+ if xf .ApplyAlignment != nil && * xf .ApplyAlignment && xf .Alignment != nil {
1281
+ style .Alignment = & Alignment {
1282
+ Horizontal : xf .Alignment .Horizontal ,
1283
+ Indent : xf .Alignment .Indent ,
1284
+ JustifyLastLine : xf .Alignment .JustifyLastLine ,
1285
+ ReadingOrder : xf .Alignment .ReadingOrder ,
1286
+ RelativeIndent : xf .Alignment .RelativeIndent ,
1287
+ ShrinkToFit : xf .Alignment .ShrinkToFit ,
1288
+ TextRotation : xf .Alignment .TextRotation ,
1289
+ Vertical : xf .Alignment .Vertical ,
1290
+ WrapText : xf .Alignment .WrapText ,
1291
+ }
1290
1292
}
1291
1293
}
1292
1294
1293
1295
// extractProtection provides a function to extract protection settings by
1294
1296
// given format definition.
1295
1297
func (f * File ) extractProtection (xf xlsxXf , s * xlsxStyleSheet , style * Style ) {
1296
- style .Protection = & Protection {}
1297
- if xf .Protection .Hidden != nil {
1298
- style .Protection .Hidden = * xf .Protection .Hidden
1299
- }
1300
- if xf .Protection .Locked != nil {
1301
- style .Protection .Locked = * xf .Protection .Locked
1298
+ if xf .ApplyProtection != nil && * xf .ApplyProtection && xf .Protection != nil {
1299
+ style .Protection = & Protection {}
1300
+ if xf .Protection .Hidden != nil {
1301
+ style .Protection .Hidden = * xf .Protection .Hidden
1302
+ }
1303
+ if xf .Protection .Locked != nil {
1304
+ style .Protection .Locked = * xf .Protection .Locked
1305
+ }
1302
1306
}
1303
1307
}
1304
1308
1309
+ // GetStyle get style details by given style index.
1310
+ func (f * File ) GetStyle (idx int ) (* Style , error ) {
1311
+ var style * Style
1312
+ f .mu .Lock ()
1313
+ s , err := f .stylesReader ()
1314
+ if err != nil {
1315
+ return style , err
1316
+ }
1317
+ f .mu .Unlock ()
1318
+ if idx < 0 || s .CellXfs == nil || len (s .CellXfs .Xf ) <= idx {
1319
+ return style , newInvalidStyleID (idx )
1320
+ }
1321
+ style = & Style {}
1322
+ xf := s .CellXfs .Xf [idx ]
1323
+ if xf .ApplyFill != nil && * xf .ApplyFill &&
1324
+ xf .FillID != nil && s .Fills != nil &&
1325
+ * xf .FillID < len (s .Fills .Fill ) {
1326
+ f .extractFills (xf , s , style )
1327
+ }
1328
+ f .extractBorders (xf , s , style )
1329
+ f .extractFont (xf , s , style )
1330
+ f .extractAlignment (xf , s , style )
1331
+ f .extractProtection (xf , s , style )
1332
+ f .extractNumFmt (xf , s , style )
1333
+ return style , nil
1334
+ }
1335
+
1305
1336
// getXfIDFuncs provides a function to get xfID by given style.
1306
1337
var getXfIDFuncs = map [string ]func (int , xlsxXf , * Style ) bool {
1307
1338
"numFmt" : func (numFmtID int , xf xlsxXf , style * Style ) bool {
0 commit comments