Fixing style errors.

This commit is contained in:
stickler-ci 2020-10-08 08:34:40 +00:00
parent fe8d7f7f1b
commit f5b34370b6

View File

@ -448,18 +448,19 @@ class ExportExcel2007new extends ModeleExports
* @param string $endCell
* @return int 1 if success -1 if failed
*/
public function setCellValue($val, $startCell, $endCell = '') {
public function setCellValue($val, $startCell, $endCell = '')
{
try {
$this->workbook->getActiveSheet()->setCellValue($startCell, $val);
if(! empty($endCell)) {
if (! empty($endCell)) {
$cellRange = $startCell.':'.$endCell;
$this->workbook->getActiveSheet()->mergeCells($startCell.':'.$endCell);
}
else $cellRange = $startCell;
if(! empty($this->styleArray)) $this->workbook->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->styleArray);
if (! empty($this->styleArray)) $this->workbook->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->styleArray);
}
catch(Exception $e) {
catch (Exception $e) {
$this->error = $e->getMessage();
return -1;
}
@ -472,7 +473,8 @@ class ExportExcel2007new extends ModeleExports
* @param string $thickness style \PhpOffice\PhpSpreadsheet\Style\Border
* @param string $color color \PhpOffice\PhpSpreadsheet\Style\Color
*/
public function setBorderStyle($thickness, $color) {
public function setBorderStyle($thickness, $color)
{
$this->styleArray['borders'] = array(
'outline' => array(
'borderStyle' => $thickness,
@ -487,7 +489,8 @@ class ExportExcel2007new extends ModeleExports
* @param bool $bold
* @param string $color color \PhpOffice\PhpSpreadsheet\Style\Color
*/
public function setFontStyle($bold, $color) {
public function setFontStyle($bold, $color)
{
$this->styleArray['font'] = array(
'color' => array('argb' => $color),
'bold' => $bold
@ -499,14 +502,16 @@ class ExportExcel2007new extends ModeleExports
*
* @param string $horizontal PhpOffice\PhpSpreadsheet\Style\Alignment
*/
public function setAlignmentStyle($horizontal) {
public function setAlignmentStyle($horizontal)
{
$this->styleArray['alignment'] = array('horizontal' => $horizontal);
}
/**
* Reset Style
*/
public function resetStyle() {
public function resetStyle()
{
$this->styleArray = array();
}
@ -518,19 +523,20 @@ class ExportExcel2007new extends ModeleExports
* @param bool $boldTitle
* @return int 1 if OK, -1 if KO
*/
public function setBlock($startCell, $TDatas = array(), $boldTitle = false) {
public function setBlock($startCell, $TDatas = array(), $boldTitle = false)
{
try {
if(! empty($TDatas)) {
if (! empty($TDatas)) {
$startCell = $this->workbook->getActiveSheet()->getCell($startCell);
$startColumn = Coordinate::columnIndexFromString($startCell->getColumn());
$startRow = $startCell->getRow();
foreach($TDatas as $column => $TRows) {
if($boldTitle) $this->setFontStyle(true, $this->styleArray['font']['color']['argb']);
foreach ($TDatas as $column => $TRows) {
if ($boldTitle) $this->setFontStyle(true, $this->styleArray['font']['color']['argb']);
$cell = $this->workbook->getActiveSheet()->getCellByColumnAndRow($startColumn, $startRow);
$this->setCellValue($column, $cell->getCoordinate());
$rowPos = $startRow;
if($boldTitle) $this->setFontStyle(false, $this->styleArray['font']['color']['argb']);
foreach($TRows as $row) {
if ($boldTitle) $this->setFontStyle(false, $this->styleArray['font']['color']['argb']);
foreach ($TRows as $row) {
$rowPos++;
$cell = $this->workbook->getActiveSheet()->getCellByColumnAndRow($startColumn, $rowPos);
$this->setCellValue($row, $cell->getCoordinate());
@ -539,7 +545,7 @@ class ExportExcel2007new extends ModeleExports
}
}
}
catch(Exception $e) {
catch (Exception $e) {
$this->error = $e->getMessage();
return -1;
}
@ -554,24 +560,25 @@ class ExportExcel2007new extends ModeleExports
* @param bool $boldTitle
* @return int 1 if OK, -1 if KO
*/
public function setBlock2Columns($startCell, $TDatas = array(), $boldTitle = false) {
public function setBlock2Columns($startCell, $TDatas = array(), $boldTitle = false)
{
try {
if(! empty($TDatas)) {
if (! empty($TDatas)) {
$startCell = $this->workbook->getActiveSheet()->getCell($startCell);
$startColumn = Coordinate::columnIndexFromString($startCell->getColumn());
$startRow = $startCell->getRow();
foreach($TDatas as $title => $val) {
foreach ($TDatas as $title => $val) {
$cell = $this->workbook->getActiveSheet()->getCellByColumnAndRow($startColumn, $startRow);
if($boldTitle) $this->setFontStyle(true, $this->styleArray['font']['color']['argb']);
if ($boldTitle) $this->setFontStyle(true, $this->styleArray['font']['color']['argb']);
$this->setCellValue($title, $cell->getCoordinate());
if($boldTitle) $this->setFontStyle(false, $this->styleArray['font']['color']['argb']);
if ($boldTitle) $this->setFontStyle(false, $this->styleArray['font']['color']['argb']);
$cell2 = $this->workbook->getActiveSheet()->getCellByColumnAndRow($startColumn + 1, $startRow);
$this->setCellValue($val, $cell2->getCoordinate());
$startRow++;
}
}
}
catch(Exception $e) {
catch (Exception $e) {
$this->error = $e->getMessage();
return -1;
}
@ -584,8 +591,9 @@ class ExportExcel2007new extends ModeleExports
* @param string $firstColumn
* @param string $lastColumn
*/
public function enableAutosize($firstColumn, $lastColumn) {
foreach(range($firstColumn, $lastColumn) as $columnID) {
public function enableAutosize($firstColumn, $lastColumn)
{
foreach (range($firstColumn, $lastColumn) as $columnID) {
$this->workbook->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
}
}
@ -599,11 +607,12 @@ class ExportExcel2007new extends ModeleExports
* @param int $offset Starting offset
* @return string Coordinate or -1 if KO
*/
public function setMergeCellValueByLength($val, $startCell, $length, $offset = 0) {
public function setMergeCellValueByLength($val, $startCell, $length, $offset = 0)
{
try {
$startCell = $this->workbook->getActiveSheet()->getCell($startCell);
$startColumn = Coordinate::columnIndexFromString($startCell->getColumn());
if(! empty($offset)) $startColumn += $offset;
if (! empty($offset)) $startColumn += $offset;
$startRow = $startCell->getRow();
$startCell = $this->workbook->getActiveSheet()->getCellByColumnAndRow($startColumn, $startRow);
@ -614,7 +623,7 @@ class ExportExcel2007new extends ModeleExports
$endCoordinate = $endCell->getCoordinate();
$this->workbook->getActiveSheet()->mergeCells($startCoordinate.':'.$endCoordinate);
}
catch(Exception $e) {
catch (Exception $e) {
$this->error = $e->getMessage();
return -1;
}