Get each element using getWordContents.
I do not want to use [contains] to get a table from the wording in the table, but I want to get the contents of a specific table, is there a way?
Get each element using getWordContents.
I do not want to use [contains] to get a table from the wording in the table, but I want to get the contents of a specific table, is there a way?
Hello,
You need to use getWordContents. As you can read on the API page (https://www.phpdocx.com/api-documentation/docx-path/get-text-word-contents-in-docx), you can query by its position, content, attributes or even a custom XPath query. Please check the included samples in the package.
Regards.
thank you for your answer.
Please tell me the specific acquisition method.
I want to get only the contents of the specified table.
The wording in that table is not constant.
Therefore, [contains] can not be used.
If you need to set attributes etc with msword, please let me know.
-<w:tbl>
-<w:tblPr>
<w:tblStyle w:val="TABLECUSTOMSTYLE"/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblInd w:w="0" w:type="dxa"/>
<w:tblLook w:val="04A0" w:noVBand="1" w:noHBand="0" w:lastColumn="0" w:firstColumn="1" w:lastRow="0" w:firstRow="1"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="10763"/>
</w:tblGrid>
-<w:tr w:rsidR="008E34E6" w14:textId="77777777" w14:paraId="57D2E49F" w:rsidTr="008E34E6">
+<w:tc>
</w:tr>
</w:tbl>
I want to get the value of w: tc in wordML above.
I want to determine by table style etc. How should I specifically set [referenceNode]?
Please let me know if there is another good way.
$ref = array(
'type' => 'table',
'attributes' => array("w:val" => "TABLECUSTOMSTYLE"),
);
$now_content = $now_docx->getWordContents($ref);
Hello,
The code you are using to get a reference node by an attribute isn't correct. This sample is included in the package:
$referenceNode = array(
'type' => 'paragraph',
'occurrence' => 1,
'attributes' => array('w:outlineLvl' => array('w:val' => 2)),
);
This reference node returns the first paragraph with a tag w:outlineLvl that include the attribute w:val=2. But it returns the whole paragraph, so if you use a similar code to get a table you get the whole table contents, not only the first cell.
If you get the whole table you can analyze its contents (using PHP DOM methods) using getDocxPathQuery. Using getWordContents you'd need to use a custom query, please check the included samples and the documentation about how to use custom queries.
Regards.