python-docx-template
python-docx-template copied to clipboard
is it possible to control the cell size of template table in docx
hello, you can see the last cell is too long, I want to broaden the last cell? can you give some suggestions? thanks a lot
It can be fixed if I revise the width in the template.
but I find another very worse problem. when combine Chinese and English. I need to set the font and size . in my template, the font is 等线, the size is 11.
no matter how I change the combination of my code, it never made sense. rt.add('BRAF', italic=True, font='等线', size=11) # 产生 斜体 效果 rt.add('基因', font='Arial', size=22)
have you ever meet this, thanks a lot
even do like this, rt.add('BRAF', italic=True) # 产生 斜体 效果 rt.add('\ngene')
the result is not good,can you help me ,thanks a lot
I aslo tried like this rt = RichText('', font='等线') rt.add('BRAF', italic=True, font='等线') # 产生 斜体 效果 rt.add('\ngene', font='等线', size=9)
but in the msword I do not know why it is 4.5, not 9,
I am really heart-broken
when I changed the size to 18, is showed 9 in msword, really amazing.
but richtext add still can not deal Chinese and english well, is there a solution? thanks a lot
Which msword version are you using ?
When you do :
rt.add('BRAF', italic=True) # 产生 斜体 效果 rt.add('\ngene')
if you want italic on 2nd line you must do :
rt.add('BRAF', italic=True) # 产生 斜体 效果 rt.add('\ngene', italic=True)
Otherwise, you will get the paragraph style.
no, I just need the first line italic=True. I am using mac nacos sierra 10.12.6 , msword 2016. set 18 will show 9 in the word, finally ok. but when combine Chinese and english, it never work, the font of Chinese will always be Calibri, really maing me miserable.
thanks a lot
rt.add('BRAF', italic=True, font='等线', size=18) rt.add('\nnot V600E', font='等线', size=18) # 产生 换行 效果
PY2 or PY3 ?
Le mer. 24 juil. 2019 à 10:30, wentgithub [email protected] a écrit :
no, I just need the first line italic=True. I am using mac nacos sierra 10.12.6 , msword 2016. set 18 will show 9 in the word, finally ok. but when combine Chinese and english, it never wrk, the font of Chinese will always be Calibri, really maing me miserable.
thanks a lot
rt.add('BRAF', italic=True, font='等线', size=18) rt.add('\nnot V600E', font='等线', size=18) # 产生 换行 效果
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/elapouya/python-docx-template/issues/218?email_source=notifications&email_token=AAGY33GY2JF6QVKD7TZOWSLQBAHIPA5CNFSM4IGGOVB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2VSXMY#issuecomment-514534323, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGY33C75RQHQFQCPMTLDATQBAHIPANCNFSM4IGGOVBQ .
Python3.7
except for the Richtext can not combine english and chinese well(the chinese will always be Calibri).
here is another big question that I have reported to you. it is about subdoc.
I need to add some subdocs into one doc, maybe 1, 2,3..8. so I need to write 8 variables in my doc,
when I determine to add 3 subdocs, the other 5 variables will be empty string
like such context['mysubdoc_THYRO_{}_tpl'.format(i)] = '',
it is the only the method I can think out**, but it will eave five lines blank,**
is there a more elegant method.

another question it is still the Chinese font, when insert subdoc into doc, the Chinese in table will be another font, but the english keep the origin style,
 
so I am sure there must be something need to be changed in table of Chinese, there maybe just a small change, because you will never write Chinses, so it is very normal that you may negelect someting .
it is not that you said before it keep with the doc style, but not the subdoc, because my doc font is "等线" all the time, I am very willing to keep touch with you to wipe out this bug of chinese not compatible
the last comment just can send 2 pictures, so I send another chinese in this comment.
thanks a lot
only Chinese in table will change the font, english or words not in table will not
{%r if foobar %} {{r foobar }}COUCOU{%r endif %} I tried to apply this to subdoc like {%p if foobar %} {{p tpl2 }} {%p endif %}, but failed, it says jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endif'.
also , the color in the subdoc will change when inset into doc
only subdoc
subdoc in doc
in docx package, it has different methods for chinese and englist to set font pa.font.name = u'微软雅黑' pa._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
Modify the source code:add w:eastAsia="{font}"
if font:
prop += ( u'<w:rFonts w:ascii="{font}" w:hAnsi="{font}" w:cs="{font}" w:eastAsia="{font}"/>'
.format(font=font) )