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

replaceBlock didn't work in office 2016 #1202

Open
sunchenweb opened this issue Nov 21, 2017 · 2 comments
Open

replaceBlock didn't work in office 2016 #1202

sunchenweb opened this issue Nov 21, 2017 · 2 comments

Comments

@sunchenweb
Copy link

the funciton replaceBlock in Temproccessor didn't work,debug info below:

the regex is this:
(<\?xml.*)(<w:p.*>\${block_table}<\/w:.*?p>)(.*)(<w:p.*\${\/block_table}<\/w:.*?p>)
and the document.xml like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n

<w:document
    xmlns:wpc="https://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
    xmlns:cx="https://schemas.microsoft.com/office/drawing/2014/chartex"
    xmlns:cx1="https://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
    xmlns:cx2="https://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
    xmlns:cx3="https://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
    xmlns:cx4="https://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
    xmlns:cx5="https://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
    xmlns:cx6="https://schemas.microsoft.com/office/drawing/2016/5/12/chartex"
    xmlns:cx7="https://schemas.microsoft.com/office/drawing/2016/5/13/chartex"
    xmlns:cx8="https://schemas.microsoft.com/office/drawing/2016/5/14/chartex"
    xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:aink="https://schemas.microsoft.com/office/drawing/2016/ink"
    xmlns:am3d="https://schemas.microsoft.com/office/drawing/2017/model3d"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships"
    xmlns:m="https://schemas.openxmlformats.org/officeDocument/2006/math"
    xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:wp14="https://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
    xmlns:wp="https://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
    xmlns:w10="urn:schemas-microsoft-com:office:word"
    xmlns:w="https://schemas.openxmlformats.org/wordprocessingml/2006/main"
    xmlns:w14="https://schemas.microsoft.com/office/word/2010/wordml"
    xmlns:w15="https://schemas.microsoft.com/office/word/2012/wordml"
    xmlns:w16cid="https://schemas.microsoft.com/office/word/2016/wordml/cid"
    xmlns:w16se="https://schemas.microsoft.com/office/word/2015/wordml/symex"
    xmlns:wpg="https://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
    xmlns:wpi="https://schemas.microsoft.com/office/word/2010/wordprocessingInk"
    xmlns:wne="https://schemas.microsoft.com/office/word/2006/wordml"
    xmlns:wps="https://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">
    <w:background w:color="FFFFFF"/>
    <w:body>
        <w:p w:rsidR="00922228" w:rsidRDefault="00922228" w:rsidP="00922228">
            <w:pPr>
                <w:jc w:val="center"/>
                <w:rPr>
                    <w:sz w:val="44"/>
                    <w:szCs w:val="44"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:hint="eastAsia"/>
                    <w:sz w:val="44"/>
                    <w:szCs w:val="44"/>
                </w:rPr>
                <w:t>月</w:t>
            </w:r>
            <w:r w:rsidRPr="00B540A2">
                <w:rPr>
                    <w:rFonts w:hint="eastAsia"/>
                    <w:sz w:val="44"/>
                    <w:szCs w:val="44"/>
                </w:rPr>
                <w:t>度总结报告</w:t>
            </w:r>
        </w:p>
        <w:p w:rsidR="00197886" w:rsidRDefault="00197886" w:rsidP="00197886">
            <w:r>
                <w:t>${block_table}</w:t>
            </w:r>
        </w:p>
        <w:p w:rsidR="00197886" w:rsidRDefault="00197886" w:rsidP="00197886">
            <w:r>
                <w:t>${/block_table}</w:t>
            </w:r>
        </w:p>
        <w:sectPr w:rsidR="00C571E7" w:rsidRPr="00C571E7" w:rsidSect="00BD69D6">
            <w:headerReference w:type="default" r:id="rId7"/>
            <w:footerReference w:type="default" r:id="rId8"/>
            <w:pgSz w:w="11906" w:h="16838" w:code="9"/>
            <w:pgMar w:top="1440" w:right="1021" w:bottom="1440" w:left="1418" w:header="851" w:footer="992" w:gutter="0"/>
            <w:cols w:space="720"/>
            <w:titlePg/>
            <w:docGrid w:linePitch="312"/>
        </w:sectPr>
    </w:body>
</w:document>

how to fix it

@nicoder
Copy link
Contributor

nicoder commented Feb 2, 2018

there is nothing inside your block (except whitespace)?

(between the two block_table placeholders)

is the xml you give the document before calling replaceBlock? or after?

when you say it did not work, do you mean that nothing changed in the document?

@liborm85
Copy link
Contributor

liborm85 commented Jan 3, 2021

replaceBlock method is broken. I use this simple modification:

  public function replaceBlock($blockname, $replacement) {
    $this->tempDocumentMainPart = preg_replace(
      '/(\${' . $blockname . '})(.*?)(\${\/' . $blockname . '})/is',
      $replacement,
      $this->tempDocumentMainPart
    );
  }

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

No branches or pull requests

3 participants