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

Nesting Sections or reordering Sections after creating them. #534

Open
meetmagdalene opened this issue May 13, 2015 · 2 comments
Open

Nesting Sections or reordering Sections after creating them. #534

meetmagdalene opened this issue May 13, 2015 · 2 comments

Comments

@meetmagdalene
Copy link

meetmagdalene commented May 13, 2015

I am new to using this PHPWord library and I am liking it so far.

If someone could help me figure this out or confirm for me if this is even possible or not I would greatly appreciate it.

It seems as though the sections need to be created in the order which you want them to appear on the page, but I'm looking for a way to re-ordering them, or better yet, even nesting them within one another.

$pSectionPointer = $oPHPWord->addSection();
$pAnotherSectionPointer = $oPHPWord->addSection();
$pFirstSectionPointer = $oPHPWord->addSection();

They appear in the document in the order in which I construct them, which is fine some of the time, but later in my code I may or may not want to change the order of the sections based on some new data in my code. So I want to move the $pFirstSectionPointer to before the $pSectionPointer.

How can I do this?

I've tried setting/changing the elementId and other properties of the sections using setters provided in the API to try and change the order, but there is no explanation for each method and none of them seem to do what I am wanting to do.

Here is my stackoverflow with the same question. I didn't get any responses right away so I thought I would add it here too. Feel free to comment on the stackoverflow instead.

http:https://stackoverflow.com/questions/30223271/nesting-sections-or-reordering-sections-in-phpword


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@ivangretsky
Copy link

Have this question too. My task is to create a custom report. I was thinking to put each report section generation code to a separate class and them add them in a custom order to PHPWord object in the end. Need to let user define the wether each section shall be included in the final report and in which order.

Was planning to create a PhpOffice\PhpWord\Element\Section object for each report section and then append them all to the main object. But it does not seem possible.

Am I missing something? Or is there another way to achieve this?

@troosan
Copy link
Contributor

troosan commented Mar 6, 2018

@ivangretsky with the latest dev-develop version you can sort the sections by passing a callable.
Internally it will use uasort to sort the array

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