當前位置: 首頁>>代碼示例>>Python>>正文


Python shared.Mm方法代碼示例

本文整理匯總了Python中docx.shared.Mm方法的典型用法代碼示例。如果您正苦於以下問題:Python shared.Mm方法的具體用法?Python shared.Mm怎麽用?Python shared.Mm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docx.shared的用法示例。


在下文中一共展示了shared.Mm方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: word_write

# 需要導入模塊: from docx import shared [as 別名]
# 或者: from docx.shared import Mm [as 別名]
def word_write(generated_doc_path):
    # 模板路徑文件夾
    template_path = current_app.config.get("REPORT_TEMPLATES")
    path = os.path.join(template_path, 'test.docx')

    # 讀取指定位置的模板文件
    doc = DocxTemplate(path)
    # 渲染的內容
    context = {
        # 標題
        'title': "人員信息",
        # 表格
        'table': [
            {"name": "小李", "age": 11},
            {"name": "小張", "age": 21},
            {"name": "小張", "age": 20},
            {"name": "小張1", "age": 10},
            {"name": "小張2", "age": 30},
            {"name": "小張3", "age": 40},
        ],
        # 頁眉
        'header': 'xxx公司人員信息管理',
        # 頁腳
        'footer': '1',
        # 圖片
        'image': InlineImage(doc, os.path.join(template_path, 'test.jpg'), height=Mm(10)),
    }
    # 渲染模板
    doc.render(context)

    # 保存渲染的文件
    doc.save(generated_doc_path)
    return generated_doc_path 
開發者ID:qzq1111,項目名稱:flask-restful-example,代碼行數:35,代碼來源:report.py

示例2: GenerateWordReport

# 需要導入模塊: from docx import shared [as 別名]
# 或者: from docx.shared import Mm [as 別名]
def GenerateWordReport(VulnerabilityDataList,**kwargs):
    #讀取模板文檔
    try:
        tpl = DocxTemplate(GetTemplateFolderLocation().Result()+'WordTemplate.docx')
        Vulnerabulity=[]
        scheme, url, port = UrlProcessing().result(kwargs.get("target_url"))

        VulnerabilityNumber=0#計算漏洞個數用最後清零
        for i in VulnerabilityDataList:
            VulnerabilityNumber+=+1#自增
            Vulnerabulity.append({'vulnerability_name': i.get("vulnerability_name"),#漏洞名稱
                 'vulnerability_level': i.get("vulnerability_level"),#漏洞級別
                'find_the_time': i.get("find_the_time"),#發現時間
                 'vulnerability_description': i.get("vulnerability_description"),#漏洞描述
                'vulnerability_details': str(base64.b64decode(i.get("vulnerability_details")),encoding='utf-8'),#.replace("\r\n","\a"),#漏洞細節,在word中\r\n需要替換成^l^p
                'vulnerability_number':VulnerabilityNumber,
                 'repair_suggestions': i.get("repair_suggestions")#修複建議
                                  })
        context = {
            'target_url':scheme + "://" + url,#傳入處理過的URL
            'number_of_vulnerabilities_in_the_target_website':VulnerabilityNumber,
            'home_picture':InlineImage(tpl,GetTemplateFolderLocation().Result()+"home_picture.jpg",width=Mm(120)),
            'vulnerability' : Vulnerabulity,
            'report_export_time':int(time.time()),
        }
        tpl.render(context)
        WordName=str(int(time.time()))+"_"+url+'.docx'#生成報告名字,這邊經過處理不然Windows報錯
        tpl.save(GetDownloadFolderLocation().Result()+WordName)
        VulnerabilityNumber=0
        return WordName#返回模板名字
    except Exception as e:
        ErrorLog().Write("Web_Api_ProcessingReport_GenerateWordReport(def)", e)
        return None 
開發者ID:Ascotbe,項目名稱:Medusa,代碼行數:35,代碼來源:ProcessingReport.py

示例3: image_for_docx

# 需要導入模塊: from docx import shared [as 別名]
# 或者: from docx.shared import Mm [as 別名]
def image_for_docx(fileref, question, tpl, width=None):
    if fileref.__class__.__name__ in ('DAFile', 'DAFileList', 'DAFileCollection', 'DALocalFile'):
        file_info = dict(fullpath=fileref.path())
    else:
        file_info = server.file_finder(fileref, convert={'svg': 'png'}, question=question)
    if 'fullpath' not in file_info:
        return '[FILE NOT FOUND]'
    if width is not None:
        m = re.search(r'^([0-9\.]+) *([A-Za-z]*)', str(width))
        if m:
            amount = float(m.group(1))
            units = m.group(2).lower()
            if units in ['in', 'inches', 'inch']:
                the_width = Inches(amount)
            elif units in ['pt', 'pts', 'point', 'points']:
                the_width = Pt(amount)
            elif units in ['mm', 'millimeter', 'millimeters']:
                the_width = Mm(amount)
            elif units in ['cm', 'centimeter', 'centimeters']:
                the_width = Cm(amount)
            elif units in ['twp', 'twip', 'twips']:
                the_width = Twips(amount)
            else:
                the_width = Pt(amount)
        else:
            the_width = Inches(2)
    else:
        the_width = Inches(2)
    return InlineImage(tpl, file_info['fullpath'], the_width) 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:31,代碼來源:file_docx.py

示例4: transform_for_docx

# 需要導入模塊: from docx import shared [as 別名]
# 或者: from docx.shared import Mm [as 別名]
def transform_for_docx(text, question, tpl, width=None):
    if type(text) in (int, float, bool, NoneType):
        return text
    text = str(text)
    # m = re.search(r'\[FILE ([^,\]]+), *([0-9\.]) *([A-Za-z]+) *\]', text)
    # if m:
    #     amount = m.group(2)
    #     units = m.group(3).lower()
    #     if units in ['in', 'inches', 'inch']:
    #         the_width = Inches(amount)
    #     elif units in ['pt', 'pts', 'point', 'points']:
    #         the_width = Pt(amount)
    #     elif units in ['mm', 'millimeter', 'millimeters']:
    #         the_width = Mm(amount)
    #     elif units in ['cm', 'centimeter', 'centimeters']:
    #         the_width = Cm(amount)
    #     elif units in ['twp', 'twip', 'twips']:
    #         the_width = Twips(amount)
    #     else:
    #         the_width = Pt(amount)
    #     file_info = server.file_finder(m.group(1), convert={'svg': 'png'}, question=question)
    #     if 'fullpath' not in file_info:
    #         return '[FILE NOT FOUND]'
    #     return InlineImage(tpl, file_info['fullpath'], the_width)
    # m = re.search(r'\[FILE ([^,\]]+)\]', text)
    # if m:
    #     file_info = server.file_finder(m.group(1), convert={'svg': 'png'}, question=question)
    #     if 'fullpath' not in file_info:
    #         return '[FILE NOT FOUND]'
    #     return InlineImage(tpl, file_info['fullpath'], Inches(2))
    #return docassemble.base.filter.docx_template_filter(text, question=question)
    return text 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:34,代碼來源:file_docx.py


注:本文中的docx.shared.Mm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。