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

Reset Numbering in Multilevel Lists In /PHPWord/TemplateProcessor cloneBlock #2436

Open
ayDavidGitHere opened this issue Aug 10, 2023 · 2 comments

Comments

@ayDavidGitHere
Copy link

I'm using the PHPWord library to clone a block containing a multilevel numbered list in a DOCX document. However, I've noticed that the numbering inner levels in the cloned block continues from the original block, which is not the behavior I'm looking for. I'd like to reset the numbering in lists inside the new block.

Steps to Reproduce:

Clone a block containing a multilevel numbered list using the cloneBlock method.
Observe that the numbering in the cloned block continues from the original block.
Expected Behavior:
I would like to reset the numbering in the lists inside the cloned block so that they start from the beginning (e.g., 1, 2, 3...).

Current Implementation:

function cloneBlockInDocx($docx_path) {
    // Load the Word document
    $phpword = new \PhpOffice\PhpWord\PhpWord();
    $template = $phpword->loadTemplate( $docx_path );

    $template->cloneBlock('Container-block', 2, true, true); //block contains lists
    
    
    // Save the modified document
    $new_docx_path = str_ireplace( ".docx", "_cloned.docx", $docx_path);
    $template->saveAs($new_docx_path);
    
    return $new_docx_path;
}

Sample Docx Result

BLOCK
1. Item 1
   a) Subitem 1a
   b) Subitem 1b
2. Item 2
   a) Subitem 2a

BLOCK
1. Item 1
   c) Subitem 1a
   d) Subitem 1b
2. Item 2
   b) Subitem 2a

BLOCK
1. Item 1
   e) Subitem 1a
   f) Subitem 1b
2. Item 2
   c) Subitem 2a

Desired Solution:
I'm looking for guidance on how to reset the numbering in the inner lists inside the cloned block so that they start from the beginning. Any suggestions or code examples would be greatly appreciated.

BLOCK
1. Item 1
   a) Subitem 1a
   b) Subitem 1b
2. Item 2
   a) Subitem 2a

BLOCK
1. Item 1
   a) Subitem 1a
   b) Subitem 1b
2. Item 2
   a) Subitem 2a

BLOCK
1. Item 1
   a) Subitem 1a
   b) Subitem 1b
2. Item 2
   a) Subitem 2a

@xinjiawei
Copy link

I'm also working on a solution to this problem. Do you have some idea now?

@ayDavidGitHere
Copy link
Author

I concluded there is no /PHPWord way to do it, I implemented a custom and rough solution. I unfortunately don't have that code available at this moment.

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

2 participants