PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.27k stars 2.7k forks source link

Table cell merge #2263

Open almazihan opened 2 years ago

almazihan commented 2 years ago

Hello author, forgive my poor English, I am a Chinese. 😁

When there are cells merge, getVMerge() has no 'continue' status and cannot get the all merged cells. I fixed this problem myself in a simple way.

PhpOffice\PhpWord\Reader\Word2007\AbstractPart.php Line:663

<?php
  /**
   * Read style definition
   *
   * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
   * @param \DOMElement $parentNode
   * @param array $styleDefs
   * @ignoreScrutinizerPatch
   * @return array
   */
  protected function readStyleDefs(XMLReader $xmlReader, \DOMElement $parentNode = null, $styleDefs = array())
  {
      $styles = array();

      foreach ($styleDefs as $styleProp => $styleVal) {
          list($method, $element, $attribute, $expected) = array_pad($styleVal, 4, null);

          $element = $this->findPossibleElement($xmlReader, $parentNode, $element);
          if ($element === null) {
              continue;
          }

          if ($xmlReader->elementExists($element, $parentNode)) {
              $node = $xmlReader->getElement($element, $parentNode);

              $attribute = $this->findPossibleAttribute($xmlReader, $node, $attribute);

              // Use w:val as default if no attribute assigned
              $attribute = ($attribute === null) ? 'w:val' : $attribute;
              $attributeValue = $xmlReader->getAttribute($attribute, $node);

              $styleValue = $this->readStyleDef($method, $attributeValue, $expected);

              // ========= I add fix code here =========
              if ($element == 'w:vMerge' && $styleValue !== 'restart') {
                  $styleValue = 'continue';
              }
              // ===============================

              if ($styleValue !== null) {
                  $styles[$styleProp] = $styleValue;
              }
          }
      }

      return $styles;
  }
github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.