Forum


Replies: 6   Views: 566
How can i get superscript and subscript from getwordcontent?
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 phosira  · 20-03-2023 - 08:30

getwordcontent not distinguished superscript and subscript.

how can i use getwordcontent for get words from docx and distinguish superscript and subscript?

Posted by admin  · 20-03-2023 - 10:10

Hello,

Sorry, but we don't understand your question. The getWordContents method returns text contents. Superscript and subscript are MS Word styles, not text contents, so you need to use getWordStyles if you need to query them.

Regards.

Posted by phosira  · 21-03-2023 - 00:44

thanks for reply.

 

so how can i get subscript or superscript using getwordstyles?

Posted by admin  · 21-03-2023 - 06:14

Hello,

getWordStyles returns an array with the styles applied to the content. You need to iterate this array to check if it contains the style (vertAlign):

Subscript and superscript. <vertAlign w:val="superscript"/>.
The single attribute is val. Permitted values are:

baseline - regular vertical positioning
subscript - lowers the text below the baseline and changes it to a small size
superscript - raises the text above the baseline and changes it to a smaller size

We recommend you check the samples included in the package (examples/DocxPath/getWordStyles folder) and the API documentation page (http://www.phpdocx.com/api-documentation/docx-path/get-styles-word-contents-in-docx).

Regards.

Posted by phosira  · 22-03-2023 - 00:40

so i use getwordstyle but i cant find w:vertAlign tag.

 

did i do something wrong?

$docx = new CreateDocxFromTemplate('Test.docx');
$referenceNode = array(
    'type' => 'paragraph',
 
);

$stylecontents = $docx->getWordStyles($referenceNode);

print_r($stylecontents);

 

and get:

 

Array ( [0] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:jc [type] => complete [level] => 2 [attributes] => Array ( [w:val] => center ) ) [2] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [3] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [5] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [2] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:jc [type] => complete [level] => 2 [attributes] => Array ( [w:val] => center ) ) [2] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [3] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:bCs [type] => complete [level] => 3 ) [5] => Array ( [tag] => w:lang [type] => complete [level] => 3 [attributes] => Array ( [w:eastAsia] => ko-KR ) ) [6] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [7] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [3] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [2] => Array ( [tag] => w:lang [type] => complete [level] => 3 [attributes] => Array ( [w:eastAsia] => ko-KR ) ) [3] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [4] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [15] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:jc [type] => complete [level] => 2 [attributes] => Array ( [w:val] => center ) ) [2] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [3] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:bCs [type] => complete [level] => 3 ) [5] => Array ( [tag] => w:lang [type] => complete [level] => 3 [attributes] => Array ( [w:eastAsia] => ko-KR ) ) [6] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [7] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [62] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:jc [type] => complete [level] => 2 [attributes] => Array ( [w:val] => center ) ) [2] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [3] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:bCs [type] => complete [level] => 3 ) [5] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [6] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [63] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [2] => Array ( [tag] => w:rFonts [type] => complete [level] => 3 [attributes] => Array ( [w:cs] => 굴림체 ) ) [3] => Array ( [tag] => w:szCs [type] => complete [level] => 3 [attributes] => Array ( [w:val] => 20 ) ) [4] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [5] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [96] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:jc [type] => complete [level] => 2 [attributes] => Array ( [w:val] => center ) ) [2] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [3] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:bCs [type] => complete [level] => 3 ) [5] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [6] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [575] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [2] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [3] => Array ( [tag] => w:bCs [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [5] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [576] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [2] => Array ( [tag] => w:lang [type] => complete [level] => 3 [attributes] => Array ( [w:eastAsia] => ko-KR ) ) [3] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [4] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) [675] => Array ( [pPr] => Array ( [type] => w:pPr [val] => w:pPr [styles] => Array ( [0] => Array ( [tag] => w:pPr [type] => open [level] => 1 ) [1] => Array ( [tag] => w:jc [type] => complete [level] => 2 [attributes] => Array ( [w:val] => center ) ) [2] => Array ( [tag] => w:rPr [type] => open [level] => 2 ) [3] => Array ( [tag] => w:b [type] => complete [level] => 3 ) [4] => Array ( [tag] => w:rPr [type] => close [level] => 2 ) [5] => Array ( [tag] => w:pPr [type] => close [level] => 1 ) ) ) ) )

 

Posted by admin  · 22-03-2023 - 08:28

Hello

The following line:

$referenceNode = array(
    'type' => 'paragraph',
 
);

$stylecontents = $docx->getWordStyles($referenceNode);

returns the styles applied to the whole paragraph. Maybe the style you want to query is not applied to the whole paragraph but to a run-of-text content in the paragraph.

As detailed on the documentation page:

type      string  * (all, default value), chart, image, default, list, paragraph (also for links and lists), run, style, table, table-row, table-cell or a custom tag.

Maybe you need to query by run type, not paragraph.

Regards.

 

Posted by phosira  · 23-03-2023 - 00:16

Thanks to you, I found the part I was missing.