Forum


Replies: 3   Views: 1872
Get contents (with info of style)
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 IHD  · 24-01-2019 - 13:49

Hi, 

Presume there is a document like: 

 

Intro body text.

1. Heading 1
1.1 Sub-heading
    This is body text.
1.2 Another sub-heading
    This is another body text, followed by:
    (A) an item
    (b) another item

I would like to get the content in way enabling me to determine if a certain text is a heading, sub-heading, body text, list-item etc. 

(Using the Indexer, I have only managed to get a long string of all text using $output['body']['text']...)

Thanks!

Posted by admin  · 24-01-2019 - 14:41

Hello,

There's no way to accomplish that task using the current release of phpdocx. The next version will include new methods and options to get styles and query contents by styles; there's no release date yet for the next release.

Regards.

Posted by IHD  · 24-01-2019 - 16:23

Hi!

I think i might manage to implement a solution using transformDocAdvHTML and then try to figure out the content's style by the classname. 

On a separate but similar note: Is there any way to include an attribute for a peice of text (inserted with addText or embedHTML), which may later be "retrieved" by transformDocAdvHTML?

For example:

$text = '<customTag hiddenvalue="10">15</customTag>';
// and then 
$docx->embedHTML($text);
// or
$docx->addText($text);

I was trying to follow the implementation of embedHTML to see if I could make a custom WordML such as <w:customTag hiddenvalue="10">... but I do not see the big picture in this fix.

 

Posted by admin  · 25-01-2019 - 08:28

Hello,

Adding custom tags or attributes to a DOCX will return a corrupted DOCX. The best approach to accomplish that task is getting DOCX contents using getDocxPathQueryInfo and query the style file. A heading content has always a w:outlineLvl tag in the w:pPr tag in the document content or in the style file.

The next release of phpdocx will include a new method to query styles.

Regards.