예제 #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());
 }
예제 #2
0
파일: AElement.php 프로젝트: ymnl007/Clerk
 /**
  * @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);
 }
예제 #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());
 }
예제 #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());
 }
예제 #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());
 }
예제 #6
0
 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());
 }
예제 #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);
         }
     }
 }
예제 #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());
     });
 }
예제 #9
0
파일: TrElement.php 프로젝트: ymnl007/Clerk
 /**
  * @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);
 }
예제 #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());
 }
예제 #11
0
 public function test_append_content_by_node()
 {
     $node = new \DOMElement('name', 'value');
     $this->table->appendContentByNode($node);
     $this->assertEquals('value', $this->table->getContent());
 }
예제 #12
0
 /**
  * @param DOMAttr        $attribute
  * @param ReferenceTable $table
  *
  * @return mixed
  */
 public function parse(DOMAttr $attribute, ReferenceTable &$table)
 {
     $this->sheet->setColumnWidth($table->getColumn(), $attribute->value);
 }
예제 #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);
     });
 }
예제 #14
0
파일: Element.php 프로젝트: ymnl007/Clerk
 /**
  * @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('');
 }
예제 #15
0
 /**
  * @param DOMAttr        $attribute
  * @param ReferenceTable $table
  *
  * @return mixed
  */
 public function parse(DOMAttr $attribute, ReferenceTable &$table)
 {
     $this->sheet->setRowHeight($table->getRow(), $attribute->value);
 }