本文整理汇总了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
示例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
示例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)
示例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