Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved problem with rowspan (#917) #1001

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
@@ -1,5 +1,5 @@
{
"name": "maatwebsite/excel",
"name": "melnykdmitro/excel",
"description": "An eloquent way of importing and exporting Excel and CSV in Laravel 4 with the power of PHPExcel",
"license": "LGPL",
"keywords": [
Expand Down
8 changes: 6 additions & 2 deletions src/Maatwebsite/Excel/Parsers/ExcelParser.php
Expand Up @@ -570,8 +570,12 @@ protected function parseDateAsCarbon()
// Convert excel time to php date object
$date = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue())->format('Y-m-d H:i:s');

// Parse with carbon
$date = Carbon::parse($date);
// Parse with carbon
if (strtotime($date)) {
$date = Carbon::parse($date);
} else {
$date = Carbon::now();
}

// Format the date if wanted
return $this->reader->getDateFormat() ? $date->format($this->reader->getDateFormat()) : $date;
Expand Down
35 changes: 28 additions & 7 deletions src/Maatwebsite/Excel/Readers/HtmlReader.php
Expand Up @@ -275,6 +275,10 @@ protected function _processDomElement(DOMNode $element, $sheet, &$row, &$column,
{
$attributeArray = array();

if ($child->nodeName == 'td') {
$this->offsetMergedCells($sheet, $column, $row);
}

// Set row (=parent) styles
if ( isset($this->styles[$row]) )
$this->parseInlineStyles($sheet, $column, $row, $this->styles[$row]);
Expand Down Expand Up @@ -446,8 +450,8 @@ protected function _processDomElement(DOMNode $element, $sheet, &$row, &$column,

// Set the url
$sheet->getCell($column . $row)
->getHyperlink()
->setUrl($attributeValue);
->getHyperlink()
->setUrl($attributeValue);

// Set styling
if ( isset($this->_formats[$child->nodeName]) )
Expand Down Expand Up @@ -612,10 +616,10 @@ protected function _processDomElement(DOMNode $element, $sheet, &$row, &$column,
$this->flushCell($sheet, $column, $row, $cellContent);

// If we have a colspan, count the right amount of columns, else just 1
for ($w = 0; $w < $this->spanWidth; $w++)
{
++$column;
}
// for ($w = 0; $w < $this->spanWidth; $w++)
// {
++$column;
// }

// reset the span width after the process
$this->spanWidth = 1;
Expand Down Expand Up @@ -780,7 +784,7 @@ protected function insertImageBySrc($sheet, $column, $row, $attributes)
* @param integer $row
* @param integer $width
* @return void
*/
*/
protected function parseDataFormat($sheet, $column, $row, $format)
{
$sheet->setColumnFormat([$column.$row => $format]);
Expand Down Expand Up @@ -1364,4 +1368,21 @@ private function processMergedCells($sheet, &$column, $row, $cellContent)

return array($column, $cellContent);
}

/**
* @param $sheet
* @param $column
* @param $row
*/
protected function offsetMergedCells($sheet, &$column, $row)
{
foreach ($sheet->getMergeCells() as $cells) {
$cell = $sheet->getCell($column . $row);
if ($cell->isInRange($cells)) {
++$column;
$this->offsetMergedCells($sheet, $column, $row);
return;
}
}
}
}