Forum


Replies: 4   Views: 1465
How to delete row to table, to get variable in document
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by dev-info  · 07-07-2021 - 12:26

Hello, I would like to delete a complete row from a spreadsheet that contains a variable.
Example:

variable : $test$ (in second columns to third row), i would like delete third row.

 

Can you help me?

Thank you

I have prenium licences

 

Posted by admin  · 07-07-2021 - 14:17

Hello,

You can use the removeWordContent method available in DOCXPath to remove contents in a DOCX document. We recommend you to check the samples included in the package (examples/DocxPath/removeWordContent folder), that illustrates how to use this method; sample_9.php illustrates how to remove a row in a table.

Regards.

Posted by dev-info  · 07-07-2021 - 14:22

Thank you for your reply.
In the example (sample_9), the line is already indicated,.

$referenceNode = array(

    'customQuery' => '//w:tbl/w:tr[2]',

);$docx->removeWordContent($referenceNode);

 

How to retrieve the row number of the correct table when looking for the variable. I can't find any documentation on this subject
Thank you

Posted by admin  · 07-07-2021 - 14:57

Hello,

The customQuery option allows using a custom XPath query (https://www.w3schools.com/xml/xpath_intro.asp). If you know a text content available in a table row you can use the contains function available in XPath, instead of setting the position. For example, using a DOCX document included in the package, you can remove the row that includes 24 running:

$referenceNode = array(
    'customQuery' => '//w:tbl/w:tr[contains(.,"24")]',
);

$docx->removeWordContent($referenceNode);

You can also get DOCXPath query information using the following method: getDocxPathQueryInfo. DOCXPath and XPath includes many options to choose the contents to be changed, updated, removed, cloned, inserted...

Please note that XPath has some protected characters that you may need to escape if you want to query by a text with protected characters.

If you open a support ticket (https://www.phpdocx.com/support) attaching the DOCX you want to modify, the dev team will generate a custom code using your template.

Regards.

Posted by dev-info  · 09-07-2021 - 06:58

Hello, Thank you to your answer, it's perfect!

Have a great day :)