2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

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

 新用戶61024634 2022-02-07

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

注意要提前安裝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]))

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多