ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Reader\Html Class Reference

PhpSpreadsheet root directory. More...

+ Inheritance diagram for PhpOffice\PhpSpreadsheet\Reader\Html:
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Reader\Html:

Public Member Functions

 __construct ()
 Create a new HTML Reader instance. More...
 
 canRead ($pFilename)
 Validate that the current file is an HTML file. More...
 
 load ($pFilename)
 Loads Spreadsheet from file. More...
 
 setInputEncoding ($pValue)
 Set input encoding. More...
 
 getInputEncoding ()
 Get input encoding. More...
 
 loadIntoExisting ($pFilename, Spreadsheet $spreadsheet)
 Loads PhpSpreadsheet from file into PhpSpreadsheet instance. More...
 
 loadFromString ($content, ?Spreadsheet $spreadsheet=null)
 Spreadsheet from content. More...
 
 getSheetIndex ()
 Get sheet index. More...
 
 setSheetIndex ($pValue)
 Set sheet index. More...
 
 getStyleColor ($value)
 Check if has #, so we can get clean hex. More...
 
 getBorderStyle ($style)
 Map html border style to PhpSpreadsheet border style. More...
 
- Public Member Functions inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 __construct ()
 IReader constructor. More...
 
 getReadDataOnly ()
 Read data only? If this is true, then the Reader will only read data values for cells, it will not read any formatting information. More...
 
 setReadDataOnly ($pValue)
 Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. More...
 
 getReadEmptyCells ()
 Read empty cells? If this is true (the default), then the Reader will read data values for all cells, irrespective of value. More...
 
 setReadEmptyCells ($pValue)
 Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. More...
 
 getIncludeCharts ()
 Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook. More...
 
 setIncludeCharts ($pValue)
 Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook. More...
 
 getLoadSheetsOnly ()
 Get which sheets to load Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null indicating that all worksheets in the workbook should be loaded. More...
 
 setLoadSheetsOnly ($value)
 Set which sheets to load. More...
 
 setLoadAllSheets ()
 Set all sheets to load Tells the Reader to load all worksheets from the workbook. More...
 
 getReadFilter ()
 Read filter. More...
 
 setReadFilter (IReadFilter $pValue)
 Set read filter. More...
 
 getSecurityScanner ()
 

Static Public Member Functions

static static getBorderMappings ()
 

Data Fields

const TEST_SAMPLE_SIZE = 2048
 Sample size to read to determine if it's HTML or not. More...
 

Protected Member Functions

 setTableStartColumn ($column)
 
 getTableStartColumn ()
 
 releaseTableStartColumn ()
 
 flushCell (Worksheet $sheet, $column, $row, &$cellContent)
 
 processDomElement (DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
 
- Protected Member Functions inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 openFile ($pFilename)
 Open file for reading. More...
 

Protected Attributes

 $inputEncoding = 'ANSI'
 
 $sheetIndex = 0
 
 $formats
 
 $rowspan = []
 
 $dataArray = []
 
 $tableLevel = 0
 
 $nestedColumn = ['A']
 
- Protected Attributes inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 $readDataOnly = false
 
 $readEmptyCells = true
 
 $includeCharts = false
 
 $loadSheetsOnly
 
 $readFilter
 
 $fileHandle
 
 $securityScanner
 

Private Member Functions

 readBeginning ()
 
 readEnding ()
 
 processDomElementBody (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child)
 
 processDomElementTitle (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementSpanEtc (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementHr (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementBr (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementA (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementH1Etc (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementLi (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementImg (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementTable (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementTr (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementThTdOther (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 processDomElementBgcolor (Worksheet $sheet, int $row, string $column, array $attributeArray)
 
 processDomElementWidth (Worksheet $sheet, string $column, array $attributeArray)
 
 processDomElementHeight (Worksheet $sheet, int $row, array $attributeArray)
 
 processDomElementAlign (Worksheet $sheet, int $row, string $column, array $attributeArray)
 
 processDomElementVAlign (Worksheet $sheet, int $row, string $column, array $attributeArray)
 
 processDomElementDataFormat (Worksheet $sheet, int $row, string $column, array $attributeArray)
 
 processDomElementThTd (Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
 
 loadDocument (DOMDocument $document, Spreadsheet $spreadsheet)
 Loads PhpSpreadsheet from DOMDocument into PhpSpreadsheet instance. More...
 
 applyInlineStyle (&$sheet, $row, $column, $attributeArray)
 Apply inline css inline style. More...
 
 insertImage (Worksheet $sheet, $column, $row, array $attributes)
 
 setBorderStyle (Style $cellStyle, $styleValue, $type)
 

Static Private Member Functions

static startsWithTag ($data)
 
static endsWithTag ($data)
 
static containsTags ($data)
 

Static Private Attributes

static $spanEtc = ['span', 'div', 'font', 'i', 'em', 'strong', 'b']
 
static $h1Etc = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'p']
 
static $borderMappings
 

Detailed Description

PhpSpreadsheet root directory.

Definition at line 22 of file Html.php.

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\Reader\Html::__construct ( )

Create a new HTML Reader instance.

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 130 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner\getInstance().

131  {
132  parent::__construct();
133  $this->securityScanner = XmlScanner::getInstance($this);
134  }
static getInstance(Reader\IReader $reader)
Definition: XmlScanner.php:39
+ Here is the call graph for this function:

Member Function Documentation

◆ applyInlineStyle()

PhpOffice\PhpSpreadsheet\Reader\Html::applyInlineStyle ( $sheet,
  $row,
  $column,
  $attributeArray 
)
private

Apply inline css inline style.

NOTES : Currently only intended for td & th element, and only takes 'background-color' and 'color'; property with HEX color

TODO :

  • Implement to other propertie, such as border
Parameters
Worksheet$sheet
int$row
string$column
array$attributeArray

Definition at line 743 of file Html.php.

References $i, $row, PhpOffice\PhpSpreadsheet\Style\Fill\FILL_SOLID, PhpOffice\PhpSpreadsheet\Reader\Html\getStyleColor(), and PhpOffice\PhpSpreadsheet\Reader\Html\setBorderStyle().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

743  : void
744  {
745  if (!isset($attributeArray['style'])) {
746  return;
747  }
748 
749  if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) {
750  $columnTo = $column;
751  for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
752  ++$columnTo;
753  }
754  $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1);
755  $cellStyle = $sheet->getStyle($range);
756  } elseif (isset($attributeArray['rowspan'])) {
757  $range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1);
758  $cellStyle = $sheet->getStyle($range);
759  } elseif (isset($attributeArray['colspan'])) {
760  $columnTo = $column;
761  for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
762  ++$columnTo;
763  }
764  $range = $column . $row . ':' . $columnTo . $row;
765  $cellStyle = $sheet->getStyle($range);
766  } else {
767  $cellStyle = $sheet->getStyle($column . $row);
768  }
769 
770  // add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color
771  $styles = explode(';', $attributeArray['style']);
772  foreach ($styles as $st) {
773  $value = explode(':', $st);
774  $styleName = isset($value[0]) ? trim($value[0]) : null;
775  $styleValue = isset($value[1]) ? trim($value[1]) : null;
776 
777  if (!$styleName) {
778  continue;
779  }
780 
781  switch ($styleName) {
782  case 'background':
783  case 'background-color':
784  $styleColor = $this->getStyleColor($styleValue);
785 
786  if (!$styleColor) {
787  continue 2;
788  }
789 
790  $cellStyle->applyFromArray(['fill' => ['fillType' => Fill::FILL_SOLID, 'color' => ['rgb' => $styleColor]]]);
791 
792  break;
793  case 'color':
794  $styleColor = $this->getStyleColor($styleValue);
795 
796  if (!$styleColor) {
797  continue 2;
798  }
799 
800  $cellStyle->applyFromArray(['font' => ['color' => ['rgb' => $styleColor]]]);
801 
802  break;
803 
804  case 'border':
805  $this->setBorderStyle($cellStyle, $styleValue, 'allBorders');
806 
807  break;
808 
809  case 'border-top':
810  $this->setBorderStyle($cellStyle, $styleValue, 'top');
811 
812  break;
813 
814  case 'border-bottom':
815  $this->setBorderStyle($cellStyle, $styleValue, 'bottom');
816 
817  break;
818 
819  case 'border-left':
820  $this->setBorderStyle($cellStyle, $styleValue, 'left');
821 
822  break;
823 
824  case 'border-right':
825  $this->setBorderStyle($cellStyle, $styleValue, 'right');
826 
827  break;
828 
829  case 'font-size':
830  $cellStyle->getFont()->setSize(
831  (float) $styleValue
832  );
833 
834  break;
835 
836  case 'font-weight':
837  if ($styleValue === 'bold' || $styleValue >= 500) {
838  $cellStyle->getFont()->setBold(true);
839  }
840 
841  break;
842 
843  case 'font-style':
844  if ($styleValue === 'italic') {
845  $cellStyle->getFont()->setItalic(true);
846  }
847 
848  break;
849 
850  case 'font-family':
851  $cellStyle->getFont()->setName(str_replace('\'', '', $styleValue));
852 
853  break;
854 
855  case 'text-decoration':
856  switch ($styleValue) {
857  case 'underline':
858  $cellStyle->getFont()->setUnderline(Font::UNDERLINE_SINGLE);
859 
860  break;
861  case 'line-through':
862  $cellStyle->getFont()->setStrikethrough(true);
863 
864  break;
865  }
866 
867  break;
868 
869  case 'text-align':
870  $cellStyle->getAlignment()->setHorizontal($styleValue);
871 
872  break;
873 
874  case 'vertical-align':
875  $cellStyle->getAlignment()->setVertical($styleValue);
876 
877  break;
878 
879  case 'width':
880  $sheet->getColumnDimension($column)->setWidth(
881  (float) str_replace(['px', 'pt'], '', $styleValue)
882  );
883 
884  break;
885 
886  case 'height':
887  $sheet->getRowDimension($row)->setRowHeight(
888  (float) str_replace(['px', 'pt'], '', $styleValue)
889  );
890 
891  break;
892 
893  case 'word-wrap':
894  $cellStyle->getAlignment()->setWrapText(
895  $styleValue === 'break-word'
896  );
897 
898  break;
899 
900  case 'text-indent':
901  $cellStyle->getAlignment()->setIndent(
902  (int) str_replace(['px'], '', $styleValue)
903  );
904 
905  break;
906  }
907  }
908  }
getStyleColor($value)
Check if has #, so we can get clean hex.
Definition: Html.php:915
setBorderStyle(Style $cellStyle, $styleValue, $type)
Definition: Html.php:1006
$row
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canRead()

PhpOffice\PhpSpreadsheet\Reader\Html::canRead (   $pFilename)

Validate that the current file is an HTML file.

Parameters
string$pFilename
Returns
bool

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 143 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\BaseReader\openFile(), PhpOffice\PhpSpreadsheet\Reader\Html\readBeginning(), and PhpOffice\PhpSpreadsheet\Reader\Html\readEnding().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\loadIntoExisting().

144  {
145  // Check if file exists
146  try {
147  $this->openFile($pFilename);
148  } catch (Exception $e) {
149  return false;
150  }
151 
152  $beginning = $this->readBeginning();
153  $startWithTag = self::startsWithTag($beginning);
154  $containsTags = self::containsTags($beginning);
155  $endsWithTag = self::endsWithTag($this->readEnding());
156 
157  fclose($this->fileHandle);
158 
159  return $startWithTag && $containsTags && $endsWithTag;
160  }
openFile($pFilename)
Open file for reading.
Definition: BaseReader.php:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ containsTags()

static PhpOffice\PhpSpreadsheet\Reader\Html::containsTags (   $data)
staticprivate

Definition at line 199 of file Html.php.

References $data.

200  {
201  return strlen($data) !== strlen(strip_tags($data));
202  }
$data
Definition: bench.php:6

◆ endsWithTag()

static PhpOffice\PhpSpreadsheet\Reader\Html::endsWithTag (   $data)
staticprivate

Definition at line 194 of file Html.php.

References $data.

195  {
196  return '>' === substr(trim($data), -1, 1);
197  }
$data
Definition: bench.php:6

◆ flushCell()

PhpOffice\PhpSpreadsheet\Reader\Html::flushCell ( Worksheet  $sheet,
  $column,
  $row,
$cellContent 
)
protected

Definition at line 282 of file Html.php.

References $row, and PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setCellValue().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBr(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementH1Etc(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementHr(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementLi(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTable(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

282  : void
283  {
284  if (is_string($cellContent)) {
285  // Simple String content
286  if (trim($cellContent) > '') {
287  // Only actually write it if there's content in the string
288  // Write to worksheet to be done here...
289  // ... we return the cell so we can mess about with styles more easily
290  $sheet->setCellValue($column . $row, $cellContent);
291  $this->dataArray[$row][$column] = $cellContent;
292  }
293  } else {
294  // We have a Rich Text run
295  // TODO
296  $this->dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent;
297  }
298  $cellContent = (string) '';
299  }
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBorderMappings()

static static PhpOffice\PhpSpreadsheet\Reader\Html::getBorderMappings ( )
static

Definition at line 985 of file Html.php.

985  : array
986  {
987  return self::$borderMappings;
988  }

◆ getBorderStyle()

PhpOffice\PhpSpreadsheet\Reader\Html::getBorderStyle (   $style)

Map html border style to PhpSpreadsheet border style.

Parameters
string$style
Returns
null|string

Definition at line 997 of file Html.php.

References $style.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\setBorderStyle().

998  {
999  return (array_key_exists($style, self::$borderMappings)) ? self::$borderMappings[$style] : null;
1000  }
$style
Definition: example_012.php:70
+ Here is the caller graph for this function:

◆ getInputEncoding()

PhpOffice\PhpSpreadsheet\Reader\Html::getInputEncoding ( )

Get input encoding.

Returns
string
Deprecated:
no use is made of this property

Definition at line 247 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\$inputEncoding.

248  {
249  return $this->inputEncoding;
250  }

◆ getSheetIndex()

PhpOffice\PhpSpreadsheet\Reader\Html::getSheetIndex ( )

Get sheet index.

Returns
int

Definition at line 709 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\$sheetIndex.

710  {
711  return $this->sheetIndex;
712  }

◆ getStyleColor()

PhpOffice\PhpSpreadsheet\Reader\Html::getStyleColor (   $value)

Check if has #, so we can get clean hex.

Returns
null|string

Definition at line 915 of file Html.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\applyInlineStyle(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBgcolor(), and PhpOffice\PhpSpreadsheet\Reader\Html\setBorderStyle().

916  {
917  if (strpos($value, '#') === 0) {
918  return substr($value, 1);
919  }
920 
921  return \PhpOffice\PhpSpreadsheet\Helper\Html::colourNameLookup((string) $value);
922  }
+ Here is the caller graph for this function:

◆ getTableStartColumn()

PhpOffice\PhpSpreadsheet\Reader\Html::getTableStartColumn ( )
protected

Definition at line 270 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\$tableLevel.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTr().

271  {
272  return $this->nestedColumn[$this->tableLevel];
273  }
+ Here is the caller graph for this function:

◆ insertImage()

PhpOffice\PhpSpreadsheet\Reader\Html::insertImage ( Worksheet  $sheet,
  $column,
  $row,
array  $attributes 
)
private
Parameters
string$column
int$row

Definition at line 928 of file Html.php.

References $name, $row, PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getColumnDimension(), and PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getRowDimension().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementImg().

928  : void
929  {
930  if (!isset($attributes['src'])) {
931  return;
932  }
933 
934  $src = urldecode($attributes['src']);
935  $width = isset($attributes['width']) ? (float) $attributes['width'] : null;
936  $height = isset($attributes['height']) ? (float) $attributes['height'] : null;
937  $name = $attributes['alt'] ?? null;
938 
939  $drawing = new Drawing();
940  $drawing->setPath($src);
941  $drawing->setWorksheet($sheet);
942  $drawing->setCoordinates($column . $row);
943  $drawing->setOffsetX(0);
944  $drawing->setOffsetY(10);
945  $drawing->setResizeProportional(true);
946 
947  if ($name) {
948  $drawing->setName($name);
949  }
950 
951  if ($width) {
952  $drawing->setWidth((int) $width);
953  }
954 
955  if ($height) {
956  $drawing->setHeight((int) $height);
957  }
958 
959  $sheet->getColumnDimension($column)->setWidth(
960  $drawing->getWidth() / 6
961  );
962 
963  $sheet->getRowDimension($row)->setRowHeight(
964  $drawing->getHeight() * 0.9
965  );
966  }
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

PhpOffice\PhpSpreadsheet\Reader\Html::load (   $pFilename)

Loads Spreadsheet from file.

Parameters
string$pFilename
Returns
Spreadsheet

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 211 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\loadIntoExisting().

212  {
213  // Create new Spreadsheet
214  $spreadsheet = new Spreadsheet();
215 
216  // Load into this instance
217  return $this->loadIntoExisting($pFilename, $spreadsheet);
218  }
loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
Definition: Html.php:637
+ Here is the call graph for this function:

◆ loadDocument()

PhpOffice\PhpSpreadsheet\Reader\Html::loadDocument ( DOMDocument  $document,
Spreadsheet  $spreadsheet 
)
private

Loads PhpSpreadsheet from DOMDocument into PhpSpreadsheet instance.

Definition at line 684 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Reader\Html\$sheetIndex, PhpOffice\PhpSpreadsheet\Spreadsheet\createSheet(), PhpOffice\PhpSpreadsheet\Spreadsheet\getActiveSheet(), PhpOffice\PhpSpreadsheet\Spreadsheet\getSheetCount(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Spreadsheet\setActiveSheetIndex().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\loadFromString(), and PhpOffice\PhpSpreadsheet\Reader\Html\loadIntoExisting().

684  : Spreadsheet
685  {
686  while ($spreadsheet->getSheetCount() <= $this->sheetIndex) {
687  $spreadsheet->createSheet();
688  }
689  $spreadsheet->setActiveSheetIndex($this->sheetIndex);
690 
691  // Discard white space
692  $document->preserveWhiteSpace = false;
693 
694  $row = 0;
695  $column = 'A';
696  $content = '';
697  $this->rowspan = [];
698  $this->processDomElement($document, $spreadsheet->getActiveSheet(), $row, $column, $content);
699 
700  // Return
701  return $spreadsheet;
702  }
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFromString()

PhpOffice\PhpSpreadsheet\Reader\Html::loadFromString (   $content,
?Spreadsheet  $spreadsheet = null 
)

Spreadsheet from content.

Parameters
string$content

Definition at line 664 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\loadDocument().

664  : Spreadsheet
665  {
666  // Create a new DOM object
667  $dom = new DOMDocument();
668  // Reload the HTML file into the DOM object
669  try {
670  $loaded = $dom->loadHTML(mb_convert_encoding($this->securityScanner->scan($content), 'HTML-ENTITIES', 'UTF-8'));
671  } catch (Throwable $e) {
672  $loaded = false;
673  }
674  if ($loaded === false) {
675  throw new Exception('Failed to load content as a DOM Document', 0, $e ?? null);
676  }
677 
678  return $this->loadDocument($dom, $spreadsheet ?? new Spreadsheet());
679  }
loadDocument(DOMDocument $document, Spreadsheet $spreadsheet)
Loads PhpSpreadsheet from DOMDocument into PhpSpreadsheet instance.
Definition: Html.php:684
+ Here is the call graph for this function:

◆ loadIntoExisting()

PhpOffice\PhpSpreadsheet\Reader\Html::loadIntoExisting (   $pFilename,
Spreadsheet  $spreadsheet 
)

Loads PhpSpreadsheet from file into PhpSpreadsheet instance.

Parameters
string$pFilename
Returns
Spreadsheet

Definition at line 637 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\canRead(), and PhpOffice\PhpSpreadsheet\Reader\Html\loadDocument().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\load().

638  {
639  // Validate
640  if (!$this->canRead($pFilename)) {
641  throw new Exception($pFilename . ' is an Invalid HTML file.');
642  }
643 
644  // Create a new DOM object
645  $dom = new DOMDocument();
646  // Reload the HTML file into the DOM object
647  try {
648  $loaded = $dom->loadHTML(mb_convert_encoding($this->securityScanner->scanFile($pFilename), 'HTML-ENTITIES', 'UTF-8'));
649  } catch (Throwable $e) {
650  $loaded = false;
651  }
652  if ($loaded === false) {
653  throw new Exception('Failed to load ' . $pFilename . ' as a DOM Document', 0, $e ?? null);
654  }
655 
656  return $this->loadDocument($dom, $spreadsheet);
657  }
loadDocument(DOMDocument $document, Spreadsheet $spreadsheet)
Loads PhpSpreadsheet from DOMDocument into PhpSpreadsheet instance.
Definition: Html.php:684
canRead($pFilename)
Validate that the current file is an HTML file.
Definition: Html.php:143
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElement()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElement ( DOMNode  $element,
Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent 
)
protected

Definition at line 613 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBody().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\loadDocument(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementA(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBody(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementH1Etc(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementLi(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementSpanEtc(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTable(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTdOther(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTitle(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTr().

613  : void
614  {
615  foreach ($element->childNodes as $child) {
616  if ($child instanceof DOMText) {
617  $domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue));
618  if (is_string($cellContent)) {
619  // simply append the text if the cell content is a plain text string
620  $cellContent .= $domText;
621  }
622  // but if we have a rich text run instead, we need to append it correctly
623  // TODO
624  } elseif ($child instanceof DOMElement) {
625  $this->processDomElementBody($sheet, $row, $column, $cellContent, $child);
626  }
627  }
628  }
processDomElementBody(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child)
Definition: Html.php:301
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementA()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementA ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 381 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getHyperlink(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementH1Etc().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBr().

381  : void
382  {
383  if ($child->nodeName === 'a') {
384  foreach ($attributeArray as $attributeName => $attributeValue) {
385  switch ($attributeName) {
386  case 'href':
387  $sheet->getCell($column . $row)->getHyperlink()->setUrl($attributeValue);
388  if (isset($this->formats[$child->nodeName])) {
389  $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
390  }
391 
392  break;
393  case 'class':
394  if ($attributeValue === 'comment-indicator') {
395  break; // Ignore - it's just a red square.
396  }
397  }
398  }
399  // no idea why this should be needed
400  //$cellContent .= ' ';
401  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
402  } else {
403  $this->processDomElementH1Etc($sheet, $row, $column, $cellContent, $child, $attributeArray);
404  }
405  }
processDomElementH1Etc(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:409
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementAlign()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementAlign ( Worksheet  $sheet,
int  $row,
string  $column,
array  $attributeArray 
)
private

Definition at line 541 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

541  : void
542  {
543  if (isset($attributeArray['align'])) {
544  $sheet->getStyle($column . $row)->getAlignment()->setHorizontal($attributeArray['align']);
545  }
546  }
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementBgcolor()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementBgcolor ( Worksheet  $sheet,
int  $row,
string  $column,
array  $attributeArray 
)
private

Definition at line 513 of file Html.php.

References PhpOffice\PhpSpreadsheet\Style\Fill\FILL_SOLID, PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle(), and PhpOffice\PhpSpreadsheet\Reader\Html\getStyleColor().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

513  : void
514  {
515  if (isset($attributeArray['bgcolor'])) {
516  $sheet->getStyle("$column$row")->applyFromArray(
517  [
518  'fill' => [
519  'fillType' => Fill::FILL_SOLID,
520  'color' => ['rgb' => $this->getStyleColor($attributeArray['bgcolor'])],
521  ],
522  ]
523  );
524  }
525  }
getStyleColor($value)
Check if has #, so we can get clean hex.
Definition: Html.php:915
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementBody()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementBody ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child 
)
private

Definition at line 301 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTitle().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement().

301  : void
302  {
303  $attributeArray = [];
304  foreach ($child->attributes as $attribute) {
305  $attributeArray[$attribute->name] = $attribute->value;
306  }
307 
308  if ($child->nodeName === 'body') {
309  $row = 1;
310  $column = 'A';
311  $cellContent = '';
312  $this->tableLevel = 0;
313  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
314  } else {
315  $this->processDomElementTitle($sheet, $row, $column, $cellContent, $child, $attributeArray);
316  }
317  }
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
processDomElementTitle(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:319
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementBr()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementBr ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 364 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Reader\Html\flushCell(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementA().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementHr().

364  : void
365  {
366  if ($child->nodeName === 'br' || $child->nodeName === 'hr') {
367  if ($this->tableLevel > 0) {
368  // If we're inside a table, replace with a \n and set the cell to wrap
369  $cellContent .= "\n";
370  $sheet->getStyle($column . $row)->getAlignment()->setWrapText(true);
371  } else {
372  // Otherwise flush our existing content and move the row cursor on
373  $this->flushCell($sheet, $column, $row, $cellContent);
374  ++$row;
375  }
376  } else {
377  $this->processDomElementA($sheet, $row, $column, $cellContent, $child, $attributeArray);
378  }
379  }
flushCell(Worksheet $sheet, $column, $row, &$cellContent)
Definition: Html.php:282
processDomElementA(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:381
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementDataFormat()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementDataFormat ( Worksheet  $sheet,
int  $row,
string  $column,
array  $attributeArray 
)
private

Definition at line 555 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

555  : void
556  {
557  if (isset($attributeArray['data-format'])) {
558  $sheet->getStyle($column . $row)->getNumberFormat()->setFormatCode($attributeArray['data-format']);
559  }
560  }
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementH1Etc()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementH1Etc ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 409 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Reader\Html\flushCell(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementLi().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementA().

409  : void
410  {
411  if (in_array($child->nodeName, self::$h1Etc)) {
412  if ($this->tableLevel > 0) {
413  // If we're inside a table, replace with a \n
414  $cellContent .= $cellContent ? "\n" : '';
415  $sheet->getStyle($column . $row)->getAlignment()->setWrapText(true);
416  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
417  } else {
418  if ($cellContent > '') {
419  $this->flushCell($sheet, $column, $row, $cellContent);
420  ++$row;
421  }
422  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
423  $this->flushCell($sheet, $column, $row, $cellContent);
424 
425  if (isset($this->formats[$child->nodeName])) {
426  $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
427  }
428 
429  ++$row;
430  $column = 'A';
431  }
432  } else {
433  $this->processDomElementLi($sheet, $row, $column, $cellContent, $child, $attributeArray);
434  }
435  }
processDomElementLi(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:437
flushCell(Worksheet $sheet, $column, $row, &$cellContent)
Definition: Html.php:282
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementHeight()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementHeight ( Worksheet  $sheet,
int  $row,
array  $attributeArray 
)
private

Definition at line 534 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getRowDimension().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

534  : void
535  {
536  if (isset($attributeArray['height'])) {
537  $sheet->getRowDimension($row)->setRowHeight($attributeArray['height']);
538  }
539  }
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementHr()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementHr ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 350 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Reader\Html\flushCell(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBr().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementSpanEtc().

350  : void
351  {
352  if ($child->nodeName === 'hr') {
353  $this->flushCell($sheet, $column, $row, $cellContent);
354  ++$row;
355  if (isset($this->formats[$child->nodeName])) {
356  $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
357  }
358  ++$row;
359  }
360  // fall through to br
361  $this->processDomElementBr($sheet, $row, $column, $cellContent, $child, $attributeArray);
362  }
flushCell(Worksheet $sheet, $column, $row, &$cellContent)
Definition: Html.php:282
processDomElementBr(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:364
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementImg()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementImg ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 458 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\insertImage(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTable().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementLi().

458  : void
459  {
460  if ($child->nodeName === 'img') {
461  $this->insertImage($sheet, $column, $row, $attributeArray);
462  } else {
463  $this->processDomElementTable($sheet, $row, $column, $cellContent, $child, $attributeArray);
464  }
465  }
processDomElementTable(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:467
insertImage(Worksheet $sheet, $column, $row, array $attributes)
Definition: Html.php:928
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementLi()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementLi ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 437 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Reader\Html\flushCell(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementImg().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementH1Etc().

437  : void
438  {
439  if ($child->nodeName === 'li') {
440  if ($this->tableLevel > 0) {
441  // If we're inside a table, replace with a \n
442  $cellContent .= $cellContent ? "\n" : '';
443  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
444  } else {
445  if ($cellContent > '') {
446  $this->flushCell($sheet, $column, $row, $cellContent);
447  }
448  ++$row;
449  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
450  $this->flushCell($sheet, $column, $row, $cellContent);
451  $column = 'A';
452  }
453  } else {
454  $this->processDomElementImg($sheet, $row, $column, $cellContent, $child, $attributeArray);
455  }
456  }
flushCell(Worksheet $sheet, $column, $row, &$cellContent)
Definition: Html.php:282
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
processDomElementImg(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:458
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementSpanEtc()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementSpanEtc ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 332 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getComment(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementHr().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTitle().

332  : void
333  {
334  if (in_array($child->nodeName, self::$spanEtc)) {
335  if (isset($attributeArray['class']) && $attributeArray['class'] === 'comment') {
336  $sheet->getComment($column . $row)
337  ->getText()
338  ->createTextRun($child->textContent);
339  }
340  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
341 
342  if (isset($this->formats[$child->nodeName])) {
343  $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
344  }
345  } else {
346  $this->processDomElementHr($sheet, $row, $column, $cellContent, $child, $attributeArray);
347  }
348  }
processDomElementHr(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:350
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementTable()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementTable ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 467 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Reader\Html\flushCell(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTr(), PhpOffice\PhpSpreadsheet\Reader\Html\releaseTableStartColumn(), and PhpOffice\PhpSpreadsheet\Reader\Html\setTableStartColumn().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementImg().

467  : void
468  {
469  if ($child->nodeName === 'table') {
470  $this->flushCell($sheet, $column, $row, $cellContent);
471  $column = $this->setTableStartColumn($column);
472  if ($this->tableLevel > 1 && $row > 1) {
473  --$row;
474  }
475  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
476  $column = $this->releaseTableStartColumn();
477  if ($this->tableLevel > 1) {
478  ++$column;
479  } else {
480  ++$row;
481  }
482  } else {
483  $this->processDomElementTr($sheet, $row, $column, $cellContent, $child, $attributeArray);
484  }
485  }
processDomElementTr(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:487
flushCell(Worksheet $sheet, $column, $row, &$cellContent)
Definition: Html.php:282
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementThTd()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementThTd ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 562 of file Html.php.

References $i, PhpOffice\PhpSpreadsheet\Reader\Html\applyInlineStyle(), PhpOffice\PhpSpreadsheet\Cell\Coordinate\extractAllCellReferencesInRange(), PhpOffice\PhpSpreadsheet\Reader\Html\flushCell(), PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\mergeCells(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementAlign(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBgcolor(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementDataFormat(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementHeight(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementVAlign(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementWidth().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTdOther().

562  : void
563  {
564  while (isset($this->rowspan[$column . $row])) {
565  ++$column;
566  }
567  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
568 
569  // apply inline style
570  $this->applyInlineStyle($sheet, $row, $column, $attributeArray);
571 
572  $this->flushCell($sheet, $column, $row, $cellContent);
573 
574  $this->processDomElementBgcolor($sheet, $row, $column, $attributeArray);
575  $this->processDomElementWidth($sheet, $column, $attributeArray);
576  $this->processDomElementHeight($sheet, $row, $attributeArray);
577  $this->processDomElementAlign($sheet, $row, $column, $attributeArray);
578  $this->processDomElementVAlign($sheet, $row, $column, $attributeArray);
579  $this->processDomElementDataFormat($sheet, $row, $column, $attributeArray);
580 
581  if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) {
582  //create merging rowspan and colspan
583  $columnTo = $column;
584  for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
585  ++$columnTo;
586  }
587  $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1);
588  foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
589  $this->rowspan[$value] = true;
590  }
591  $sheet->mergeCells($range);
592  $column = $columnTo;
593  } elseif (isset($attributeArray['rowspan'])) {
594  //create merging rowspan
595  $range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1);
596  foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
597  $this->rowspan[$value] = true;
598  }
599  $sheet->mergeCells($range);
600  } elseif (isset($attributeArray['colspan'])) {
601  //create merging colspan
602  $columnTo = $column;
603  for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
604  ++$columnTo;
605  }
606  $sheet->mergeCells($column . $row . ':' . $columnTo . $row);
607  $column = $columnTo;
608  }
609 
610  ++$column;
611  }
processDomElementBgcolor(Worksheet $sheet, int $row, string $column, array $attributeArray)
Definition: Html.php:513
flushCell(Worksheet $sheet, $column, $row, &$cellContent)
Definition: Html.php:282
processDomElementHeight(Worksheet $sheet, int $row, array $attributeArray)
Definition: Html.php:534
applyInlineStyle(&$sheet, $row, $column, $attributeArray)
Apply inline css inline style.
Definition: Html.php:743
processDomElementVAlign(Worksheet $sheet, int $row, string $column, array $attributeArray)
Definition: Html.php:548
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
processDomElementWidth(Worksheet $sheet, string $column, array $attributeArray)
Definition: Html.php:527
$row
$i
Definition: disco.tpl.php:19
static extractAllCellReferencesInRange($cellRange)
Extract all cell references in range, which may be comprised of multiple cell ranges.
Definition: Coordinate.php:338
processDomElementAlign(Worksheet $sheet, int $row, string $column, array $attributeArray)
Definition: Html.php:541
processDomElementDataFormat(Worksheet $sheet, int $row, string $column, array $attributeArray)
Definition: Html.php:555
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementThTdOther()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementThTdOther ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 504 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTr().

504  : void
505  {
506  if ($child->nodeName !== 'td' && $child->nodeName !== 'th') {
507  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
508  } else {
509  $this->processDomElementThTd($sheet, $row, $column, $cellContent, $child, $attributeArray);
510  }
511  }
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
processDomElementThTd(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:562
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementTitle()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementTitle ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 319 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementSpanEtc(), and PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\setTitle().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementBody().

319  : void
320  {
321  if ($child->nodeName === 'title') {
322  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
323  $sheet->setTitle($cellContent, true, true);
324  $cellContent = '';
325  } else {
326  $this->processDomElementSpanEtc($sheet, $row, $column, $cellContent, $child, $attributeArray);
327  }
328  }
processDomElementSpanEtc(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:332
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementTr()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementTr ( Worksheet  $sheet,
int &  $row,
string &  $column,
string &  $cellContent,
DOMElement  $child,
array &  $attributeArray 
)
private

Definition at line 487 of file Html.php.

References $row, PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getRowDimension(), PhpOffice\PhpSpreadsheet\Reader\Html\getTableStartColumn(), PhpOffice\PhpSpreadsheet\Reader\Html\processDomElement(), and PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTdOther().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTable().

487  : void
488  {
489  if ($child->nodeName === 'tr') {
490  $column = $this->getTableStartColumn();
491  $cellContent = '';
492  $this->processDomElement($child, $sheet, $row, $column, $cellContent);
493 
494  if (isset($attributeArray['height'])) {
495  $sheet->getRowDimension($row)->setRowHeight($attributeArray['height']);
496  }
497 
498  ++$row;
499  } else {
500  $this->processDomElementThTdOther($sheet, $row, $column, $cellContent, $child, $attributeArray);
501  }
502  }
processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent)
Definition: Html.php:613
$row
processDomElementThTdOther(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray)
Definition: Html.php:504
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementVAlign()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementVAlign ( Worksheet  $sheet,
int  $row,
string  $column,
array  $attributeArray 
)
private

Definition at line 548 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getStyle().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

548  : void
549  {
550  if (isset($attributeArray['valign'])) {
551  $sheet->getStyle($column . $row)->getAlignment()->setVertical($attributeArray['valign']);
552  }
553  }
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processDomElementWidth()

PhpOffice\PhpSpreadsheet\Reader\Html::processDomElementWidth ( Worksheet  $sheet,
string  $column,
array  $attributeArray 
)
private

Definition at line 527 of file Html.php.

References PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\getColumnDimension().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementThTd().

527  : void
528  {
529  if (isset($attributeArray['width'])) {
530  $sheet->getColumnDimension($column)->setWidth($attributeArray['width']);
531  }
532  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readBeginning()

PhpOffice\PhpSpreadsheet\Reader\Html::readBeginning ( )
private

Definition at line 162 of file Html.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\canRead().

163  {
164  fseek($this->fileHandle, 0);
165 
166  return fread($this->fileHandle, self::TEST_SAMPLE_SIZE);
167  }
+ Here is the caller graph for this function:

◆ readEnding()

PhpOffice\PhpSpreadsheet\Reader\Html::readEnding ( )
private

Definition at line 169 of file Html.php.

References $filename, and $size.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\canRead().

170  {
171  $meta = stream_get_meta_data($this->fileHandle);
172  $filename = $meta['uri'];
173 
174  $size = filesize($filename);
175  if ($size === 0) {
176  return '';
177  }
178 
179  $blockSize = self::TEST_SAMPLE_SIZE;
180  if ($size < $blockSize) {
181  $blockSize = $size;
182  }
183 
184  fseek($this->fileHandle, $size - $blockSize);
185 
186  return fread($this->fileHandle, $blockSize);
187  }
$size
Definition: RandomTest.php:84
$filename
Definition: buildRTE.php:89
+ Here is the caller graph for this function:

◆ releaseTableStartColumn()

PhpOffice\PhpSpreadsheet\Reader\Html::releaseTableStartColumn ( )
protected

Definition at line 275 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\$tableLevel.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTable().

276  {
278 
279  return array_pop($this->nestedColumn);
280  }
+ Here is the caller graph for this function:

◆ setBorderStyle()

PhpOffice\PhpSpreadsheet\Reader\Html::setBorderStyle ( Style  $cellStyle,
  $styleValue,
  $type 
)
private
Parameters
string$styleValue
string$type

Definition at line 1006 of file Html.php.

References $type, PhpOffice\PhpSpreadsheet\Style\Border\BORDER_NONE, PhpOffice\PhpSpreadsheet\Reader\Html\getBorderStyle(), and PhpOffice\PhpSpreadsheet\Reader\Html\getStyleColor().

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\applyInlineStyle().

1006  : void
1007  {
1008  if (trim($styleValue) === Border::BORDER_NONE) {
1009  $borderStyle = Border::BORDER_NONE;
1010  $color = null;
1011  } else {
1012  $borderArray = explode(' ', $styleValue);
1013  $borderCount = count($borderArray);
1014  if ($borderCount >= 3) {
1015  $borderStyle = $borderArray[1];
1016  $color = $borderArray[2];
1017  } else {
1018  $borderStyle = $borderArray[0];
1019  $color = $borderArray[1] ?? null;
1020  }
1021  }
1022 
1023  $cellStyle->applyFromArray([
1024  'borders' => [
1025  $type => [
1026  'borderStyle' => $this->getBorderStyle($borderStyle),
1027  'color' => ['rgb' => $this->getStyleColor($color)],
1028  ],
1029  ],
1030  ]);
1031  }
getStyleColor($value)
Check if has #, so we can get clean hex.
Definition: Html.php:915
$type
getBorderStyle($style)
Map html border style to PhpSpreadsheet border style.
Definition: Html.php:997
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setInputEncoding()

PhpOffice\PhpSpreadsheet\Reader\Html::setInputEncoding (   $pValue)

Set input encoding.

Parameters
string$pValueInput encoding, eg: 'ANSI'
Returns
$this
Deprecated:
no use is made of this property

Definition at line 231 of file Html.php.

232  {
233  $this->inputEncoding = $pValue;
234 
235  return $this;
236  }

◆ setSheetIndex()

PhpOffice\PhpSpreadsheet\Reader\Html::setSheetIndex (   $pValue)

Set sheet index.

Parameters
int$pValueSheet index
Returns
$this

Definition at line 721 of file Html.php.

722  {
723  $this->sheetIndex = $pValue;
724 
725  return $this;
726  }

◆ setTableStartColumn()

PhpOffice\PhpSpreadsheet\Reader\Html::setTableStartColumn (   $column)
protected

Definition at line 259 of file Html.php.

References PhpOffice\PhpSpreadsheet\Reader\Html\$tableLevel.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\processDomElementTable().

260  {
261  if ($this->tableLevel == 0) {
262  $column = 'A';
263  }
265  $this->nestedColumn[$this->tableLevel] = $column;
266 
267  return $this->nestedColumn[$this->tableLevel];
268  }
+ Here is the caller graph for this function:

◆ startsWithTag()

static PhpOffice\PhpSpreadsheet\Reader\Html::startsWithTag (   $data)
staticprivate

Definition at line 189 of file Html.php.

References $data.

190  {
191  return '<' === substr(trim($data), 0, 1);
192  }
$data
Definition: bench.php:6

Field Documentation

◆ $borderMappings

PhpOffice\PhpSpreadsheet\Reader\Html::$borderMappings
staticprivate
Initial value:
= [
'dash-dot' => Border::BORDER_DASHDOT

Definition at line 968 of file Html.php.

◆ $dataArray

PhpOffice\PhpSpreadsheet\Reader\Html::$dataArray = []
protected

Definition at line 253 of file Html.php.

◆ $formats

PhpOffice\PhpSpreadsheet\Reader\Html::$formats
protected
Initial value:
= [
'h1' => [
'font' => [
'bold' => true

Definition at line 48 of file Html.php.

◆ $h1Etc

PhpOffice\PhpSpreadsheet\Reader\Html::$h1Etc = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'p']
staticprivate

Definition at line 407 of file Html.php.

◆ $inputEncoding

PhpOffice\PhpSpreadsheet\Reader\Html::$inputEncoding = 'ANSI'
protected

Definition at line 34 of file Html.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Html\getInputEncoding().

◆ $nestedColumn

PhpOffice\PhpSpreadsheet\Reader\Html::$nestedColumn = ['A']
protected

Definition at line 257 of file Html.php.

◆ $rowspan

PhpOffice\PhpSpreadsheet\Reader\Html::$rowspan = []
protected

Definition at line 125 of file Html.php.

◆ $sheetIndex

PhpOffice\PhpSpreadsheet\Reader\Html::$sheetIndex = 0
protected

◆ $spanEtc

PhpOffice\PhpSpreadsheet\Reader\Html::$spanEtc = ['span', 'div', 'font', 'i', 'em', 'strong', 'b']
staticprivate

Definition at line 330 of file Html.php.

◆ $tableLevel

◆ TEST_SAMPLE_SIZE

const PhpOffice\PhpSpreadsheet\Reader\Html::TEST_SAMPLE_SIZE = 2048

Sample size to read to determine if it's HTML or not.

Definition at line 27 of file Html.php.


The documentation for this class was generated from the following file: