日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

python docx 設(shè)置word表格邊框(顏色/線型/粗細(xì))

 新用戶61024634 2022-02-07

曾經(jīng)在網(wǎng)上苦苦尋找過(guò)python docx對(duì)word表格邊框的設(shè)置,一直沒有,現(xiàn)在終于有了,包括邊框顏色、線型、寬度粗細(xì)的設(shè)置,直接用這個(gè)函數(shù)set_cell_border就行了(附加office的參數(shù)參考),這是對(duì)單個(gè)單元格(cell)的上下左右四個(gè)邊框進(jìn)行設(shè)置的:

注意要提前安裝python-docx模塊呦,pip安裝命令:pip install python-docx!

from docx.oxml import OxmlElement from docx.oxml.ns import qn def set_cell_border(cell, **kwargs): ''' Set cell`s border Usage: set_cell_border( cell, top={'sz': 12, 'val': 'single', 'color': '#FF0000', 'space': '0'}, bottom={'sz': 12, 'color': '#00FF00', 'val': 'single'}, left={'sz': 24, 'val': 'dashed', 'shadow': 'true'}, right={'sz': 12, 'val': 'dashed'}, ) ''' tc = cell._tc tcPr = tc.get_or_add_tcPr() # check for tag existnace, if none found, then create one tcBorders = tcPr.first_child_found_in('w:tcBorders') if tcBorders is None: tcBorders = OxmlElement('w:tcBorders') tcPr.append(tcBorders) # list over all available tags for edge in ('left', 'top', 'right', 'bottom', 'insideH', 'insideV'): edge_data = kwargs.get(edge) if edge_data: tag = 'w:{}'.format(edge) # check for tag existnace, if none found, then create one element = tcBorders.find(qn(tag)) if element is None: element = OxmlElement(tag) tcBorders.append(element) # looks like order of attributes is important for key in ['sz', 'val', 'color', 'space', 'shadow']: if key in edge_data: element.set(qn('w:{}'.format(key)), str(edge_data[key]))

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多