码迷,mamicode.com
首页 > 其他好文 > 详细

word编辑

时间:2020-11-21 12:00:03      阅读:7      评论:0      收藏:0      [点我收藏+]

标签:def   inpu   elf   函数   strong   blog   tle   filename   save   

from docx import Document
from docx.enum.style import WD_STYLE_TYPE
from docx.enum.text import WD_ALIGN_PARAGRAPH
import os

class Word:
def init(self):

pass

    self.doc = Document()
def write_word(self):
    ‘‘‘主函数‘‘‘
    titles = input(‘请输入标题:‘)
    self.add_titles(titles)   #可以在被的函数中通过self调用其它的函数方法,self即为类本身

    sub_titles = input(‘请输入副标题:‘)
    self.add_subtitles(sub_titles)

    para = input(‘请输入正文:‘)
    self.add_paragraphs(para)

    filename = input(‘请输入文件名:‘)
    self.save_docss(filename)

def add_titles(self, text):
    ‘‘‘添加标题方法‘‘‘
    self.doc.add_heading(text)

def add_subtitles(self, subtitle):
    self.doc.add_paragraph(subtitle, ‘Subtitle‘)

def add_paragraphs(self,para):
    self.doc.add_paragraph(para)

def save_docss(self, filename):
    name =filename + ‘.‘ + ‘docx‘
    self.doc.save(name)

def main():
aa = Word()
aa.write_word()

aa.add_titles(‘bb‘)

if name =="main":
main()

aa.add_subtitles()

请输入标题:aa
请输入副标题:bb
请输入正文:cc
请输入文件名:dd
os.
Object join not found.
import math
class Shttps://blog.csdn.net/shkfpwzolution(object):
def is_square(self,n):
s=int(math.sqrt(n))
return s*s==n

def numSquares(self, n):
    if Solution.is_square(self,n)==True:
        return 1
    while n%4==0:
        n=n/4
    if n%8==7:
        return 4
    i=1
    while i*i<n:
        if Solution.is_square(self,n-i*i)==True:
            return 2
        i+=1
    return 3

import math
class Solution(object):

def is_square(self,n):
    s=int(math.sqrt(n))
    return s*s==n
def numSquares(self, n):
    if self.is_square(n)== True:
        return 1
    while n%4==0:
        n=n/4
    if n%8==7:
        return 4
    i=1
    while i*i<n:
        if self.is_square(n-i*i)==True:
            return 2
        i+=1
    return 3

word编辑

标签:def   inpu   elf   函数   strong   blog   tle   filename   save   

原文地址:https://blog.51cto.com/14308899/2551442

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!