Exemple #1
0
 public function test_table_gets_parsed()
 {
     $dom = new \DOMElement('table', '');
     $table = new ReferenceTable();
     $sheet = $this->mockSheet();
     $this->assertEquals(0, $table->getRow());
     $element = new TableElement($sheet);
     $element->parse($dom, $table);
     $this->assertEquals(1, $table->getRow());
 }
Exemple #2
0
 /**
  * @param DOMNode        $node
  * @param ReferenceTable $table
  *
  * @return mixed|void
  */
 public function parse(DOMNode $node, ReferenceTable &$table)
 {
     $this->sheet->getCell($table->getCoordinate())->getHyperlink()->setUrl($node->getAttribute('href'));
     // Underline and make it blue
     $this->sheet->cell($table->getCoordinate(), function ($cell) {
         $cell->font()->underline()->color('0000ff');
     });
     // Add whitespace
     $table->appendContent(' ');
     $this->next($node, $table);
 }
Exemple #3
0
 public function test_tr_element_gets_parsed()
 {
     $dom = new \DOMElement('tr', '');
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     $sheet = $this->mockSheet();
     $this->assertEquals(0, $table->getRow());
     $element = new TrElement($sheet);
     $element->parse($dom, $table);
     $this->assertEquals(1, $table->getRow());
 }
Exemple #4
0
 public function test_if_align_attribute_gets_translated_to_aligned_cells()
 {
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $node = new \DOMAttr('align', 'center');
     $sheet = $this->mockSheet();
     $attribute = new AlignAttribute($sheet);
     $attribute->parse($node, $table);
     $this->assertContains('center', $sheet->cell($table->getCoordinate())->align()->getHorizontal());
 }
Exemple #5
0
 public function test_if_style_attribute()
 {
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $node = new \DOMAttr('style', 'text-align:center;');
     $sheet = $this->mockSheet();
     $attribute = new StyleAttribute($sheet);
     $attribute->parse($node, $table);
     $this->assertContains('center', $sheet->cell($table->getCoordinate())->align()->getHorizontal());
 }
 public function test_if_rowspan_attribute_gets_translated_to_a_merged_rows()
 {
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $node = new \DOMAttr('rowspan', 3);
     $sheet = $this->mockSheet();
     $attribute = new RowspanAttribute($sheet);
     $attribute->parse($node, $table);
     // 3 rows in the first column
     $this->assertContains('A1:A3', $sheet->getMergeCells());
 }
Exemple #7
0
 /**
  * @param DOMAttr        $attribute
  * @param ReferenceTable $table
  *
  * @return mixed
  */
 public function parse(DOMAttr $attribute, ReferenceTable &$table)
 {
     // Get all inline styles separately
     $styles = explode($this->styleSeparator, $attribute->value);
     foreach ($styles as $style) {
         $style = explode($this->valueSeperator, $style);
         $name = trim(reset($style));
         $value = trim(end($style));
         // When the parser exists, parse the style
         if ($name && $value && ($parser = StyleParserFactory::create($name, $this->sheet))) {
             $cell = $this->sheet->cell($table->getCoordinate());
             $parser->parse($cell, $value, $table);
         }
     }
 }
Exemple #8
0
 public function test_a_element_gets_parsed()
 {
     $doc = new DOMDocument();
     $dom = $doc->createElement('a');
     $dom->setAttribute('href', 'http://google.com');
     $sheet = $this->mockSheet();
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $element = new AElement($sheet);
     $element->parse($dom, $table);
     $this->assertEquals('http://google.com', $sheet->getCell($table->getCoordinate())->getHyperlink()->getUrl());
     // Text color should be blue
     $sheet->cell($table->getCoordinate(), function ($cell) {
         $this->assertEquals('0000ff', $cell->font()->getColor());
     });
 }
Exemple #9
0
 /**
  * @param DOMNode        $node
  * @param ReferenceTable $table
  *
  * @return mixed|void
  */
 public function parse(DOMNode $node, ReferenceTable &$table)
 {
     // Tr adds a new row
     $table->nextRow();
     $table->setColumn($table->getStartColumn());
     $table->resetContent();
     // Next element
     $this->next($node, $table);
 }
Exemple #10
0
 public function test_td_element_gets_parsed()
 {
     $dom = new \DOMElement('td', 'Patrick');
     $table = new ReferenceTable();
     // Fake as if we are inside a <table>
     $table->setColumn($table->setStartColumn());
     // Fake as if we are inside a <tr>
     $table->nextRow();
     $this->assertEquals('A', $table->getColumn());
     $sheet = $this->mockSheet();
     $element = new TdElement($sheet);
     $element->parse($dom, $table);
     // Flush the element
     $element->flush($table);
     $this->assertEquals('B', $table->getColumn());
 }
Exemple #11
0
 public function test_append_content_by_node()
 {
     $node = new \DOMElement('name', 'value');
     $this->table->appendContentByNode($node);
     $this->assertEquals('value', $this->table->getContent());
 }
Exemple #12
0
 /**
  * @param DOMAttr        $attribute
  * @param ReferenceTable $table
  *
  * @return mixed
  */
 public function parse(DOMAttr $attribute, ReferenceTable &$table)
 {
     $this->sheet->setColumnWidth($table->getColumn(), $attribute->value);
 }
Exemple #13
0
 /**
  * @param DOMAttr        $attribute
  * @param ReferenceTable $table
  *
  * @return mixed
  */
 public function parse(DOMAttr $attribute, ReferenceTable &$table)
 {
     $this->sheet->cell($table->getCoordinate(), function (Cell $cell) use($attribute) {
         $cell->align($attribute->value);
     });
 }
Exemple #14
0
 /**
  * @param ReferenceTable $table
  */
 public function flush(ReferenceTable &$table)
 {
     if (is_string($table->getContent())) {
         if (trim($table->getContent()) > '') {
             $this->sheet->cell($table->getColumn() . $table->getRow(), $table->getContent());
             $table->rememberData($table->getContent());
         }
     } else {
         $table->rememberData('RICH TEXT: ' . $table->getContent());
     }
     $table->setContent('');
 }
Exemple #15
0
 /**
  * @param DOMAttr        $attribute
  * @param ReferenceTable $table
  *
  * @return mixed
  */
 public function parse(DOMAttr $attribute, ReferenceTable &$table)
 {
     $this->sheet->setRowHeight($table->getRow(), $attribute->value);
 }