python-docx-template icon indicating copy to clipboard operation
python-docx-template copied to clipboard

is it possible to control the cell size of template table in docx

Open wentgithub opened this issue 5 years ago • 16 comments

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 image

wentgithub avatar Jul 23 '19 16:07 wentgithub

It can be fixed if I revise the width in the template.

wentgithub avatar Jul 24 '19 02:07 wentgithub

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

wentgithub avatar Jul 24 '19 02:07 wentgithub

even do like this, rt.add('BRAF', italic=True) # 产生 斜体 效果 rt.add('\ngene')

the result is not good,can you help me ,thanks a lot image

wentgithub avatar Jul 24 '19 03:07 wentgithub

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, image I am really heart-broken

wentgithub avatar Jul 24 '19 05:07 wentgithub

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

wentgithub avatar Jul 24 '19 06:07 wentgithub

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.

elapouya avatar Jul 24 '19 07:07 elapouya

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) # 产生 换行 效果

wentgithub avatar Jul 24 '19 08:07 wentgithub

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 .

elapouya avatar Jul 24 '19 08:07 elapouya

Python3.7

wentgithub avatar Jul 24 '19 08:07 wentgithub

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,** image is there a more elegant method.


![image](https://user-images.githubusercontent.com/48668142/61782129-1ed22180-ae38-11e9-9363-35c5e07822fd.png)
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,

image


![image](https://user-images.githubusercontent.com/48668142/61781691-65734c00-ae37-11e9-9612-c9771431fcb4.png) ![image](https://user-images.githubusercontent.com/48668142/61781925-c6028900-ae37-11e9-8ad5-12f291d94e24.png)

image


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

wentgithub avatar Jul 24 '19 09:07 wentgithub

image the last comment just can send 2 pictures, so I send another chinese in this comment. thanks a lot

wentgithub avatar Jul 24 '19 09:07 wentgithub

only Chinese in table will change the font, english or words not in table will not

wentgithub avatar Jul 24 '19 09:07 wentgithub

{%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'.

wentgithub avatar Jul 24 '19 11:07 wentgithub

also , the color in the subdoc will change when inset into doc
only subdoc image
subdoc in doc image

wentgithub avatar Jul 25 '19 07:07 wentgithub

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'微软雅黑')

wentgithub avatar Jul 25 '19 12:07 wentgithub

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) )

ruizgo avatar Apr 14 '20 07:04 ruizgo