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

Word2007 Style Reader not using styleId #1785

Open
begnini opened this issue Dec 20, 2019 · 1 comment
Open

Word2007 Style Reader not using styleId #1785

begnini opened this issue Dec 20, 2019 · 1 comment

Comments

@begnini
Copy link
Contributor

begnini commented Dec 20, 2019

Describe the Bug

Sometimes, Word refers to his style by id, not by name. I believe this happens when the style name has accents in it.

Steps to Reproduce

Style Snippet (from styles.xml)

<w:style w:styleId="Nfaseforte" w:type="character">
        <w:name w:val="Enfase forte"/>
        <w:qFormat/>
        <w:rPr>
            <w:b/>
            <w:bCs/>
        </w:rPr>
</w:style>

paragraph snippet (from document.xml)

<w:p>
    <w:pPr>
        <w:pStyle w:val="Corpodotexto"/>
        <w:bidi w:val="0"/>
        <w:jc w:val="center"/>
        <w:rPr/>
    </w:pPr>
    <w:r>
        <w:rPr>
            <w:rStyle w:val="Nfaseforte"/>
            <w:sz w:val="28"/>
        </w:rPr>
        <w:t>Lore ipsun</w:t>
        <w:br/>
        <w:t>Lore ipsun</w:t>
    </w:r>
</w:p>
            

Expected Behavior

We expect the method PhpOffice\PhpWord\Style::getStyle($styleName) return a FontStyle when passing Nfaseforte referenced by the TextRun.

Current Behavior

Actually, Style::getStyle('Nfaseforte') is returning null (no style found) when called.

Context

Looking at the PhpOffice\PhpWord\Reader\Word2007\Styles class, in the master branch, we have the lib using the style name and, only if the name is empty, using the style id. Below the code:

https://github.com/PHPOffice/PHPWord/blob/733f845f8f93dbc4e1be5d565420aa9244626919/src/PhpWord/Reader/Word2007/Styles.php#L67:L69

I believe we should use the name and the id referencing the same style. If you are ok with this, I can create a PR.

  • PHP Version: 7.2.10
  • PHPWord Version: develop
begnini added a commit to begnini/PHPWord that referenced this issue Dec 26, 2019
begnini added a commit to begnini/PHPWord that referenced this issue Dec 26, 2019
begnini added a commit to begnini/PHPWord that referenced this issue Dec 26, 2019
begnini added a commit to begnini/PHPWord that referenced this issue Jan 17, 2020
Use style id to link styles with document elements (fixes PHPOffice#1785)
@hrst
Copy link

hrst commented Jan 10, 2023

It would be very helpful if PhpWord also reads the styleId. Using

$objReader = IOFactory::createReader('Word2007');
$phpWord = $objReader->load('filename.docx');
var_dump(Style::getStyles());

it seems that the styleId value is not read by PhpWord, and as a result cannot be used to set the style by using

$textRun->setParagraphStyle('styleId');

Any update for this would be awesome as it would allow to first read the style IDs and then use them for e.g. paragraphs.

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

Successfully merging a pull request may close this issue.

2 participants