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

文本框中缺少表格元素(Missing Table element in Textbox) #2349

Closed
zxf5115 opened this issue Dec 5, 2022 · 2 comments
Closed

Comments

@zxf5115
Copy link

zxf5115 commented Dec 5, 2022

Describe the Bug

在word2007格式(docx)读取文件时,如果内容在文本框中的表格中,我无法获取到它们。

T10.docx

Steps to Reproduce

<?php
$objReader= IOFactory::createReader('Word2007');
$phpWord = $objReader->load($path);

$write = new HTML($phpWord);
$write->getContent();

Expected Behavior

可以将textbox中表格的内容读取出来。

<!DOCTYPE html><html><head><meta charset="UTF-8" /><title></title></head><body><p></p><p><table><tr><td colspan="4"><p>电源回路参数(Supply circuit)</p></td></tr><tr><td><p>容量(Power)</p></td><td colspan="2"><p>MVA</p></td><td><p>104</p></td></tr><tr><td><p>频率(Frequency)</p></td><td colspan="2"><p>Hz</p></td><td><p>50</p></td></tr><tr><td colspan="3"><p>相数(Phase)</p></td><td><p>3</p></td></tr><tr><td colspan="2"><p>电压(Voltage)</p></td><td><p>kV</p></td><td><p>12</p></td></tr><tr><td colspan="2"><p>电流(Current)</p></td><td><p>kA</p></td><td><p>5</p></td></tr><tr><td colspan="2"><p>阻抗(Impedance)</p></td><td><p>Ω</p></td><td><p>1.39</p></td></tr><tr><td colspan="3"><p>功率因数(Power factor)</p></td><td><p>&lt;0.15</p></td></tr><tr><td colspan="3"><p>中性点(Neutral)</p></td><td><p>接地(earthed)</p></td></tr></table></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p></body></html>

Current Behavior

无法读取到textbox中表格内容。

<!DOCTYPE html><html><head><meta charset="UTF-8" /><title></title></head><body><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p></body></html>

Context

  • PHP Version: 7.3
  • PHPWord Version: 0.18.3
@zxf5115
Copy link
Author

zxf5115 commented Dec 5, 2022

我根据 #2183 老哥提供方案进行了修改。

在 phpoffice\phpword\src\PhpWord\Reader\Word2007\AbstractPart.php 文件的第249行添加

// 文本框中表格丢失找回
$textbox = $xmlReader->getElement('v:shape/v:textbox', $node);
if (null !== $textbox) {
    $textboxLength = $xmlReader->getElements('w:txbxContent/w:tbl', $textbox);
    if (null !== $textboxLength) {
        foreach ($textboxLength as $item) {
            $this->readTable($xmlReader, $item, $parent, $docPart);
        }
    }
} else {
// Image

在 phpoffice\phpword\src\PhpWord\Element\AbstractContainer.php 文件的第243行,数组中添加(TextRun)

'Table'         => array('Section', 'Header', 'Footer', 'Cell', 'TextBox' , 'TextRun'),

@zxf5115 zxf5115 closed this as completed Dec 5, 2022
@zxf5115
Copy link
Author

zxf5115 commented Dec 5, 2022

thanks! #2183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant