Skip to content

Commit

Permalink
Add Columns Format feature
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Mar 29, 2018
1 parent c0a642b commit 26d0655
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ OUTLINE
- [Merge Cells](#merge-cells)
- [Multiple Sheets](#multiple-sheets)
- [Map of Coordinates & Ranges](#multiple-sheets)
- [Columns Format](#columns-format)
- [Cells Format](#cells-format)

---
Expand Down Expand Up @@ -293,10 +294,26 @@ sn range: A1:A2
All range: A1:E4
```

### Columns Format

The options for each cell data:

* `width`: setWidth() for the column

```php
\yidas\phpSpreadsheet\Helper::newSpreadsheet()
->addRow([['value'=>'ID', 'width'=>10], ['value'=>'Name', 'width'=>25], ['value'=>'Email', 'width'=>50]])
->addRows([
['1', 'Nick','myintaer@gmail.com'],
['2', 'Eric','eric@.....'],
])
->output('My Excel');
```

### Cells Format

* setWrapText(): Set to all cells by default
* setAutoSize(): Set to all cells(columns) by default
* `setWrapText()`: Set to all cells by default
* `setAutoSize()`: Set to all cells(columns) by default

```php
\yidas\phpSpreadsheet\Helper::newSpreadsheet()
Expand Down
11 changes: 11 additions & 0 deletions demo/columns-format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

require __DIR__ . '/_config.php';

\yidas\phpSpreadsheet\Helper::newSpreadsheet()
->addRow([['value'=>'ID', 'width'=>10], ['value'=>'Name', 'width'=>25], ['value'=>'Email', 'width'=>50]])
->addRows([
['1', 'Nick','myintaer@gmail.com'],
['2', 'Eric','eric@.....'],
])
->output('My Excel');
9 changes: 8 additions & 1 deletion src/phpSpreadsheet/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* PhpSpreadsheet Helper
*
* @author Nick Tsai <myintaer@gmail.com>
* @version 1.1.4
* @version 1.1.5
* @filesource PhpSpreadsheet <https://github.com/PHPOffice/PhpSpreadsheet>
* @see https://github.com/yidas/phpspreadsheet-helper
* @example
Expand Down Expand Up @@ -263,6 +263,7 @@ public static function addRow($rowData)
if (is_array($value)) {

// Options
$width = isset($value['width']) ? $value['width'] : NULL;
$colspan = isset($value['col']) ? $value['col'] : 1;
$rowspan = isset($value['row']) ? $value['row'] : 1;
$skip = isset($value['skip']) ? $value['skip'] : 1;
Expand All @@ -271,6 +272,12 @@ public static function addRow($rowData)

$sheetObj->setCellValueByColumnAndRow($posCol, self::$_offsetRow, $value);

// Setting the column's width
if ($width) {

$sheetObj->getColumnDimension(self::num2alpha($posCol))->setWidth($width);
}

// Merge handler
if ($colspan>1 || $rowspan>1) {
$posColLast = $posCol;
Expand Down

0 comments on commit 26d0655

Please sign in to comment.