@@ -124,7 +124,8 @@ public function __construct($tableStyle = null, $firstRowStyle = null)
124
124
{
125
125
$ this ->alignment = new Alignment ();
126
126
127
- if ($ firstRowStyle !== null && is_array ($ firstRowStyle )) {
127
+ // Clone first row from table style, but with certain properties disabled
128
+ if ($ firstRowStyle !== null && is_array ($ firstRowStyle )) {
128
129
$ this ->firstRow = clone $ this ;
129
130
unset($ this ->firstRow ->firstRow );
130
131
unset($ this ->firstRow ->borderInsideHSize );
@@ -257,7 +258,7 @@ public function setBorderColor($value = null)
257
258
*/
258
259
public function getBorderInsideHSize ()
259
260
{
260
- return isset ( $ this ->borderInsideHSize ) ? $ this -> borderInsideHSize : null ;
261
+ return $ this ->getTableOnlyProperty ( ' borderInsideHSize ' ) ;
261
262
}
262
263
263
264
/**
@@ -268,9 +269,7 @@ public function getBorderInsideHSize()
268
269
*/
269
270
public function setBorderInsideHSize ($ value = null )
270
271
{
271
- $ this ->borderInsideHSize = $ this ->setNumericVal ($ value , $ this ->borderInsideHSize );
272
-
273
- return $ this ;
272
+ return $ this ->setTableOnlyProperty ('borderInsideHSize ' , $ value );
274
273
}
275
274
276
275
/**
@@ -280,7 +279,7 @@ public function setBorderInsideHSize($value = null)
280
279
*/
281
280
public function getBorderInsideHColor ()
282
281
{
283
- return isset ( $ this ->borderInsideHColor ) ? $ this -> borderInsideHColor : null ;
282
+ return $ this ->getTableOnlyProperty ( ' borderInsideHColor ' ) ;
284
283
}
285
284
286
285
/**
@@ -291,9 +290,7 @@ public function getBorderInsideHColor()
291
290
*/
292
291
public function setBorderInsideHColor ($ value = null )
293
292
{
294
- $ this ->borderInsideHColor = $ value ;
295
-
296
- return $ this ;
293
+ return $ this ->setTableOnlyProperty ('borderInsideHColor ' , $ value , false );
297
294
}
298
295
299
296
/**
@@ -303,7 +300,7 @@ public function setBorderInsideHColor($value = null)
303
300
*/
304
301
public function getBorderInsideVSize ()
305
302
{
306
- return isset ( $ this ->borderInsideVSize ) ? $ this -> borderInsideVSize : null ;
303
+ return $ this ->getTableOnlyProperty ( ' borderInsideVSize ' ) ;
307
304
}
308
305
309
306
/**
@@ -314,9 +311,7 @@ public function getBorderInsideVSize()
314
311
*/
315
312
public function setBorderInsideVSize ($ value = null )
316
313
{
317
- $ this ->borderInsideVSize = $ this ->setNumericVal ($ value , $ this ->borderInsideVSize );
318
-
319
- return $ this ;
314
+ return $ this ->setTableOnlyProperty ('borderInsideVSize ' , $ value );
320
315
}
321
316
322
317
/**
@@ -326,7 +321,7 @@ public function setBorderInsideVSize($value = null)
326
321
*/
327
322
public function getBorderInsideVColor ()
328
323
{
329
- return isset ( $ this ->borderInsideVColor ) ? $ this -> borderInsideVColor : null ;
324
+ return $ this ->getTableOnlyProperty ( ' borderInsideVColor ' ) ;
330
325
}
331
326
332
327
/**
@@ -337,9 +332,7 @@ public function getBorderInsideVColor()
337
332
*/
338
333
public function setBorderInsideVColor ($ value = null )
339
334
{
340
- $ this ->borderInsideVColor = $ value ;
341
-
342
- return $ this ;
335
+ return $ this ->setTableOnlyProperty ('borderInsideVColor ' , $ value , false );
343
336
}
344
337
345
338
/**
@@ -349,7 +342,7 @@ public function setBorderInsideVColor($value = null)
349
342
*/
350
343
public function getCellMarginTop ()
351
344
{
352
- return $ this ->cellMarginTop ;
345
+ return $ this ->getTableOnlyProperty ( ' cellMarginTop ' ) ;
353
346
}
354
347
355
348
/**
@@ -360,9 +353,7 @@ public function getCellMarginTop()
360
353
*/
361
354
public function setCellMarginTop ($ value = null )
362
355
{
363
- $ this ->cellMarginTop = $ this ->setNumericVal ($ value , $ this ->cellMarginTop );
364
-
365
- return $ this ;
356
+ return $ this ->setTableOnlyProperty ('cellMarginTop ' , $ value );
366
357
}
367
358
368
359
/**
@@ -372,7 +363,7 @@ public function setCellMarginTop($value = null)
372
363
*/
373
364
public function getCellMarginLeft ()
374
365
{
375
- return $ this ->cellMarginLeft ;
366
+ return $ this ->getTableOnlyProperty ( ' cellMarginLeft ' ) ;
376
367
}
377
368
378
369
/**
@@ -383,9 +374,7 @@ public function getCellMarginLeft()
383
374
*/
384
375
public function setCellMarginLeft ($ value = null )
385
376
{
386
- $ this ->cellMarginLeft = $ this ->setNumericVal ($ value , $ this ->cellMarginLeft );
387
-
388
- return $ this ;
377
+ return $ this ->setTableOnlyProperty ('cellMarginLeft ' , $ value );
389
378
}
390
379
391
380
/**
@@ -395,7 +384,7 @@ public function setCellMarginLeft($value = null)
395
384
*/
396
385
public function getCellMarginRight ()
397
386
{
398
- return $ this ->cellMarginRight ;
387
+ return $ this ->getTableOnlyProperty ( ' cellMarginRight ' ) ;
399
388
}
400
389
401
390
/**
@@ -406,9 +395,7 @@ public function getCellMarginRight()
406
395
*/
407
396
public function setCellMarginRight ($ value = null )
408
397
{
409
- $ this ->cellMarginRight = $ this ->setNumericVal ($ value , $ this ->cellMarginRight );
410
-
411
- return $ this ;
398
+ return $ this ->setTableOnlyProperty ('cellMarginRight ' , $ value );
412
399
}
413
400
414
401
/**
@@ -418,7 +405,7 @@ public function setCellMarginRight($value = null)
418
405
*/
419
406
public function getCellMarginBottom ()
420
407
{
421
- return $ this ->cellMarginBottom ;
408
+ return $ this ->getTableOnlyProperty ( ' cellMarginBottom ' ) ;
422
409
}
423
410
424
411
/**
@@ -429,9 +416,7 @@ public function getCellMarginBottom()
429
416
*/
430
417
public function setCellMarginBottom ($ value = null )
431
418
{
432
- $ this ->cellMarginBottom = $ this ->setNumericVal ($ value , $ this ->cellMarginBottom );
433
-
434
- return $ this ;
419
+ return $ this ->setTableOnlyProperty ('cellMarginBottom ' , $ value );
435
420
}
436
421
437
422
/**
@@ -569,4 +554,46 @@ public function setUnit($value = null)
569
554
570
555
return $ this ;
571
556
}
557
+
558
+ /**
559
+ * Get table style only property by checking if firstRow is set
560
+ *
561
+ * This is necessary since firstRow style is cloned from table style but
562
+ * without certain properties activated, e.g. margins
563
+ *
564
+ * @param string $property
565
+ * @return int|string|null
566
+ */
567
+ private function getTableOnlyProperty ($ property )
568
+ {
569
+ if (isset ($ this ->firstRow )) {
570
+ return $ this ->$ property ;
571
+ }
572
+
573
+ return null ;
574
+ }
575
+
576
+ /**
577
+ * Set table style only property by checking if firstRow is set
578
+ *
579
+ * This is necessary since firstRow style is cloned from table style but
580
+ * without certain properties activated, e.g. margins
581
+ *
582
+ * @param string $property
583
+ * @param int|string $value
584
+ * @param bool $isNumeric
585
+ * @return self
586
+ */
587
+ private function setTableOnlyProperty ($ property , $ value , $ isNumeric = true )
588
+ {
589
+ if (isset ($ this ->firstRow )) {
590
+ if ($ isNumeric ) {
591
+ $ this ->$ property = $ this ->setNumericVal ($ value , $ this ->$ property );
592
+ } else {
593
+ $ this ->$ property = $ value ;
594
+ }
595
+ }
596
+
597
+ return $ this ;
598
+ }
572
599
}
0 commit comments