getwordcontent not distinguished superscript and subscript.
how can i use getwordcontent for get words from docx and distinguish superscript and subscript?
getwordcontent not distinguished superscript and subscript.
how can i use getwordcontent for get words from docx and distinguish superscript and subscript?
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.
thanks for reply.
so how can i get subscript or superscript using getwordstyles?
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.
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 ) ) ) ) )
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.