本文整理汇总了Python中docx.shared.Inches方法的典型用法代码示例。如果您正苦于以下问题:Python shared.Inches方法的具体用法?Python shared.Inches怎么用?Python shared.Inches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docx.shared
的用法示例。
在下文中一共展示了shared.Inches方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insetImgToDocx
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [as 别名]
def insetImgToDocx(image):
document = Document(docx_file)
p = document.add_paragraph()
r = p.add_run()
r.add_picture(image, width=Inches(5.5)) #inces sesuai yang ada di garis
r.add_text('Ini picture: {}'.format(image))
document.save(docx_file)
示例2: createDoc
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [as 别名]
def createDoc(pairfig,rollfig,mafig):
document=Document()
p=document.add_heading(u'训练情况分析报告',0)
p=document.add_heading(u'一、训练分数描述性统计',level=1)
document.add_picture(pairfig,width=Inches(6.0))
p=document.add_heading(u'二、训练分数12阶滑动平均数图',level=1)
document.add_picture(mafig,width=Inches(6.0))
p=document.add_heading(u'三、训练分数均值、标准差移动平均线',level=1)
document.add_picture(rollfig,width=Inches(6.0))
document.save(doc_path)
示例3: add_header_logos
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [as 别名]
def add_header_logos(self):
# Find the headers
section = self.document.sections[0]
section.header_distance = Pt(0)
header = section.header
table = header.add_table(rows=1, cols=2, width=Inches(24))
table.alignment = WD_TABLE_ALIGNMENT.CENTER
table.autofit = True
left_cell = table.cell(0, 0)
right_cell = table.cell(0, 1)
# Add the left cell to the header
left_image = CellObject(left_cell)
left_cell.paragraphs[-1].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
left_cell.vertical_alignment = 1
# Add the right cell to the header
right_image = CellObject(right_cell)
right_cell.paragraphs[-1].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
right_cell.vertical_alignment = 1
# Add the main logo
left_logo_b64 = self.options.get('demistoLogo', XSOAR_LOGO_BASE64)
s = Section('image', left_logo_b64, {}, {})
image.invoke(left_image, s)
# Add the customer logo
right_logo_b64 = self.options.get('customerLogo', False)
if right_logo_b64:
s = Section('image', right_logo_b64, {}, {
'max_size': {'height': MAX_CUSTOMER_LOGO_HEIGHT_INCH, # max size in inches
'width': MAX_CUSTOMER_LOGO_WIDTH_INCH}})
image.invoke(right_image, s)
示例4: addimg
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [as 别名]
def addimg(self, imglocation):
document.add_picture(imglocation) # , width=Inches(1.25))
示例5: image_for_docx
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [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)
示例6: transform_for_docx
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [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
示例7: default_cx
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [as 别名]
def default_cx(self):
"""
Native width of this image, calculated from its width in pixels and
horizontal dots per inch (dpi).
"""
px_width = self.image.px_width
horz_dpi = self.image.horz_dpi
width_in_inches = px_width / horz_dpi
return Inches(width_in_inches)
示例8: insert
# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import Inches [as 别名]
def insert(self):
if DEBUG:
print("Adding image...")
# Fix empty images
if self.section.contents == '' or self.section.contents == []:
return
if self.section.contents.startswith('http://') or \
self.section.contents.startswith('https://'):
self.section.type = MD_TYPE_IMAGE
self.section.extra['src'] = self.section.contents
md_image.invoke(self.cell_object, self.section)
return
image = None
width_inch = None
height_inch = None
should_shrink = False
if self.section.contents.startswith('data:image/svg+xml;base64'):
image = fix_svg_to_png(self.section.contents)
else:
image = open_b64_image(self.section.contents)
# Some dark magic here to determine the image width (png)
w_px, h_px = struct.unpack(">LL", image.read(26)[16:24])
width_inch = pixels_to_inches(int(w_px))
height_inch = pixels_to_inches(int(h_px))
should_shrink = self.section.extra.get('should_shrink', False)
if should_shrink:
width_inch *= 0.91 # (the size that was calculated was without-
# regards to margins in the doc, let's remove them here)
if self.section.extra.get('max_size', False):
max_size = self.section.extra.get('max_size', {})
max_width = max_size.get('width', None)
max_height = max_size.get('height', None)
width_inch = min(width_inch, max_width)
height_inch = min(height_inch, max_height)
width_inch = Inches(width_inch) if width_inch else None
height_inch = Inches(height_inch) if width_inch else None
self.cell_object.run.add_picture(image, width=width_inch,
height=height_inch)