随笔分类 -  编辑word文档

摘要:from docx import Document from docx.shared import Pt from docx.enum.text import WD_ALIGN_PARAGRAPH #导入对齐库 文件=Document(r'E:\word练习\页眉页脚.docx') 第一节=文件.s 阅读全文
posted @ 2020-07-12 10:54 马蹄哒哒 阅读(786) 评论(0) 推荐(0)
摘要:from docx import Document from docx.shared import Cm 文件=Document(r'E:\word练习\页眉页脚.docx') 第一节=文件.sections[0] print(第一节.gutter.cm) 第一节.gutter=Cm(2) prin 阅读全文
posted @ 2020-07-12 10:44 马蹄哒哒 阅读(250) 评论(0) 推荐(0)
摘要:from docx import Document from docx.shared import Cm 文件=Document(r'E:\word练习\页眉页脚.docx') 第一节=文件.sections[0] print("上边距:",第一节.top_margin.cm) print("下边距 阅读全文
posted @ 2020-07-12 10:36 马蹄哒哒 阅读(318) 评论(0) 推荐(0)
摘要:from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.shared import Pt from docx import Document w=Document(r'E:\word练习\a.docx') w.sections.odd_and_ 阅读全文
posted @ 2020-07-11 10:08 马蹄哒哒 阅读(275) 评论(0) 推荐(0)
摘要:from docx.shared import Cm from docx import Document w=Document(,,,,) w.sections[0].header_distance=Cm(10) w.sections[0].footer_distance=Cm(10) w.save 阅读全文
posted @ 2020-07-11 09:22 马蹄哒哒 阅读(303) 评论(0) 推荐(0)
摘要:from docx import Document w=Document() #添加页眉页脚 页眉=w.sections[0].header 段落=页眉.paragraphs[0].add_run('这是第一节页眉') 页脚=w.sections[0].footer 段落=页脚.paragraphs 阅读全文
posted @ 2020-07-10 13:10 马蹄哒哒 阅读(320) 评论(0) 推荐(0)
摘要:from docx import Document w=Document() w.add_section() w.add_section() w.paragraphs[0].add_run('第一个段落') w.paragraphs[1].add_run('第二个段落') w.save(r'D:\w 阅读全文
posted @ 2020-07-08 22:42 马蹄哒哒 阅读(199) 评论(0) 推荐(0)
摘要:from docx import Document from docx.shared import Pt,Inches #Pt指镑(int类型),Inches指英寸(float类型) w=Document(r'D:\word练习\练习.docx') for paragraph in w.paragr 阅读全文
posted @ 2020-07-08 22:15 马蹄哒哒 阅读(209) 评论(0) 推荐(0)
摘要:from docx import Document w=Document(r'D:\word练习\练习.docx') for paragraph in w.paragraphs: if paragraph.style.name=='Normal': paragraph.paragraph_forma 阅读全文
posted @ 2020-07-08 13:02 马蹄哒哒 阅读(285) 评论(0) 推荐(0)
摘要:from docx import Document from docx.shared import Pt,RGBColor from docx.oxml.ns import qn w=Document(r'D:\word练习\练习.docx') for paragraph in w.paragrap 阅读全文
posted @ 2020-07-07 15:13 马蹄哒哒 阅读(397) 评论(0) 推荐(0)
摘要:from docx import Document from docx.oxml.ns import qn #中文字体 w=Document() table=w.add_table(3,3,style='Medium Grid 1 Accent 1') table_head=table.rows[0 阅读全文
posted @ 2020-07-06 18:29 马蹄哒哒 阅读(1798) 评论(0) 推荐(0)
摘要:from docx import Document from docx.enum.style import WD_STYLE_TYPE w=Document() styles=w.styles #生成所有的样式表 for style in styles: if style.type==WD_STYL 阅读全文
posted @ 2020-07-06 18:15 马蹄哒哒 阅读(171) 评论(0) 推荐(0)
摘要:from docx import Document from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT from docx.enum.text import WD_PARAGRAPH_ALIGNMENT w=Document(r'D:\wor 阅读全文
posted @ 2020-07-06 17:54 马蹄哒哒 阅读(210) 评论(0) 推荐(0)
摘要:from docx import Document from docx.shared import Cm from docx.enum.table import WD_TABLE_ALIGNMENT #设置表格对齐方式 w=Document(r'D:\word练习\练习.docx') table=w 阅读全文
posted @ 2020-07-06 16:52 马蹄哒哒 阅读(617) 评论(0) 推荐(0)
摘要:from docx import Document word=Document(r' ') tale=word.tables[0] #第一种删除单元格的方法 table.cell(0,0).text="" #第二种删除单元格的方法 paragraph=table.cell(0,1).paragrap 阅读全文
posted @ 2020-07-05 22:02 马蹄哒哒 阅读(251) 评论(0) 推荐(0)
摘要:import pandas from docx import Document excel=pandas.read_excel(r'F:\word练习\数据.xlsx',header=None) 文件=Document(r'F:\word练习\a.docx') 表=文件.add_table(4,4) 阅读全文
posted @ 2020-07-04 23:15 马蹄哒哒 阅读(700) 评论(0) 推荐(0)
摘要:from docx import Document from docx import WD_PARAGRAPH_ALIGNMENT w=Documeent(r'F:\word练习\a.docx') #第一种方法 t=w.add_table(3,3) t.cell(0,0).text='李先生' #第 阅读全文
posted @ 2020-07-04 23:02 马蹄哒哒 阅读(320) 评论(0) 推荐(0)
摘要:from docx import Document w=Document(r'F:\word练习\表格.docx') #删除表 print(len(w.tables)) t=w.tables[0] t._element.getparent().remove(t._element) print(len 阅读全文
posted @ 2020-07-04 22:42 马蹄哒哒 阅读(184) 评论(0) 推荐(0)
摘要:from docx import Document w=Document(r'F:\word练习\表格.docx') table_1=w.tables[0] #删除行 print(len(table_1.rows)) row2=table_1.rows[1] row2._element.getpar 阅读全文
posted @ 2020-07-04 22:34 马蹄哒哒 阅读(386) 评论(0) 推荐(0)
摘要:from docx import Document from docx.shared import Cm w=Document(r' ') w.tables[0].add_row() #给表格增加一行 w.tables[0].add_column(Cm(5)) #给表哥增加一列 print(len( 阅读全文
posted @ 2020-07-03 11:36 马蹄哒哒 阅读(769) 评论(0) 推荐(0)