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

Variable number of lists in TemplateProcessor #1393

Open
rkorebrits opened this issue May 31, 2018 · 3 comments
Open

Variable number of lists in TemplateProcessor #1393

rkorebrits opened this issue May 31, 2018 · 3 comments

Comments

@rkorebrits
Copy link

rkorebrits commented May 31, 2018

We are using the TemplateProcessor for writing content to documents and use https://github.com/rkorebrits/HTMLtoOpenXML to transform HTML to OOXML, which all works fine overall.

The issue that we are having currently though is with lists. As the content we are populating comes from a CMS, there can be a number of lists in the content and there is an option to use <ul> or <ol>.

Over the last few weeks, I've done quite extensive research on how the numbering works in Word documents and from what I gather, it is not possible to set the type of list from the document.xml. numbering.xml has all of that information in it:

  1. All the types of lists
  2. Every single list in document.xml has its own node, referring to a list type (e.g. <w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num>).

I've got the feeling that it is not really possible in the PHPWord TemplateProcessor, to be able to dictate what type of list is added, by adding XML to the document.xml only, but I'm hoping there might be some trick that I know of?

Also, is it possible at all to write to numbering.xml from the TemplateProcessor? What I otherwise could do is prepare the numbering.xml file, to have 2 styles in it (unordered and ordered) but without a list of actual implementations, and when parsing the HTML, for each list, write a node to numbering.xml to say if its unordered/bullet or ordered/number.

Context

  • PHP version: 7.0/2
  • PHPWord version: custom branch (with cloneBlockString and insertImage), up-to-date with dev-master
@dodeagung
Copy link

Hi @rkorebrits,

Did you get solution for this problem?

since I have same issue.

Best,
Agung

@ThomasBS
Copy link

I know this is an old issue but I just spent SO MUCH time figure out a solution for this. I'm pretty sure my hair turned a little grey. I did find a solution. It's not perfect, but it seems to work.

I'm using the template processor as well and I had a specific requirement that lists should be styled with a specific setup: First level should be dash, second open bullet.

What I did was I added a block in the DOCX template and set up the desired styles for the levels. It looks like this:

image

This will ensure that the proper numbering.xml file is added in the DOCX template.

What you then can do is simply remove this block before saving the new file:

$templateProcessor->cloneBlock('list_block', 0, true, true);

The template processor's deleteBlock() didnt do the trick for me, but the above workaround (clone) did.

Now, all the lists added from <ul><li> etc is correctly styled.

@CISPDEVELOP
Copy link

CISPDEVELOP commented Apr 4, 2024

Hello I am using TemplateProcessor + HTMLtoOpenXML\Parser;
I am looking for a way to prevent Word from continuing the numbering of the lists
That is, if I have multiple ->setValue(${mivar}, $htmlParsed) containing list it respects the numbering of the parsed html
if I have 3 variables with html content and ordered lists, the numbering in Word interprets them as if they were just 1

Expected behavior

  1.Value 1
  2.Value 2
  3.Value 3

  1.Value 1
  2.Value 2
  3.Value 3

Obtained behavior

  * 1.Value 1
  * 2.Value 2
  * 3.Value 3
  *
  * 4.Value 1
  * 5.Value 2
  * 6.Value 3

Thank you

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

4 participants