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


Python shared.Inches方法代碼示例

本文整理匯總了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) 
開發者ID:agusmakmun,項目名稱:Some-Examples-of-Simple-Python-Script,代碼行數:9,代碼來源:script.py

示例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) 
開發者ID:liangzp,項目名稱:DQLearning-Toolbox,代碼行數:12,代碼來源:document.py

示例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) 
開發者ID:demisto,項目名稱:dockerfiles,代碼行數:36,代碼來源:Report.py

示例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)) 
開發者ID:xillwillx,項目名稱:skiptracer,代碼行數:4,代碼來源:reporter.py

示例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) 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:31,代碼來源:file_docx.py

示例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 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:34,代碼來源:file_docx.py

示例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) 
開發者ID:skylander86,項目名稱:lambda-text-extractor,代碼行數:11,代碼來源:image.py

示例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) 
開發者ID:demisto,項目名稱:dockerfiles,代碼行數:50,代碼來源:image.py


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