Add styling rules in pandoc tables for odt/docx output (table borders)

前端 未结 6 1539
一整个雨季
一整个雨季 2020-12-24 02:42

I\'m generating some odt/docx reports via markdown using knitr and pandoc and am now wondering how you\'d go about formating tables. Primarily I\'m interested in adding rule

6条回答
  •  忘掉有多难
    2020-12-24 03:27

    Using a reference docx file and then python-docx does the job pretty easily :

    https://python-docx.readthedocs.io/

    First convert your document to docx :

    Bash :

    pandoc --standalone --data-dir=/path/to/reference/ --output=/tmp/xxx.docx input_file.md
    

    Notes :

    • /path/to/reference/ points to the folder containing reference.docx
    • reference.docx is a file containing the styles you need for docx elements

    Then give the tables of your document the style you want to use :

    Python :

    import docx
    document = docx.Document('/tmp/xxx.docx')
    for table in document.tables:
        table.style = document.styles['custom_style'] # custom_style must exist in your reference.docx file
    

提交回复
热议问题