Can't set font size and rtl









up vote
8
down vote

favorite












Using docx, I am trying to define for a run multiple attributes.
When I set color, rtl, it works fine.
But when I add also font size, it is ignored.
If I set only font size, it works fine.



This works fine (font color changes and run is right-to-left):



run = p.add_run(line)
font = run.font
font.rtl = True
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)


This also works fine (font size is modified):



run = p.add_run(line)
font = run.font
font.size = Pt(8)
#font.rtl = True # commented out


But this does not change the font's size:



run = p.add_run(line)
font = run.font
font.size = Pt(8)
font.rtl = True


I tried different order of the commands, but nothing works.










share|improve this question























  • And if you do font.rtl = True before you change the size?
    – Torxed
    Nov 11 at 8:41










  • tried to reorder the command - same result
    – OritK
    Nov 11 at 8:55














up vote
8
down vote

favorite












Using docx, I am trying to define for a run multiple attributes.
When I set color, rtl, it works fine.
But when I add also font size, it is ignored.
If I set only font size, it works fine.



This works fine (font color changes and run is right-to-left):



run = p.add_run(line)
font = run.font
font.rtl = True
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)


This also works fine (font size is modified):



run = p.add_run(line)
font = run.font
font.size = Pt(8)
#font.rtl = True # commented out


But this does not change the font's size:



run = p.add_run(line)
font = run.font
font.size = Pt(8)
font.rtl = True


I tried different order of the commands, but nothing works.










share|improve this question























  • And if you do font.rtl = True before you change the size?
    – Torxed
    Nov 11 at 8:41










  • tried to reorder the command - same result
    – OritK
    Nov 11 at 8:55












up vote
8
down vote

favorite









up vote
8
down vote

favorite











Using docx, I am trying to define for a run multiple attributes.
When I set color, rtl, it works fine.
But when I add also font size, it is ignored.
If I set only font size, it works fine.



This works fine (font color changes and run is right-to-left):



run = p.add_run(line)
font = run.font
font.rtl = True
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)


This also works fine (font size is modified):



run = p.add_run(line)
font = run.font
font.size = Pt(8)
#font.rtl = True # commented out


But this does not change the font's size:



run = p.add_run(line)
font = run.font
font.size = Pt(8)
font.rtl = True


I tried different order of the commands, but nothing works.










share|improve this question















Using docx, I am trying to define for a run multiple attributes.
When I set color, rtl, it works fine.
But when I add also font size, it is ignored.
If I set only font size, it works fine.



This works fine (font color changes and run is right-to-left):



run = p.add_run(line)
font = run.font
font.rtl = True
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)


This also works fine (font size is modified):



run = p.add_run(line)
font = run.font
font.size = Pt(8)
#font.rtl = True # commented out


But this does not change the font's size:



run = p.add_run(line)
font = run.font
font.size = Pt(8)
font.rtl = True


I tried different order of the commands, but nothing works.







python docx right-to-left






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 19:19

























asked Nov 11 at 8:25









OritK

1681113




1681113











  • And if you do font.rtl = True before you change the size?
    – Torxed
    Nov 11 at 8:41










  • tried to reorder the command - same result
    – OritK
    Nov 11 at 8:55
















  • And if you do font.rtl = True before you change the size?
    – Torxed
    Nov 11 at 8:41










  • tried to reorder the command - same result
    – OritK
    Nov 11 at 8:55















And if you do font.rtl = True before you change the size?
– Torxed
Nov 11 at 8:41




And if you do font.rtl = True before you change the size?
– Torxed
Nov 11 at 8:41












tried to reorder the command - same result
– OritK
Nov 11 at 8:55




tried to reorder the command - same result
– OritK
Nov 11 at 8:55












2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










ok, found it!
It turns out that in word, the font size for such a case has to include complex script instructions. It means that you have to add



<w:szCs w:val="???"/> 


instead (or in addition to) the normal



<w:sz w:val="??"/> 


I had to add a new attribute to the font in the docx library and it now works fine. The change is in 3 docs files:



text/font.py
oxml/__init.py__
oxml/text/font.py


and the usage in my view:



run = p.add_run(line)
font = run.font
#font.size = Pt(8) This line is redundant - but you can leave it
font.cs_size = Pt(8)
font.rtl = True


Added a fork to docx library. In https://github.com/Oritk/python-docx






share|improve this answer





























    up vote
    0
    down vote













    accepted
    I haven't gotten around to playing with docx yet (I've mostly used Excel python modules), but based on the documentation here it's looking like you're modifying the wrong property of style. The Font property, per this definition of the rtl property, would only modify an added run (via myparagraph.add_run("Hello World", style = "rtl")).As far as I can tell, the code you're looking for is:



    missingwords = Document()
    style = missingwords.styles.add_style('rtl', WD_STYLE_TYPE.PARAGRAPH)
    style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT


    And then you can go ahead and add the paragraph like you were



    paragraph = missingwords.add_paragraph("Hello world",style='rtl')


    Again, just going off the documentation, so let me know if that works






    share|improve this answer




















    • Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
      – OritK
      Nov 11 at 8:52











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247010%2fcant-set-font-size-and-rtl%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    ok, found it!
    It turns out that in word, the font size for such a case has to include complex script instructions. It means that you have to add



    <w:szCs w:val="???"/> 


    instead (or in addition to) the normal



    <w:sz w:val="??"/> 


    I had to add a new attribute to the font in the docx library and it now works fine. The change is in 3 docs files:



    text/font.py
    oxml/__init.py__
    oxml/text/font.py


    and the usage in my view:



    run = p.add_run(line)
    font = run.font
    #font.size = Pt(8) This line is redundant - but you can leave it
    font.cs_size = Pt(8)
    font.rtl = True


    Added a fork to docx library. In https://github.com/Oritk/python-docx






    share|improve this answer


























      up vote
      3
      down vote



      accepted










      ok, found it!
      It turns out that in word, the font size for such a case has to include complex script instructions. It means that you have to add



      <w:szCs w:val="???"/> 


      instead (or in addition to) the normal



      <w:sz w:val="??"/> 


      I had to add a new attribute to the font in the docx library and it now works fine. The change is in 3 docs files:



      text/font.py
      oxml/__init.py__
      oxml/text/font.py


      and the usage in my view:



      run = p.add_run(line)
      font = run.font
      #font.size = Pt(8) This line is redundant - but you can leave it
      font.cs_size = Pt(8)
      font.rtl = True


      Added a fork to docx library. In https://github.com/Oritk/python-docx






      share|improve this answer
























        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        ok, found it!
        It turns out that in word, the font size for such a case has to include complex script instructions. It means that you have to add



        <w:szCs w:val="???"/> 


        instead (or in addition to) the normal



        <w:sz w:val="??"/> 


        I had to add a new attribute to the font in the docx library and it now works fine. The change is in 3 docs files:



        text/font.py
        oxml/__init.py__
        oxml/text/font.py


        and the usage in my view:



        run = p.add_run(line)
        font = run.font
        #font.size = Pt(8) This line is redundant - but you can leave it
        font.cs_size = Pt(8)
        font.rtl = True


        Added a fork to docx library. In https://github.com/Oritk/python-docx






        share|improve this answer














        ok, found it!
        It turns out that in word, the font size for such a case has to include complex script instructions. It means that you have to add



        <w:szCs w:val="???"/> 


        instead (or in addition to) the normal



        <w:sz w:val="??"/> 


        I had to add a new attribute to the font in the docx library and it now works fine. The change is in 3 docs files:



        text/font.py
        oxml/__init.py__
        oxml/text/font.py


        and the usage in my view:



        run = p.add_run(line)
        font = run.font
        #font.size = Pt(8) This line is redundant - but you can leave it
        font.cs_size = Pt(8)
        font.rtl = True


        Added a fork to docx library. In https://github.com/Oritk/python-docx







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 at 11:13

























        answered Nov 16 at 10:57









        OritK

        1681113




        1681113






















            up vote
            0
            down vote













            accepted
            I haven't gotten around to playing with docx yet (I've mostly used Excel python modules), but based on the documentation here it's looking like you're modifying the wrong property of style. The Font property, per this definition of the rtl property, would only modify an added run (via myparagraph.add_run("Hello World", style = "rtl")).As far as I can tell, the code you're looking for is:



            missingwords = Document()
            style = missingwords.styles.add_style('rtl', WD_STYLE_TYPE.PARAGRAPH)
            style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT


            And then you can go ahead and add the paragraph like you were



            paragraph = missingwords.add_paragraph("Hello world",style='rtl')


            Again, just going off the documentation, so let me know if that works






            share|improve this answer




















            • Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
              – OritK
              Nov 11 at 8:52















            up vote
            0
            down vote













            accepted
            I haven't gotten around to playing with docx yet (I've mostly used Excel python modules), but based on the documentation here it's looking like you're modifying the wrong property of style. The Font property, per this definition of the rtl property, would only modify an added run (via myparagraph.add_run("Hello World", style = "rtl")).As far as I can tell, the code you're looking for is:



            missingwords = Document()
            style = missingwords.styles.add_style('rtl', WD_STYLE_TYPE.PARAGRAPH)
            style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT


            And then you can go ahead and add the paragraph like you were



            paragraph = missingwords.add_paragraph("Hello world",style='rtl')


            Again, just going off the documentation, so let me know if that works






            share|improve this answer




















            • Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
              – OritK
              Nov 11 at 8:52













            up vote
            0
            down vote










            up vote
            0
            down vote









            accepted
            I haven't gotten around to playing with docx yet (I've mostly used Excel python modules), but based on the documentation here it's looking like you're modifying the wrong property of style. The Font property, per this definition of the rtl property, would only modify an added run (via myparagraph.add_run("Hello World", style = "rtl")).As far as I can tell, the code you're looking for is:



            missingwords = Document()
            style = missingwords.styles.add_style('rtl', WD_STYLE_TYPE.PARAGRAPH)
            style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT


            And then you can go ahead and add the paragraph like you were



            paragraph = missingwords.add_paragraph("Hello world",style='rtl')


            Again, just going off the documentation, so let me know if that works






            share|improve this answer












            accepted
            I haven't gotten around to playing with docx yet (I've mostly used Excel python modules), but based on the documentation here it's looking like you're modifying the wrong property of style. The Font property, per this definition of the rtl property, would only modify an added run (via myparagraph.add_run("Hello World", style = "rtl")).As far as I can tell, the code you're looking for is:



            missingwords = Document()
            style = missingwords.styles.add_style('rtl', WD_STYLE_TYPE.PARAGRAPH)
            style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT


            And then you can go ahead and add the paragraph like you were



            paragraph = missingwords.add_paragraph("Hello world",style='rtl')


            Again, just going off the documentation, so let me know if that works







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 at 8:41









            omair issa

            14




            14











            • Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
              – OritK
              Nov 11 at 8:52

















            • Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
              – OritK
              Nov 11 at 8:52
















            Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
            – OritK
            Nov 11 at 8:52





            Thanks - but i tried this before and this does not work... 1) alignment is not the same as direction - it does not show the sentence correctly 2) i want to change the size for some words, not the whole paragraph, which is why i do not use style 3) font.rtl is a valid option, as far as i know - it works and i also see it in python-docx.readthedocs.io/en/latest/_modules/docx/text/… (and in few answers here in stackoverflow)
            – OritK
            Nov 11 at 8:52


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247010%2fcant-set-font-size-and-rtl%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands