Skip to content

Commit 554f304

Browse files
author
Patrick Brouwers
committed
Change min. stability to stable
2 parents cc81ffb + e2a17f9 commit 554f304

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

src/Maatwebsite/Excel/Excel.php

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Excel extends \PHPExcel
1616
{
1717

1818

19-
protected $excel;
19+
public $excel;
2020
protected $object;
2121
public $i = 0; // the current sheet number
2222
public $title;
@@ -1136,4 +1136,79 @@ public function setColumnFormat(Array $formats){
11361136
return $this;
11371137
}
11381138

1139+
/**
1140+
*
1141+
* Set the cell width of the columns
1142+
*
1143+
* @return $this
1144+
* @param array $pane An array of column widths
1145+
*
1146+
* @author xiehai
1147+
* @example ->setColumnWidth(array(
1148+
* 'A' => '10',
1149+
* 'B' => '22',
1150+
* 'F' => '8',
1151+
* 'N' => '13',
1152+
* ......
1153+
* )
1154+
* )
1155+
*
1156+
*/
1157+
1158+
public function setColumnWidth(Array $pane)
1159+
{
1160+
1161+
foreach ($pane as $column => $width) {
1162+
$this->excel->getActiveSheet()->getColumnDimension($column)->setWidth($width);
1163+
}
1164+
1165+
return $this;
1166+
}
1167+
1168+
/**
1169+
*
1170+
* Set the columns you want to merge
1171+
*
1172+
* @return $this
1173+
* @param array $mergeColumn An array of columns you want to merge
1174+
*
1175+
* @author xiehai
1176+
* @example $mergeColumn = array(
1177+
* 'columns' => array('A','B','C','D'),
1178+
* 'rows' => array(
1179+
* array(2,3),
1180+
* array(5,11),
1181+
* .....
1182+
* )
1183+
* );
1184+
*
1185+
*/
1186+
public function setMergeColumn(Array $mergeColumn)
1187+
{
1188+
1189+
foreach ($mergeColumn['columns'] as $column) {
1190+
foreach ($mergeColumn['rows'] as $row) {
1191+
$this->mergeCells($column.$row[0].":".$column.$row[1]);
1192+
}
1193+
}
1194+
1195+
return $this;
1196+
}
1197+
1198+
/**
1199+
*
1200+
* Native merged cell method
1201+
*
1202+
* @return $this
1203+
* @param array $cells
1204+
*
1205+
* @author xiehai
1206+
*
1207+
*/
1208+
public function mergeCells($cells)
1209+
{
1210+
$this->excel->getActiveSheet()->mergeCells($cells);
1211+
return $this;
1212+
}
1213+
11391214
}

0 commit comments

Comments
 (0)