Skip to content

Commit e2a17f9

Browse files
MaatwebsiteMaatwebsite
authored andcommitted
Merge pull request SpartnerNL#13 from hicode/master
+ Set the cell width of the columns
2 parents 76891c5 + b02c511 commit e2a17f9

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

src/Maatwebsite/Excel/Excel.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,4 +1135,80 @@ public function setColumnFormat(Array $formats){
11351135

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

0 commit comments

Comments
 (0)