Skip to content

Commit 35fffcc

Browse files
Added Delete Table function
Below Function will add the delete Table function in template Processor which will help to remove the table from Word File can be usefu for condition based approach and dynamic behaviour of Word DOC
1 parent feadceb commit 35fffcc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/PhpWord/TemplateProcessor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,4 +1499,25 @@ public function getTempDocumentFilename(): string
14991499
{
15001500
return $this->tempDocumentFilename;
15011501
}
1502+
1503+
/**
1504+
* Delete Table
1505+
*
1506+
* Below function will take $search Parameter as an Input and remove Respective table from format
1507+
*
1508+
* @param string $search
1509+
* return void
1510+
*/
1511+
public function deleteTable(string $search): void
1512+
{
1513+
$search = self::ensureMacroCompleted($search);
1514+
$tagPos = strpos($this->tempDocumentMainPart, $search);
1515+
if ($tagPos) {
1516+
$tableStart = $this->findTableStart($tagPos);
1517+
$tableEnd = $this->findTableEnd($tagPos);
1518+
1519+
// Delete the entire table
1520+
$this->tempDocumentMainPart = $this->getSlice(0, $tableStart) . $this->getSlice($tableEnd);
1521+
}
1522+
}
15021523
}

0 commit comments

Comments
 (0)