├── .gitignore
├── .idea
└── workspace.xml
├── ArticleCode
└── 还原复旦博士的OCR代码
│ ├── README.md
│ ├── ocr.py
│ ├── pandas.py
│ └── re.py
├── CourseCode
├── Python自动化办公(2021最新版!有源代码 ,适合小白~)
│ ├── 01excel
│ │ ├── 001_Excel_xlrd读_xlwt写
│ │ │ ├── 7月下旬入库表.xlsx
│ │ │ ├── 7月新.xls
│ │ │ ├── read.py
│ │ │ ├── test.xls
│ │ │ ├── write.py
│ │ │ └── 新建文本文档.txt
│ │ ├── 002_Excel_xlutils设置格式
│ │ │ ├── format.py
│ │ │ ├── 填写.xls
│ │ │ └── 日统计.xls
│ │ ├── 003_Excel_案例_统计每位同学总分
│ │ │ ├── 0701SUM.py
│ │ │ ├── 2班学生总分.xls
│ │ │ └── 三年二班(各科成绩单).xls
│ │ ├── 004_Excel_更灵活的操作方式_xlsxwriter_openpyxl
│ │ │ ├── num_open.xlsx
│ │ │ ├── number.xlsx
│ │ │ └── writer_openpyxl.py
│ │ ├── 005-xlwings-pandas
│ │ │ └── xlwings.md
│ │ ├── 006_Excel_案例_把文件夹整理到Excel中
│ │ │ ├── dir.py
│ │ │ └── dir.xls
│ │ ├── 007_Excel_案例_用Excel画画
│ │ │ ├── 0407.xlsx
│ │ │ ├── 111.jpg
│ │ │ ├── image2excel.py
│ │ │ └── test.jpg
│ │ └── textbook.md
│ ├── 02word
│ │ ├── 008_Word_docx_批量把文字写入Word
│ │ │ └── write_doc.py
│ │ ├── 009_Word_docx_批量把图片和表格写入Word
│ │ │ ├── img_table.py
│ │ │ └── title002.jpg
│ │ ├── 010_Word_docx_读取word
│ │ │ ├── document.xhtml
│ │ │ ├── pure.docx
│ │ │ ├── pure.py
│ │ │ ├── word_table.docx
│ │ │ └── word_table.py
│ │ ├── 012_Word_word转pdf
│ │ │ ├── test.docx
│ │ │ └── word2pdf.py
│ │ ├── 013_Word_word批量转pdf,效率提高10倍
│ │ │ ├── words2pdfs.py
│ │ │ └── 员工1-工资调整通知.docx
│ │ └── textbook.md
│ ├── 03pdf
│ │ ├── 14_PDF_识别并读取PDF中的文字
│ │ │ ├── pdf_rd.py
│ │ │ ├── 静夜思.doc
│ │ │ └── 静夜思.pdf
│ │ └── 15_合并PDF
│ │ │ ├── merge.py
│ │ │ ├── merged.pdf
│ │ │ ├── use
│ │ │ ├── merge.py
│ │ │ ├── study.doc
│ │ │ └── study.pdf
│ │ │ └── 静夜思.pdf
│ ├── 04ppt
│ │ ├── 15_PPT_pptx_在PPT中写入文字
│ │ │ ├── ppt_wt.py
│ │ │ └── test.pptx
│ │ ├── 16_PPT_pptx_在PPT中写入图片和表格
│ │ │ ├── img.jpg
│ │ │ ├── ppt_img.py
│ │ │ └── text.pptx
│ │ ├── 17_PPT_pptx_设置统一格式
│ │ │ └── text.txt
│ │ └── textbook.md
│ ├── 05数据可视化
│ │ └── course.py
│ ├── 06机器人
│ │ ├── 26_wxpy_用Python玩微信:可视化统计好友地理位置.py
│ │ ├── 27_wxpy_20行Python代码,获取全部微信好友头像.py
│ │ ├── 28_Python聊天机器人.py
│ │ ├── ali_start.sh
│ │ ├── shadowsocks.json
│ │ └── stop.sh
│ ├── 07爬虫
│ │ └── 31_spider_Python爬虫教程.py
│ ├── 0808的更新通知.xmind
│ ├── 2021更新说明.xmind
│ ├── README.md
│ ├── 图片
│ │ └── excel的学习顺序.jpg
│ ├── 更多Python学习资源.md
│ └── 答疑群.jpg
└── Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)
│ ├── 00demo
│ ├── cmder
│ │ └── cmder.py
│ └── problem
│ │ └── test.doc
│ ├── 01excel
│ ├── 001_Excel_xlrd读_xlwt写
│ │ ├── 7月下旬入库表.xlsx
│ │ ├── read.py
│ │ ├── test.xls
│ │ └── write.py
│ ├── 002_Excel_xlutils设置格式
│ │ ├── format.py
│ │ └── 日统计.xls
│ ├── 003_Excel_案例_统计每位同学总分
│ │ ├── 0701SUM.py
│ │ ├── 2班学生总分.xls
│ │ └── 三年二班(各科成绩单).xls
│ ├── 005_Excel_更灵活的操作方式_xlsxwriter_openpyxl
│ │ ├── num_open.xlsx
│ │ ├── number.xlsx
│ │ └── writer_openpyxl.py
│ ├── 006_Excel_案例_把文件夹整理到Excel中
│ │ ├── dir.py
│ │ └── dir.xls
│ ├── 007_Excel_案例_用Excel画画
│ │ ├── 0407.xlsx
│ │ ├── 111.jpg
│ │ └── image2excel.py
│ └── textbook.md
│ ├── 02word
│ ├── 008_Word_docx_批量把文字写入Word
│ │ └── write_doc.py
│ ├── 009_Word_docx_批量把图片和表格写入Word
│ │ ├── img_table.py
│ │ └── title002.jpg
│ ├── 010_Word_docx_读取word
│ │ ├── pure.docx
│ │ ├── pure.py
│ │ ├── word_table.docx
│ │ └── word_table.py
│ ├── 012_Word_word转pdf
│ │ ├── test.docx
│ │ └── word2pdf.py
│ ├── 013_Word_word批量转pdf,效率提高10倍
│ │ └── words2pdfs.py
│ └── textbook.md
│ ├── 03pdf
│ └── 14_PDF_识别并读取PDF中的文字
│ │ ├── pdf_rd.py
│ │ ├── 静夜思.doc
│ │ └── 静夜思.pdf
│ ├── 04ppt
│ ├── 15_PPT_pptx_在PPT中写入文字
│ │ ├── ppt_wt.py
│ │ └── test.pptx
│ ├── 16_PPT_pptx_在PPT中写入图片和表格
│ │ ├── img.jpg
│ │ ├── ppt_img.py
│ │ └── text.pptx
│ ├── 17_PPT_pptx_设置统一格式
│ │ └── text.txt
│ └── textbook.md
│ ├── 06_email
│ ├── 23_用Python发送普通的文字邮件.py
│ ├── 24_用Python发送带附件的邮件.py
│ └── student.xls
│ ├── 07web
│ └── 25_web_入门教程看这里.py
│ ├── 08wxpy
│ ├── 26_wxpy_用Python玩微信:可视化统计好友地理位置.py
│ ├── 27_wxpy_20行Python代码,获取全部微信好友头像.py
│ └── 28_Python聊天机器人.py
│ ├── 09spider
│ └── 31_spider_Python爬虫教程.py
│ ├── 更多Python学习资源.md
│ └── 答疑群.jpg
├── LICENSE
├── README.md
├── img
└── WeChatPay.png
└── pip
└── python4office
├── python4office
├── __init__.py
└── hello-world.py
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98 | __pypackages__/
99 |
100 | # Celery stuff
101 | celerybeat-schedule
102 | celerybeat.pid
103 |
104 | # SageMath parsed files
105 | *.sage.py
106 |
107 | # Environments
108 | .env
109 | .venv
110 | env/
111 | venv/
112 | ENV/
113 | env.bak/
114 | venv.bak/
115 | .idea/
116 |
117 | # Spyder project settings
118 | .spyderproject
119 | .spyproject
120 |
121 | # Rope project settings
122 | .ropeproject
123 |
124 | # mkdocs documentation
125 | /site
126 |
127 | # mypy
128 | .mypy_cache/
129 | .dmypy.json
130 | dmypy.json
131 |
132 | # Pyre type checker
133 | .pyre/
134 |
135 | # pytype static type analyzer
136 | .pytype/
137 |
138 | # Cython debug symbols
139 | cython_debug/
140 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
42 |
43 |
44 |
45 |
46 |
47 | 1620355846401
48 |
49 |
50 | 1620355846401
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | 1650007983921
59 |
60 |
61 |
62 | 1650007983921
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ArticleCode/还原复旦博士的OCR代码/README.md:
--------------------------------------------------------------------------------
1 | # 还原复旦博士OCR代码
2 |
3 | ### 你好呀,我是[程序员晚枫](https://mp.weixin.qq.com/s/CmuopIUWCWP-YZRaBnKNNg)
4 | - 🐧 编程知识博主
5 | - 👨💻 我的经历,点击查看👉[法学院毕业后转行Python程序员,现定居重庆,就职于某上市航空公司](https://www.bilibili.com/video/BV1uT4y1i7J8)
6 | - 💬 我的微信,点击添加👉[CoderWanFeng](/images/CoderWanFeng.jpg)
7 | - ⚡ 学习资料,点击领取👉[6套自媒体课程的合集](https://mp.weixin.qq.com/s/QSFUzwPZMnIQDFdt_JQXug)
8 | - 🎁 粉丝福利👉[我收集的办公黑科技软件,免费赠送](https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg2MjU3ODYyNA==&action=getalbum&album_id=2186546268016017410&scene=173&from_msgid=2247485082&from_itemidx=1&count=3&nolastread=1#wechat_redirect)
9 |
10 |
11 |
12 | ### 代码
13 |
14 | - ocr:https://gitee.com/CoderWanFeng/python4office/blob/master/ArticleCode/%E8%BF%98%E5%8E%9F%E5%A4%8D%E6%97%A6%E5%8D%9A%E5%A3%AB%E7%9A%84OCR%E4%BB%A3%E7%A0%81/ocr.py
15 | - re:https://gitee.com/CoderWanFeng/python4office/blob/master/ArticleCode/%E8%BF%98%E5%8E%9F%E5%A4%8D%E6%97%A6%E5%8D%9A%E5%A3%AB%E7%9A%84OCR%E4%BB%A3%E7%A0%81/re.py
16 | - pandas:https://gitee.com/CoderWanFeng/python4office/blob/master/ArticleCode/%E8%BF%98%E5%8E%9F%E5%A4%8D%E6%97%A6%E5%8D%9A%E5%A3%AB%E7%9A%84OCR%E4%BB%A3%E7%A0%81/pandas.py
17 |
18 |
--------------------------------------------------------------------------------
/ArticleCode/还原复旦博士的OCR代码/ocr.py:
--------------------------------------------------------------------------------
1 | from paddleocr import PaddleOCR, draw_ocr
2 |
3 | # Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
4 | # 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
5 | ocr = PaddleOCR(use_angle_cls=True, lang="ch")
6 | img_path = './imgs/test.jpg'
7 | result = ocr.ocr(img_path, cls=True)
8 | for line in result:
9 | print(line)
--------------------------------------------------------------------------------
/ArticleCode/还原复旦博士的OCR代码/pandas.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import numpy as np
3 |
4 | info1 = name + time + result
5 | info1 = np.array(info1).reshape(1,3)
6 |
7 | df = pd.DataFrame(info1,columns=['姓名','时间','检测结果'])
8 | df.to_excel('核酸结果.xlsx', index=False)
--------------------------------------------------------------------------------
/ArticleCode/还原复旦博士的OCR代码/re.py:
--------------------------------------------------------------------------------
1 | # 导入re模块
2 | import re
3 |
4 | strs = '''17:28
5 | 检测结果查询
6 | 检测结果【阴性】
7 | 姓名 朱卫军
8 | 采样时间 2022-04-08 12:28
9 | 试剂编码 48
10 | 检测项目 新冠抗原'''
11 |
12 | name = re.findall('(?<=姓名 ).*',strs)
13 | time = re.findall('(?<=采样时间 ).*',strs)
14 | result = re.findall('(?<=【).*(?=】)',strs)
15 | print(name)
16 | print(time)
17 | print(result)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/7月下旬入库表.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/7月下旬入库表.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/7月新.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/7月新.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/read.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : read.py
4 | # @Software: PyCharm
5 | # @Description:
6 | # 0基础如何系统的学会Python? 链接:https://mp.weixin.qq.com/s/xkZSp3606rTPN_JbLT3hSQ
7 | #安装命令:pip install xlrd
8 |
9 | import xlrd
10 | # 打开excel
11 | xlsx = xlrd.open_workbook('7月新.xls')
12 |
13 | sheet = xlsx.sheet_by_index(0)
14 | data = sheet.cell_value(5, 1)
15 | print(data)
16 |
17 | # for i in xlsx.sheet_names():
18 | # print(i)
19 | # table = xlsx.sheet_by_name(i)
20 | # print(table.cell_value(3, 3))
21 | # 通过sheet名查找:xlsx.sheet_by_name("7月下旬入库表")
22 | # 通过索引查找:xlsx.sheet_by_index(3)
23 | # print(table.cell_value(0, 0))
24 |
25 | # print(sheet.cell_value(1, 2))
26 | # print(sheet.cell(0, 0).value)
27 | # print(sheet.row(0)[0].value)
28 |
29 |
30 | # for i in range(0, xlsx.nsheets):
31 | # sheet = xlsx.sheet_by_index(i)
32 | # print(sheet.name)
33 | # print(sheet.cell_value(0, 0))
34 | #
35 | # # 获取所有sheet名字:xlsx.sheet_names()
36 | # # 获取sheet数量:xlsx.nsheets
37 | #
38 | # for i in xlsx.sheet_names():
39 | # print(i)
40 | # table = xlsx.sheet_by_name(i)
41 | # print(table.cell_value(3, 3))
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/test.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/test.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/write.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : write.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | import xlwt
8 | #安装:pip install xlwt
9 | # 打开terminal
10 |
11 | # 新建工作簿
12 | new_workbook = xlwt.Workbook()
13 | # 新建sheet
14 | worksheet = new_workbook.add_sheet('new_test')
15 | # 新建单元格,并写入内容-行列
16 | worksheet.write(1, 2, 'test')
17 | # 保存
18 | new_workbook.save('test.xls')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/新建文本文档.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/新建文本文档.txt
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/format.py:
--------------------------------------------------------------------------------
1 | from xlutils.copy import copy
2 | import xlrd
3 | import xlwt
4 |
5 | # 安装:pip install xlutils
6 |
7 | tem_excel = xlrd.open_workbook('日统计.xls', formatting_info=True)
8 | tem_sheet = tem_excel.sheet_by_index(0)
9 |
10 | new_excel = copy(tem_excel)
11 | new_sheet = new_excel.get_sheet(0)
12 |
13 | style = xlwt.XFStyle()
14 |
15 | # 字体
16 | font = xlwt.Font()
17 | font.name = '微软雅黑'
18 | font.bold = True
19 | # 18*20
20 | font.height = 360
21 | style.font = font
22 |
23 | # 边框:细线==THIN
24 | borders = xlwt.Borders()
25 | borders.top = xlwt.Borders.THIN
26 | borders.bottom = xlwt.Borders.THIN
27 | borders.left = xlwt.Borders.THIN
28 | borders.right = xlwt.Borders.THIN
29 | style.borders = borders
30 |
31 | # 对齐
32 | alignment = xlwt.Alignment()
33 | alignment.horz = xlwt.Alignment.HORZ_CENTER
34 | alignment.vert = xlwt.Alignment.VERT_CENTER
35 | style.alignment = alignment
36 |
37 |
38 | new_sheet.write(2, 1, 12)
39 | new_sheet.write(3, 1, 18)
40 | new_sheet.write(4, 1, 19)
41 | new_sheet.write(5, 1, 15)
42 |
43 |
44 | # new_sheet.write(2, 1, 12, style)
45 | # new_sheet.write(3, 1, 18, style)
46 | # new_sheet.write(4, 1, 19, style)
47 | # new_sheet.write(5, 1, 15, style)
48 |
49 | new_excel.save('填写.xls')
50 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/填写.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/填写.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/日统计.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/日统计.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/0701SUM.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : 0701SUM.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | import xlrd
8 |
9 | import xlwt
10 |
11 | # 读取excel文件
12 | xlsx = xlrd.open_workbook('三年二班(各科成绩单).xls')
13 | # 选择指定sheet
14 | sheet = xlsx.sheet_by_index(0)
15 |
16 | # 入门23讲:https://www.bilibili.com/video/BV17p4y1i7Vn
17 | # 前3讲听完,再回来运行:数据类型、for、计算
18 | # 依次单元格数据,并统计总分
19 | all_data = []
20 | # 统计共有多少学生,并去重
21 | num_set = set()
22 | for row_i in range(1, sheet.nrows):
23 | num = sheet.cell_value(row_i, 0)
24 | name = sheet.cell_value(row_i, 1)
25 | grade = sheet.cell_value(row_i, 3)
26 |
27 | student = {
28 | 'num': num,
29 | 'name': name,
30 | 'grade': grade,
31 | }
32 | all_data.append(student)
33 | num_set.add(num)
34 | # print(all_data)
35 | # print(len(all_data))
36 | # print(len(num_set))
37 |
38 | # 计算总分
39 | sum_list = []
40 | for num in num_set:
41 | name = ''
42 | sum = 0
43 | for student in all_data:
44 | # print(student['num'])
45 | # print(num)
46 | if num == student['num']:
47 | sum += student['grade']
48 | name = student['name']
49 | sum_stu = {
50 | 'num': num,
51 | 'name': name,
52 | 'sum': sum
53 | }
54 | sum_list.append(sum_stu)
55 | print(sum_list)
56 |
57 | # 写入新的excel
58 |
59 | # 新建工作簿
60 | new_workbook = xlwt.Workbook()
61 | # 新建sheet
62 | worksheet = new_workbook.add_sheet('2班')
63 | # 新建单元格,并写入内容
64 | # 写入第一列的内容
65 | worksheet.write(0, 0, '学号')
66 | worksheet.write(0, 1, '姓名')
67 | worksheet.write(0, 2, '总分')
68 | # 自动写入后面的内容
69 | for row in range(0,len(sum_list)):
70 | worksheet.write(row+1,0,sum_list[row]['num'])
71 | worksheet.write(row+1,1,sum_list[row]['name'])
72 | worksheet.write(row+1,2,sum_list[row]['sum'])
73 | # 保存
74 | new_workbook.save('2班学生总分.xls')
75 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/2班学生总分.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/2班学生总分.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/三年二班(各科成绩单).xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/三年二班(各科成绩单).xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/004_Excel_更灵活的操作方式_xlsxwriter_openpyxl/num_open.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/004_Excel_更灵活的操作方式_xlsxwriter_openpyxl/num_open.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/004_Excel_更灵活的操作方式_xlsxwriter_openpyxl/number.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/004_Excel_更灵活的操作方式_xlsxwriter_openpyxl/number.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/004_Excel_更灵活的操作方式_xlsxwriter_openpyxl/writer_openpyxl.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : writer_openpyxl.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | # import xlwt
8 | #
9 | # workbook = xlwt.Workbook()
10 | # sheet0 = workbook.add_sheet('sheet0')
11 | # for i in range(0,300):
12 | # sheet0.write(0,i,i)
13 | # workbook.save('num.xls')
14 |
15 | # 不带格式
16 | import xlsxwriter as xw
17 | workbook = xw.Workbook('number.xlsx')
18 | sheet0 = workbook.add_worksheet('sheet0')
19 | for i in range(0,300):
20 | sheet0.write(0,i,i)
21 | workbook.close()
22 |
23 |
24 | # 性能不稳定
25 | import openpyxl
26 | workbook = openpyxl.load_workbook('number.xlsx')
27 | sheet0 = workbook['sheet0']
28 | sheet0['B3']= '2'
29 | sheet0['C2']= '4'
30 | sheet0['D7']= '3'
31 | workbook.save('num_open.xlsx')
32 |
33 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/005-xlwings-pandas/xlwings.md:
--------------------------------------------------------------------------------
1 | ### 为什么是xlwings ?
2 |
3 | 
4 |
5 | 之前给大家整理过Python用来处理Excel的全部可用库,以及它们的优缺点:[全解析!9个处理Excel的Python库,到底哪个最好用?](http://mp.weixin.qq.com/s?__biz=MzI2Nzg5MjgyNg==&mid=2247489016&idx=1&sn=189adc7795cebc6e71543d6bbeebb735&chksm=eaf6b4cddd813ddb53f2db0e1e901e293569b2292179801dc73223799e5ea90d4dfe049b30a9#rd)
6 |
7 | > 每个人来学习都是想一步到位,不会考虑那些功能不全的库。
8 |
9 | 这其中最强大的库是Pandas,之前已经给大家推荐过相关的课程和全部文档了。大家可以去免费i学习~
10 |
11 | 除了Pandas,只有两个库:**xlwings**和win32com,具有全部操作权限,然而win32com,因为各种技术原因在使用中经常出难解决的问题。所以只剩下xlwings是最佳选项了。
12 |
13 | #### xlwings具有以下优点:
14 |
15 | - xlwings能够非常方便的读写Excel文件中的数据,并且能够进行单元格格式的修改
16 | - 可以和matplotlib以及pandas无缝连接
17 | - 可以调用Excel文件中VBA写好的程序,也可以让VBA调用用Python写的程序。
18 | - 开源免费,一直在更新
19 |
20 | 我们今天就来讲解一下,xlwings如何使用~
21 |
22 | > xlwings的详细官方使用文档,获取方式见文末~
23 |
24 |
25 |
26 | ### 安装
27 |
28 | 工欲善其事必先利其器,
29 |
30 | 如果是在开始xlwings之前,您还没有安装Python+开发工具,请花10分钟的时间,移步此链接:链接,先把Python+开发工具,可以吗?安装过程中,有问题可以来交流群提问:交流群
31 |
32 | #### Python环境下安装(推荐)
33 |
34 | ```
35 | pip install xlwings
36 | ```
37 |
38 | #### Anaconda环境下安装
39 |
40 | ```
41 | conda install xlwings
42 | ```
43 | 不推荐使用anaconda
44 | - 这个东西很大,100库,但是和自动化办公无关
45 | - 8G,2G,100库
46 | - anaconda独立的编程环境,这套课很多技术不能用
47 | - 多学一些无用知识,浪费时间
48 |
49 | ### 使用演示
50 |
51 | 
52 |
53 | #### 1、打开/新建Excel文档
54 |
55 | ```python
56 | import xlwings as xw
57 | wb = xw.Book() # 新建一个文档
58 | wb = xw.Book('test.xlsx') # 打开一个已有的文档
59 | ```
60 |
61 | #### 2、读取/写入数据
62 |
63 | ```python
64 | sht = wb.sheets['Sheet1'] # 找到指定sheet
65 | print(sht.range('A1').value) # 读取指定单元格的数据,这里读的是A1
66 | sht.range('B1').value = 10 # 给指定的空白单元格赋值,这里赋值的是B1
67 | ```
68 |
69 | #### 3、保存文件、退出程序
70 |
71 | ```python
72 | wb.save(r'test.xlsx') #保存Excel文档,命名为test.xlsx,并保存在D盘
73 | wb.close() # 退出程序,该步骤不可省略
74 | ```
75 |
76 | #### 4、连接pandas处理复杂数据
77 |
78 | ```python
79 | import pandas as pd
80 | df = pd.DataFrame([[1,2], [3,4]], columns=['a', 'b'])
81 | sht.range('A1').value = df
82 | sht.range('A1').options(pd.DataFrame, expand='table').value
83 | ```
84 |
85 | #### 5、连接**Matplotlib** 画图
86 |
87 | ```python
88 | import matplotlib.pyplot as plt
89 | fig = plt.figure()
90 | plt.plot([1, 2, 3, 4, 5])
91 | sht.pictures.add(fig, name='MyPlot', update=True)
92 | ```
93 |
94 |
95 |
96 | ### 其他资源
97 |
98 | 可以在Python-Docx的GitHub页面上找到更多示例代码。
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/006_Excel_案例_把文件夹整理到Excel中/dir.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : dir.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | import os
8 | import xlwt
9 |
10 | # 目标文件夹
11 | file_path = 'd:/'
12 | # 取出目标文件夹下的文件名
13 | os.listdir(file_path)
14 |
15 | new_workbook = xlwt.Workbook()
16 | sheet = new_workbook.add_sheet('new_dir')
17 |
18 | n = 0
19 | for i in os.listdir(file_path):
20 | sheet.write(n,0,i)
21 | n+=1
22 | new_workbook.save('dir.xls')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/006_Excel_案例_把文件夹整理到Excel中/dir.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/006_Excel_案例_把文件夹整理到Excel中/dir.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/0407.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/0407.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/111.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/111.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/image2excel.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 |
3 | from PIL import Image
4 | from xlsxwriter.workbook import Workbook
5 |
6 |
7 | # 入门23讲:https://www.bilibili.com/video/BV17p4y1i7Vn
8 | # 第10听完,再回来运行:面向对象的知识
9 |
10 | class ExcelPicture(object):
11 | FORMAT_CONSTRAINT = 65536
12 |
13 | def __init__(self, pic_file, ratio=0.5):
14 | self.__pic_file = pic_file
15 |
16 | self.__ratio = ratio
17 | self.__zoomed_out = False
18 |
19 | self.__formats = dict()
20 |
21 | # 缩小图片
22 | def zoom_out(self, _img):
23 | _size = _img.size
24 | _img.thumbnail((int(_img.size[0] * self.__ratio), int(_img.size[1] * self.__ratio)))
25 |
26 | self.__zoomed_out = True
27 |
28 | # 对颜色进行圆整
29 | def round_rgb(self, rgb, model):
30 | return tuple([int(round(x / model) * model) for x in rgb])
31 |
32 | # 查找颜色样式,去重
33 | def get_format(self, color):
34 | _format = self.__formats.get(color, None)
35 |
36 | if _format is None:
37 | _format = self.__wb.add_format({'bg_color': color})
38 | self.__formats[color] = _format
39 |
40 | return _format
41 |
42 | # 操作流程
43 | def process(self, output_file='_pic.xlsx', color_rounding=False, color_rounding_model=5.0):
44 | # 创建xlsx文件,并调整行列属性
45 | self.__wb = Workbook(output_file)
46 | self.__sht = self.__wb.add_worksheet()
47 | self.__sht.set_default_row(height=9)
48 | self.__sht.set_column(0, 5000, width=1)
49 |
50 | # 打开需要进行转换的图片
51 | _img = Image.open(self.__pic_file)
52 | print('Picture filename:', self.__pic_file)
53 |
54 | # 判断是否需要缩小图片尺寸
55 | if self.__ratio < 1:
56 | self.zoom_out(_img)
57 |
58 | # 遍历每一个像素点,并填充对应的颜色到对应的Excel单元格
59 | _size = _img.size
60 | print('Picture size:', _size)
61 | for (x, y) in [(x, y) for x in range(_size[0]) for y in range(_size[1])]:
62 | _clr = _img.getpixel((x, y))
63 |
64 | # 如果颜色种类过多,则需要将颜色圆整到近似的颜色上,以减少颜色种类
65 | if color_rounding: _clr = self.round_rgb(_clr, color_rounding_model)
66 |
67 | _color = '#%02X%02X%02X' % _clr
68 | self.__sht.write(y, x, '', self.get_format(_color))
69 |
70 | self.__wb.close()
71 |
72 | # 检查颜色样式种类是否超出限制,Excel2007对样式数量有最大限制
73 | format_size = len(self.__formats.keys())
74 | if format_size >= ExcelPicture.FORMAT_CONSTRAINT:
75 | print('Failed! Color size overflow: %s.' % format_size)
76 | else:
77 | print('Success!')
78 | print('Color: %s' % format_size)
79 | print('Color_rounding:', color_rounding)
80 | if color_rounding:
81 | print('Color_rounding_model:', color_rounding_model)
82 |
83 |
84 | if __name__ == '__main__':
85 | r = ExcelPicture('test.jpg', ratio=0.5)
86 | r.process('0407.xlsx', color_rounding=True, color_rounding_model=5.0)
87 | # 同级目录
88 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/test.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/test.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/01excel/textbook.md:
--------------------------------------------------------------------------------
1 | - excel:
2 | - 文件.xlsx
3 | - sheet
4 | - 单元格:a1/a2/b3/c6
5 | - xlrd
6 | - 读excel
7 |
8 | - xlwt
9 | - 写excel
10 |
11 | - xlutils
12 | - 设置单元格格式(选学)
13 |
14 | - 统计3年2班学生总分
15 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/008_Word_docx_批量把文字写入Word/write_doc.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : write_doc.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | from docx import Document
8 | from docx.enum.text import WD_ALIGN_PARAGRAPH
9 | from docx.shared import Pt
10 | from docx.oxml.ns import qn
11 |
12 | import time
13 |
14 | price = input('请输入工资调整金额:')
15 | # 全体员工姓名
16 | company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10' ]
17 | # word和excel
18 | # excel学习:for
19 | # 当天的日期
20 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
21 |
22 | for i in company_list:
23 | document = Document()
24 | # 设置文档的基础字体
25 | document.styles['Normal'].font.name = u'宋体'
26 | # 识别中文
27 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
28 |
29 | # 建立一个自然段
30 | p1 = document.add_paragraph()
31 | # 对齐方式为居中,没有这句的话默认左对齐
32 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
33 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
34 | run1.font.name = '微软雅黑'
35 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
36 | run1.font.size = Pt(21)
37 | run1.font.bold = True
38 | p1.space_after = Pt(5)
39 | p1.space_before = Pt(5)
40 |
41 | p2 = document.add_paragraph()
42 | run2 = p2.add_run(i + ':')
43 | run2.font.name = '宋体'
44 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
45 | run2.font.size = Pt(16)
46 | run2.font.bold = True
47 |
48 | p3 = document.add_paragraph()
49 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知' % price)
50 | run3.font.name = '宋体'
51 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
52 | run3.font.size = Pt(14)
53 |
54 | p4 = document.add_paragraph()
55 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
56 | run4 = p4.add_run('人事:王小姐 电话:686868')
57 | run4.font.name = '宋体'
58 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
59 | run4.font.size = Pt(14)
60 | run4.font.bold = True
61 |
62 |
63 | document.save('%s-工资调整通知.docx' % i)
64 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/009_Word_docx_批量把图片和表格写入Word/img_table.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : img_table.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 |
8 | from docx import Document
9 | from docx.enum.text import WD_ALIGN_PARAGRAPH
10 | from docx.shared import Pt
11 | from docx.oxml.ns import qn
12 | from docx.shared import Inches
13 |
14 | import time
15 |
16 | price = input('请输入工资调整金额:')
17 | company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10', ]
18 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
19 | for i in company_list:
20 | document = Document()
21 | # 设置文档的基础字体
22 | document.styles['Normal'].font.name = u'宋体'
23 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
24 | # 红头文件
25 | document.add_picture('title002.jpg', width=Inches(6))
26 |
27 | # 建立一个自然段
28 | p1 = document.add_paragraph()
29 | # 对齐方式为居中,没有这句的话默认左对齐
30 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
31 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
32 | run1.font.name = '微软雅黑'
33 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
34 | run1.font.size = Pt(21)
35 | run1.font.bold = True
36 | p1.space_after = Pt(5)
37 | p1.space_before = Pt(5)
38 |
39 | p2 = document.add_paragraph()
40 | run2 = p2.add_run(i + ':')
41 | run2.font.name = '宋体'
42 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
43 | run2.font.size = Pt(16)
44 | run2.font.bold = True
45 |
46 | p3 = document.add_paragraph()
47 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知。' % price)
48 | run3.font.name = '宋体'
49 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
50 | run3.font.size = Pt(14)
51 |
52 | table = document.add_table(rows=2, cols=2, style='Table Grid')
53 | # 合并单元格
54 | table.cell(0, 0).merge(table.cell(0, 1))
55 | table_run1 = table.cell(0, 0).paragraphs[0].add_run('签名栏')
56 | table_run1.font.name = '黑体'
57 | table_run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'黑体')
58 | table.cell(0, 0).paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
59 | table.cell(1, 0).text = i
60 | table.cell(1, 0).paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
61 |
62 | p4 = document.add_paragraph()
63 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
64 |
65 | run4 = p4.add_run('人事:王小姐 电话:686868')
66 | run4.font.name = '宋体'
67 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
68 | run4.font.size = Pt(14)
69 | run4.font.bold = True
70 |
71 | document.save('%s-工资调整通知.docx' % i)
72 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/009_Word_docx_批量把图片和表格写入Word/title002.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/009_Word_docx_批量把图片和表格写入Word/title002.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/document.xhtml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | 关于2020年08月20日工资调整的通知
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | 员工1:
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | 因为疫情影响,我们很抱歉的通知您,您的工资调整为每月100元,特此通知。
85 |
86 |
87 |
88 |
89 |
90 |
91 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | 签名栏
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | 员工1
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 | 人事:王小姐 电话:686868
150 |
151 |
152 |
153 |
154 |
156 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/pure.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/pure.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/pure.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # @公众号 :Python自动化办公社区
4 | # @File : pure.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | from docx import Document
9 |
10 | document = Document('pure.docx')
11 | all_paragraphs = document.paragraphs
12 | for p in all_paragraphs:
13 | print(p.text)
14 |
15 |
16 | # excel写入
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/word_table.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/word_table.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/word_table.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 19:10
3 | # @公众号 :Python自动化办公社区
4 | # @File : word_table.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import zipfile
9 |
10 | word_book = zipfile.ZipFile('word_table.docx')
11 | xml = word_book.read("word/document.xml").decode('utf-8')
12 | # print(xml)
13 | xml_list = xml.split('')
14 | print(xml_list)
15 | text_list = []
16 | for i in xml_list:
17 | if i.find('') + 1:
18 | text_list.append(i[:i.find('')])
19 | else:
20 | pass
21 | text = "".join(text_list)
22 | print(text)
23 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/012_Word_word转pdf/test.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/012_Word_word转pdf/test.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/012_Word_word转pdf/word2pdf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File : word2pdf.py
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | from win32com.client import Dispatch,constants,gencache
8 |
9 | doc_path = 'test.docx'
10 | pdf_path = 'test.pdf'
11 |
12 | gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}',0,8,4)
13 | wd = Dispatch("Word.Application")
14 | doc = wd.Documents.Open(doc_path,ReadOnly=1)
15 | doc.ExportAsFixedFormat(pdf_path,constants.wdExportFormatPDF,
16 | Item=constants.wdExportDocumentWithMarkup,
17 | CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
18 | wd.Quit(constants.wdDoNotSaveChanges)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/013_Word_word批量转pdf,效率提高10倍/words2pdfs.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 22:52
3 | # @公众号 :Python自动化办公社区
4 | # @File : words2pdfs.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import os
9 | from win32com.client import Dispatch,constants,gencache
10 |
11 |
12 |
13 | from docx import Document
14 | from docx.enum.text import WD_ALIGN_PARAGRAPH
15 | from docx.shared import Pt
16 | from docx.oxml.ns import qn
17 |
18 | import time
19 |
20 | price = input('请输入工资调整金额:')
21 | # 全体员工姓名
22 | company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10' ]
23 | # 当天的日期
24 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
25 |
26 | for i in company_list:
27 | document = Document()
28 | # 设置文档的基础字体
29 | document.styles['Normal'].font.name = u'宋体'
30 | # 识别中文
31 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
32 |
33 | # 建立一个自然段
34 | p1 = document.add_paragraph()
35 | # 对齐方式为居中,没有这句的话默认左对齐
36 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
37 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
38 | run1.font.name = '微软雅黑'
39 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
40 | run1.font.size = Pt(21)
41 | run1.font.bold = True
42 | p1.space_after = Pt(5)
43 | p1.space_before = Pt(5)
44 |
45 | p2 = document.add_paragraph()
46 | run2 = p2.add_run(i + ':')
47 | run2.font.name = '宋体'
48 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
49 | run2.font.size = Pt(16)
50 | run2.font.bold = True
51 |
52 | p3 = document.add_paragraph()
53 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知' % price)
54 | run3.font.name = '宋体'
55 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
56 | run3.font.size = Pt(14)
57 |
58 | p4 = document.add_paragraph()
59 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
60 | run4 = p4.add_run('人事:王小姐 电话:686868')
61 | run4.font.name = '宋体'
62 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
63 | run4.font.size = Pt(14)
64 | run4.font.bold = True
65 |
66 |
67 | document.save('%s-工资调整通知.docx' % i)
68 |
69 | doc_path = '%s-工资调整通知.docx' % i
70 | pdf_path = '%s-工资调整通知.pdf' % i
71 |
72 | gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}',0,8,4)
73 | wd = Dispatch("Word.Application")
74 | doc = wd.Documents.Open(doc_path,ReadOnly=1)
75 | doc.ExportAsFixedFormat(pdf_path,constants.wdExportFormatPDF,Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
76 | wd.Quit(constants.wdDoNotSaveChanges)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/013_Word_word批量转pdf,效率提高10倍/员工1-工资调整通知.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/013_Word_word批量转pdf,效率提高10倍/员工1-工资调整通知.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/02word/textbook.md:
--------------------------------------------------------------------------------
1 | - python-docx
2 | - 说明文档:https://python-docx.readthedocs.io/en/latest/#api-documentation
3 |
4 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/pdf_rd.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2021/3/16 18:02
3 | # @公众号 :Python自动化办公社区
4 | # @File : pdf_python.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import PyPDF2
9 | import pdfplumber
10 |
11 | def extract_content(pdf_path):
12 | # 内容提取,使用 pdfplumber 打开 PDF,用于提取文本
13 | with pdfplumber.open(pdf_path) as pdf_file:
14 | # 使用 PyPDF2 打开 PDF 用于提取图片
15 | pdf_image_reader = PyPDF2.PdfFileReader(open(pdf_path, "rb"))
16 | print(pdf_image_reader.getNumPages())
17 |
18 | content = ''
19 | # len(pdf.pages)为PDF文档页数,一页页解析
20 | for i in range(len(pdf_file.pages)):
21 | print("当前第 %s 页" % i)
22 | # pdf.pages[i] 是读取PDF文档第i+1页
23 | page_text = pdf_file.pages[i]
24 | # page.extract_text()函数即读取文本内容
25 | page_content = page_text.extract_text()
26 | if page_content:
27 | content = content + page_content + "\n"
28 | print(page_content)
29 |
30 | extract_content('静夜思.pdf')
31 |
32 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.doc
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.pdf
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/merge.py:
--------------------------------------------------------------------------------
1 | from PyPDF2 import PdfFileReader, PdfFileWriter
2 |
3 | def merge_pdfs(paths, output):
4 | pdf_writer = PdfFileWriter()
5 |
6 | for path in paths:
7 | pdf_reader = PdfFileReader(path)
8 | for page in range(pdf_reader.getNumPages()):
9 | # 把每张PDF页面加入到这个可读取对象中
10 | pdf_writer.addPage(pdf_reader.getPage(page))
11 |
12 | # 把这个已合并了的PDF文档存储起来
13 | with open(output, 'wb') as out:
14 | pdf_writer.write(out)
15 |
16 | if __name__ == '__main__':
17 | paths = ['静夜思.pdf', '静夜思.pdf']
18 | merge_pdfs(paths, output='pandas官方文档中文版.pdf')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/merged.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/merged.pdf
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/use/merge.py:
--------------------------------------------------------------------------------
1 | from PyPDF2 import PdfFileReader, PdfFileWriter
2 |
3 | def merge_pdfs(paths, output):
4 | pdf_writer = PdfFileWriter()
5 |
6 | for path in paths:
7 | pdf_reader = PdfFileReader(path)
8 | for page in range(pdf_reader.getNumPages()):
9 | # 把每张PDF页面加入到这个可读取对象中
10 | pdf_writer.addPage(pdf_reader.getPage(page))
11 |
12 | # 把这个已合并了的PDF文档存储起来
13 | with open(output, 'wb') as out:
14 | pdf_writer.write(out)
15 |
16 | if __name__ == '__main__':
17 | paths = ['study.pdf', 'labuladong的算法小抄官方完整版.pdf']
18 | merge_pdfs(paths, output='pandas官方文档中文版.pdf')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/use/study.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/use/study.doc
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/use/study.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/use/study.pdf
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/静夜思.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/03pdf/15_合并PDF/静夜思.pdf
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/15_PPT_pptx_在PPT中写入文字/ppt_wt.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/21 20:13
3 | # @公众号 :Python自动化办公社区
4 | # @File : ppt_wt.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # pip install python-pptx
9 | from pptx import Presentation
10 | from pptx.util import Inches,Pt
11 |
12 | ppt = Presentation()
13 | slide = ppt.slides.add_slide(ppt.slide_layouts[1])# 在PPT中插入一个幻灯片
14 |
15 | body_shape = slide.shapes.placeholders
16 | # body_shape[0].text = '这是占位符0'
17 | # body_shape[1].text = '这是占位符1'
18 | #
19 | title_shape = slide.shapes.title
20 | title_shape.text = '这是标题'
21 | # subtitle = slide.shapes.placeholders[1] #取出本页第二个文本框
22 | # subtitle.text = '这是文本框'
23 | #
24 | # new_paragraph = body_shape[1].text_frame.add_paragraph()
25 | # new_paragraph.text = '新段落'
26 | # new_paragraph.font.bold = True
27 | # new_paragraph.font.italic = True
28 | # new_paragraph.font.size = Pt(15)
29 | # new_paragraph.font.underline = True
30 | #
31 | left = Inches(2)
32 | top = Inches(2)
33 | width = Inches(3)
34 | height = Inches(3)
35 | #
36 | #
37 | #
38 | textbox = slide.shapes.add_textbox(left,top,width,height)
39 | textbox.text = 'new textbox'
40 | # 如何在文本框里添加第二段文字?
41 | # new_para = textbox.text_frame.add_paragraph()
42 | # new_para.text = '第二段文字'
43 | #
44 |
45 |
46 | ppt.save('test.pptx')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/15_PPT_pptx_在PPT中写入文字/test.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/15_PPT_pptx_在PPT中写入文字/test.pptx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/img.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/img.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/ppt_img.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/22 10:03
3 | # @公众号 :Python自动化办公社区
4 | # @File : ppt_img.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # pip install python-pptx
9 | from pptx import Presentation
10 | from pptx.util import Inches,Pt
11 |
12 | ppt = Presentation()
13 | slide = ppt.slides.add_slide(ppt.slide_layouts[1])# 在PPT中插入一个幻灯片
14 |
15 | # left = Inches(1)
16 | # top = Inches(1)
17 | # width = Inches(2)
18 | # height = Inches(2)
19 | #
20 | # img = slide.shapes.add_picture('img.jpg',left,top,width,height)
21 |
22 | rows = 2
23 | cols = 2
24 | left = Inches(1)
25 | top = Inches(1)
26 | width = Inches(4)
27 | height = Inches(4)
28 |
29 | table = slide.shapes.add_table(rows,cols,left,top,width,height).table
30 | table.columns[0].width = Inches(1)
31 | table.columns[1].width = Inches(3)
32 | table.cell(0,0).text = '00'
33 | table.cell(0,1).text = '01'
34 | table.cell(1,0).text = '10'
35 | table.cell(1,1).text = '11' #二进制的11,代表十进制的多少?
36 |
37 | ppt.save('text.pptx')
38 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/text.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/text.pptx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/17_PPT_pptx_设置统一格式/text.txt:
--------------------------------------------------------------------------------
1 | 见笔记:textbook.md,
2 | 需要单独的一门课,需要的话,弹幕:666,
3 | 数量够多,我另外录制。
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/04ppt/textbook.md:
--------------------------------------------------------------------------------
1 | - python-pptx说明文档
2 | - https://pypi.org/project/python-pptx/
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/05数据可视化/course.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @公众号 :Python自动化办公社区
3 | # @File :
4 | # @Software: PyCharm
5 | # @Description:
6 |
7 | # django极简入门教程:https://www.bilibili.com/video/BV1Kz4y1r76w
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/06机器人/26_wxpy_用Python玩微信:可视化统计好友地理位置.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:24
3 | # @公众号 :Python自动化办公社区
4 | # @File : 26_wxpy_用Python玩微信:可视化统计好友地理位置.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # pip install wxpy
9 | from wxpy import *
10 |
11 | # 初始化一个机器人对象
12 | # cache_path缓存路径,给定值为第一次登录生成的缓存文件路径
13 | bot = Bot()
14 | # 获取好友列表(包括自己)
15 | my_friends = bot.friends(update=False)
16 | '''
17 | stats_text 函数:帮助我们简单统计微信好友基本信息
18 | 简单的统计结果的文本
19 | :param total: 总体数量
20 | :param sex: 性别分布
21 | :param top_provinces: 省份分布
22 | :param top_cities: 城市分布
23 | :return: 统计结果文本
24 | '''
25 | print(my_friends.stats_text())
26 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/06机器人/27_wxpy_20行Python代码,获取全部微信好友头像.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:25
3 | # @公众号 :Python自动化办公社区
4 | # @File : 27_wxpy_20行Python代码,获取全部微信好友头像.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | from wxpy import *
9 | import os,sys
10 |
11 | # 初始化机器人,扫码登陆微信,适用于Windows系统
12 | bot = Bot()
13 | # # Linux系统,执行登陆请调用下面的这句
14 | # bot = Bot(console_qr=2, cache_path="botoo.pkl"
15 | # 获取当前路径信息
16 | image_dir = os.getcwd()+'\\' + "FriendImgs\\"
17 | # 如果保存头像的FriendImgs目录不存在就创建一个
18 | if not os.path.exists(image_dir):
19 | os.mkdir(image_dir)
20 | os.popen('explorer ' + image_dir)
21 | my_friends = bot.friends(update=True)
22 | # 获取好友头像信息并存储在FriendImgs目录中
23 | n = 0
24 | for friend in my_friends:
25 | print(friend)
26 | image_name = image_dir + str(n) + '.jpg'
27 | friend.get_avatar(image_name)
28 | n = n + 1
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/06机器人/28_Python聊天机器人.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:25
3 | # @公众号 :Python自动化办公社区
4 | # @File : 28_Python聊天机器人.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # 展示
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/06机器人/ali_start.sh:
--------------------------------------------------------------------------------
1 | yum install python-setuptools
2 | easy_install pip
3 | pip install shadowsocks
4 |
5 | nohup ssserver -c shadowsocks.json -d start &
6 |
7 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/06机器人/shadowsocks.json:
--------------------------------------------------------------------------------
1 | {
2 | "server":"0.0.0.0",
3 | "local_address": "127.0.0.1",
4 | "local_port":1080,
5 | "port_password":{
6 | "18001":"123456ss"
7 | },
8 | "timeout":300,
9 | "method":"aes-256-cfb",
10 | "fast_open": false
11 | }
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/06机器人/stop.sh:
--------------------------------------------------------------------------------
1 | ssserver -c shadowsocks.json -d stop
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/07爬虫/31_spider_Python爬虫教程.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:20
3 | # @公众号 :Python自动化办公社区
4 | # @File : 31_spider_Python爬虫教程.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # 爬虫案例和源代码:https://www.bilibili.com/video/BV15E411P7ey
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/0808的更新通知.xmind:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/0808的更新通知.xmind
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/2021更新说明.xmind:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/2021更新说明.xmind
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/README.md:
--------------------------------------------------------------------------------
1 | ## 代码说明
2 | 本仓库用来存放课程代码,使用的是代码专用工具git
3 | - 每一个文件夹都可以直接打开,跟着课程一个个的使用
4 | - 如需下载全部代码到本地,请查看这个10分钟的git使用教程:[重要!GitHub的下载和使用教程~(附:开放我的社区全部代码仓)](https://www.bilibili.com/video/BV1Ry4y1m7Ai?spm_id_from=333.999.0.0)
5 |
6 | ## 课程说明
7 | 本套课程,录制于2021年5月,
8 | 也欢迎大家通过提交pull request的形式,和我一起丰富这套课程的代码~
9 | 我的微信:[点击查看](http://python4office.cn/wechat-qrcode/)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/图片/excel的学习顺序.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/图片/excel的学习顺序.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/更多Python学习资源.md:
--------------------------------------------------------------------------------
1 | - 免费获取精选Python技术资源
2 | https://mp.weixin.qq.com/s/-4mPV9G5_vgAD0fBg74asg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/答疑群.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(2021最新版!有源代码 ,适合小白~)/答疑群.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/00demo/cmder/cmder.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/28 19:39
3 | # @Author :liuzf
4 | # @File : cmder.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 |
9 | from docx import Document
10 | from docx.enum.text import WD_ALIGN_PARAGRAPH
11 | from docx.shared import Pt
12 | from docx.oxml.ns import qn
13 |
14 | import time
15 |
16 | # price = input('请输入工资调整金额:')
17 | # 全体员工姓名
18 | # company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10' ]
19 | # 当天的日期
20 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
21 |
22 | for i in range(1,40):
23 | price = 200
24 | document = Document()
25 | # 设置文档的基础字体
26 | document.styles['Normal'].font.name = u'宋体'
27 | # 识别中文
28 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
29 |
30 | # 建立一个自然段
31 | p1 = document.add_paragraph()
32 | # 对齐方式为居中,没有这句的话默认左对齐
33 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
34 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
35 | run1.font.name = '微软雅黑'
36 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
37 | run1.font.size = Pt(21)
38 | run1.font.bold = True
39 | p1.space_after = Pt(5)
40 | p1.space_before = Pt(5)
41 |
42 | p2 = document.add_paragraph()
43 | run2 = p2.add_run(str(i) + ':')
44 | run2.font.name = '宋体'
45 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
46 | run2.font.size = Pt(16)
47 | run2.font.bold = True
48 |
49 | p3 = document.add_paragraph()
50 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知' % price)
51 | run3.font.name = '宋体'
52 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
53 | run3.font.size = Pt(14)
54 |
55 | p4 = document.add_paragraph()
56 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
57 | run4 = p4.add_run('人事:王小姐 电话:686868')
58 | run4.font.name = '宋体'
59 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
60 | run4.font.size = Pt(14)
61 | run4.font.bold = True
62 |
63 |
64 | document.save('%s-工资调整通知.docx' % i)
65 |
66 |
67 |
68 | print(666)
69 | print(888)
70 |
71 |
72 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/00demo/problem/test.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/00demo/problem/test.doc
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/7月下旬入库表.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/7月下旬入库表.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/read.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/18 18:35
3 | # @公众号 :Python自动化办公社区
4 | # @File : read.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import xlrd
9 |
10 | xlsx = xlrd.open_workbook('7月下旬入库表.xlsx')
11 |
12 | sheet = xlsx.sheet_by_index(0)
13 | # 通过sheet名查找:xlsx.sheet_by_name("7月下旬入库表")
14 | # 通过索引查找:xlsx.sheet_by_index(3)
15 | # print(table.cell_value(0, 0))
16 |
17 | # print(sheet.cell_value(1, 2))
18 | # print(sheet.cell(0, 0).value)
19 | # print(sheet.row(0)[0].value)
20 |
21 |
22 | # for i in range(0, xlsx.nsheets):
23 | # sheet = xlsx.sheet_by_index(i)
24 | # print(sheet.name)
25 | # print(sheet.cell_value(0, 0))
26 | #
27 | # # 获取所有sheet名字:xlsx.sheet_names()
28 | # # 获取sheet数量:xlsx.nsheets
29 | #
30 | for i in xlsx.sheet_names():
31 | print(i)
32 | # table = xlsx.sheet_by_name(i)
33 | # print(table.cell_value(3, 3))
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/test.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/test.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/001_Excel_xlrd读_xlwt写/write.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/18 19:04
3 | # @公众号 :Python自动化办公社区
4 | # @File : write.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import xlwt
9 | # 新建工作簿
10 | new_workbook = xlwt.Workbook()
11 | # 新建sheet
12 | worksheet = new_workbook.add_sheet('new_test')
13 | # 新建单元格,并写入内容
14 | worksheet.write(0, 0, 'test')
15 | # 保存
16 | new_workbook.save('test.xls')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/format.py:
--------------------------------------------------------------------------------
1 | from xlutils.copy import copy
2 | import xlrd
3 | import xlwt
4 |
5 | tem_excel = xlrd.open_workbook('日统计.xls', formatting_info=True)
6 | tem_sheet = tem_excel.sheet_by_index(0)
7 |
8 | new_excel = copy(tem_excel)
9 | new_sheet = new_excel.get_sheet(0)
10 |
11 | style = xlwt.XFStyle()
12 |
13 | # 字体
14 | font = xlwt.Font()
15 | font.name = '微软雅黑'
16 | font.bold = True
17 | # 18*20
18 | font.height = 360
19 | style.font = font
20 |
21 | # 边框:细线==THIN
22 | borders = xlwt.Borders()
23 | borders.top = xlwt.Borders.THIN
24 | borders.bottom = xlwt.Borders.THIN
25 | borders.left = xlwt.Borders.THIN
26 | borders.right = xlwt.Borders.THIN
27 | style.borders = borders
28 |
29 | # 对齐
30 | alignment = xlwt.Alignment()
31 | alignment.horz = xlwt.Alignment.HORZ_CENTER
32 | alignment.vert = xlwt.Alignment.VERT_CENTER
33 | style.alignment = alignment
34 |
35 |
36 | new_sheet.write(2, 1, 12)
37 | new_sheet.write(3, 1, 18)
38 | new_sheet.write(4, 1, 19)
39 | new_sheet.write(5, 1, 15)
40 |
41 |
42 | # new_sheet.write(2, 1, 12, style)
43 | # new_sheet.write(3, 1, 18, style)
44 | # new_sheet.write(4, 1, 19, style)
45 | # new_sheet.write(5, 1, 15, style)
46 |
47 | new_excel.save('填写.xls')
48 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/日统计.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/002_Excel_xlutils设置格式/日统计.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/0701SUM.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/19 19:03
3 | # @公众号 :Python自动化办公社区
4 | # @File : 0701SUM.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import xlrd
9 | import xlwt
10 |
11 | # 读取excel文件
12 | xlsx = xlrd.open_workbook('三年二班(各科成绩单).xls')
13 | # 选择指定sheet
14 | sheet = xlsx.sheet_by_index(0)
15 | # 依次单元格数据,并统计总分
16 | all_data = []
17 | # 统计共有多少学生,并去重
18 | num_set = set()
19 | for row_i in range(1, sheet.nrows):
20 | num = sheet.cell_value(row_i, 0)
21 | name = sheet.cell_value(row_i, 1)
22 | grade = sheet.cell_value(row_i, 3)
23 |
24 | student = {
25 | 'num': num,
26 | 'name': name,
27 | 'grade': grade,
28 | }
29 | all_data.append(student)
30 | num_set.add(num)
31 | # print(all_data)
32 | # print(len(all_data))
33 | # print(len(num_set))
34 |
35 | # 计算总分
36 | sum_list = []
37 | for num in num_set:
38 | name = ''
39 | sum = 0
40 | for student in all_data:
41 | # print(student['num'])
42 | # print(num)
43 | if num == student['num']:
44 | sum += student['grade']
45 | name = student['name']
46 | sum_stu = {
47 | 'num': num,
48 | 'name': name,
49 | 'sum': sum
50 | }
51 | sum_list.append(sum_stu)
52 | print(sum_list)
53 |
54 | # 写入新的excel
55 |
56 | # 新建工作簿
57 | new_workbook = xlwt.Workbook()
58 | # 新建sheet
59 | worksheet = new_workbook.add_sheet('2班')
60 | # 新建单元格,并写入内容
61 | # 写入第一列的内容
62 | worksheet.write(0, 0, '学号')
63 | worksheet.write(0, 1, '姓名')
64 | worksheet.write(0, 2, '总分')
65 | # 自动写入后面的内容
66 | for row in range(0,len(sum_list)):
67 | worksheet.write(row+1,0,sum_list[row]['num'])
68 | worksheet.write(row+1,1,sum_list[row]['name'])
69 | worksheet.write(row+1,2,sum_list[row]['sum'])
70 | # 保存
71 | new_workbook.save('2班学生总分.xls')
72 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/2班学生总分.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/2班学生总分.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/三年二班(各科成绩单).xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/003_Excel_案例_统计每位同学总分/三年二班(各科成绩单).xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/005_Excel_更灵活的操作方式_xlsxwriter_openpyxl/num_open.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/005_Excel_更灵活的操作方式_xlsxwriter_openpyxl/num_open.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/005_Excel_更灵活的操作方式_xlsxwriter_openpyxl/number.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/005_Excel_更灵活的操作方式_xlsxwriter_openpyxl/number.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/005_Excel_更灵活的操作方式_xlsxwriter_openpyxl/writer_openpyxl.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 17:16
3 | # @公众号 :Python自动化办公社区
4 | # @File : writer_openpyxl.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # import xlwt
9 | #
10 | # workbook = xlwt.Workbook()
11 | # sheet0 = workbook.add_sheet('sheet0')
12 | # for i in range(0,300):
13 | # sheet0.write(0,i,i)
14 | # workbook.save('num.xls')
15 |
16 | # 不带格式
17 | import xlsxwriter as xw
18 | workbook = xw.Workbook('number.xlsx')
19 | sheet0 = workbook.add_worksheet('sheet0')
20 | for i in range(0,300):
21 | sheet0.write(0,i,i)
22 | workbook.close()
23 |
24 |
25 | # 性能不稳定
26 | import openpyxl
27 | workbook = openpyxl.load_workbook('number.xlsx')
28 | sheet0 = workbook['sheet0']
29 | sheet0['B3']= '2'
30 | sheet0['C2']= '4'
31 | sheet0['D7']= '3'
32 | workbook.save('num_open.xlsx')
33 |
34 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/006_Excel_案例_把文件夹整理到Excel中/dir.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 17:42
3 | # @公众号 :Python自动化办公社区
4 | # @File : dir.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import os
9 | import xlwt
10 |
11 | # 目标文件夹
12 | file_path = 'd:/'
13 | # 取出目标文件夹下的文件名
14 | os.listdir(file_path)
15 |
16 | new_workbook = xlwt.Workbook()
17 | sheet = new_workbook.add_sheet('new_dir')
18 |
19 | n = 0
20 | for i in os.listdir(file_path):
21 | sheet.write(n,0,i)
22 | n+=1
23 | new_workbook.save('dir.xls')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/006_Excel_案例_把文件夹整理到Excel中/dir.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/006_Excel_案例_把文件夹整理到Excel中/dir.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/0407.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/0407.xlsx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/111.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/111.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/007_Excel_案例_用Excel画画/image2excel.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 |
3 | from PIL import Image
4 | from xlsxwriter.workbook import Workbook
5 |
6 |
7 | class ExcelPicture(object):
8 | FORMAT_CONSTRAINT = 65536
9 |
10 | def __init__(self, pic_file, ratio=0.5):
11 | self.__pic_file = pic_file
12 |
13 | self.__ratio = ratio
14 | self.__zoomed_out = False
15 |
16 | self.__formats = dict()
17 |
18 | # 缩小图片
19 | def zoom_out(self, _img):
20 | _size = _img.size
21 | _img.thumbnail((int(_img.size[0] * self.__ratio), int(_img.size[1] * self.__ratio)))
22 |
23 | self.__zoomed_out = True
24 |
25 | # 对颜色进行圆整
26 | def round_rgb(self, rgb, model):
27 | return tuple([int(round(x / model) * model) for x in rgb])
28 |
29 | # 查找颜色样式,去重
30 | def get_format(self, color):
31 | _format = self.__formats.get(color, None)
32 |
33 | if _format is None:
34 | _format = self.__wb.add_format({'bg_color': color})
35 | self.__formats[color] = _format
36 |
37 | return _format
38 |
39 | # 操作流程
40 | def process(self, output_file='_pic.xlsx', color_rounding=False, color_rounding_model=5.0):
41 | # 创建xlsx文件,并调整行列属性
42 | self.__wb = Workbook(output_file)
43 | self.__sht = self.__wb.add_worksheet()
44 | self.__sht.set_default_row(height=9)
45 | self.__sht.set_column(0, 5000, width=1)
46 |
47 | # 打开需要进行转换的图片
48 | _img = Image.open(self.__pic_file)
49 | print ('Picture filename:', self.__pic_file)
50 |
51 | # 判断是否需要缩小图片尺寸
52 | if self.__ratio < 1:
53 | self.zoom_out(_img)
54 |
55 | # 遍历每一个像素点,并填充对应的颜色到对应的Excel单元格
56 | _size = _img.size
57 | print('Picture size:', _size)
58 | for (x, y) in [(x, y) for x in range(_size[0]) for y in range(_size[1])]:
59 | _clr = _img.getpixel((x, y))
60 |
61 | # 如果颜色种类过多,则需要将颜色圆整到近似的颜色上,以减少颜色种类
62 | if color_rounding: _clr = self.round_rgb(_clr, color_rounding_model)
63 |
64 | _color = '#%02X%02X%02X' % _clr
65 | self.__sht.write(y, x, '', self.get_format(_color))
66 |
67 | self.__wb.close()
68 |
69 | # 检查颜色样式种类是否超出限制,Excel2007对样式数量有最大限制
70 | format_size = len(self.__formats.keys())
71 | if format_size >= ExcelPicture.FORMAT_CONSTRAINT:
72 | print('Failed! Color size overflow: %s.' % format_size)
73 | else:
74 | print ('Success!')
75 | print ('Color: %s' % format_size)
76 | print ('Color_rounding:', color_rounding)
77 | if color_rounding:
78 | print ('Color_rounding_model:', color_rounding_model)
79 |
80 |
81 | if __name__ == '__main__':
82 | r = ExcelPicture('111.jpg', ratio=0.5)
83 | r.process('0407.xlsx', color_rounding=True, color_rounding_model=5.0)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/01excel/textbook.md:
--------------------------------------------------------------------------------
1 | - excel:
2 | - 文件.xlsx
3 | - sheet
4 | - 单元格:a1/a2/b3/c6
5 | - xlrd
6 | - 读excel
7 |
8 | - xlwt
9 | - 写excel
10 |
11 | - xlutils
12 | - 设置单元格格式(选学)
13 |
14 | - 统计3年2班学生总分
15 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/008_Word_docx_批量把文字写入Word/write_doc.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 18:10
3 | # @公众号 :Python自动化办公社区
4 | # @File : write_doc.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | from docx import Document
9 | from docx.enum.text import WD_ALIGN_PARAGRAPH
10 | from docx.shared import Pt
11 | from docx.oxml.ns import qn
12 |
13 | import time
14 |
15 | price = input('请输入工资调整金额:')
16 | # 全体员工姓名
17 | company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10' ]
18 | # 当天的日期
19 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
20 |
21 | for i in company_list:
22 | document = Document()
23 | # 设置文档的基础字体
24 | document.styles['Normal'].font.name = u'宋体'
25 | # 识别中文
26 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
27 |
28 | # 建立一个自然段
29 | p1 = document.add_paragraph()
30 | # 对齐方式为居中,没有这句的话默认左对齐
31 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
32 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
33 | run1.font.name = '微软雅黑'
34 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
35 | run1.font.size = Pt(21)
36 | run1.font.bold = True
37 | p1.space_after = Pt(5)
38 | p1.space_before = Pt(5)
39 |
40 | p2 = document.add_paragraph()
41 | run2 = p2.add_run(i + ':')
42 | run2.font.name = '宋体'
43 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
44 | run2.font.size = Pt(16)
45 | run2.font.bold = True
46 |
47 | p3 = document.add_paragraph()
48 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知' % price)
49 | run3.font.name = '宋体'
50 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
51 | run3.font.size = Pt(14)
52 |
53 | p4 = document.add_paragraph()
54 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
55 | run4 = p4.add_run('人事:王小姐 电话:686868')
56 | run4.font.name = '宋体'
57 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
58 | run4.font.size = Pt(14)
59 | run4.font.bold = True
60 |
61 |
62 | document.save('%s-工资调整通知.docx' % i)
63 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/009_Word_docx_批量把图片和表格写入Word/img_table.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 18:49
3 | # @公众号 :Python自动化办公社区
4 | # @File : img_table.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 |
9 | from docx import Document
10 | from docx.enum.text import WD_ALIGN_PARAGRAPH
11 | from docx.shared import Pt
12 | from docx.oxml.ns import qn
13 | from docx.shared import Inches
14 |
15 | import time
16 |
17 | price = input('请输入工资调整金额:')
18 | company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10', ]
19 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
20 | for i in company_list:
21 | document = Document()
22 | # 设置文档的基础字体
23 | document.styles['Normal'].font.name = u'宋体'
24 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
25 | # 红头文件
26 | document.add_picture('title002.jpg', width=Inches(6))
27 |
28 | # 建立一个自然段
29 | p1 = document.add_paragraph()
30 | # 对齐方式为居中,没有这句的话默认左对齐
31 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
32 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
33 | run1.font.name = '微软雅黑'
34 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
35 | run1.font.size = Pt(21)
36 | run1.font.bold = True
37 | p1.space_after = Pt(5)
38 | p1.space_before = Pt(5)
39 |
40 | p2 = document.add_paragraph()
41 | run2 = p2.add_run(i + ':')
42 | run2.font.name = '宋体'
43 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
44 | run2.font.size = Pt(16)
45 | run2.font.bold = True
46 |
47 | p3 = document.add_paragraph()
48 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知。' % price)
49 | run3.font.name = '宋体'
50 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
51 | run3.font.size = Pt(14)
52 |
53 | table = document.add_table(rows=2, cols=2, style='Table Grid')
54 | # 合并单元格
55 | table.cell(0, 0).merge(table.cell(0, 1))
56 | table_run1 = table.cell(0, 0).paragraphs[0].add_run('签名栏')
57 | table_run1.font.name = '黑体'
58 | table_run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'黑体')
59 | table.cell(0, 0).paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
60 | table.cell(1, 0).text = i
61 | table.cell(1, 0).paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
62 |
63 | p4 = document.add_paragraph()
64 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
65 |
66 | run4 = p4.add_run('人事:王小姐 电话:686868')
67 | run4.font.name = '宋体'
68 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
69 | run4.font.size = Pt(14)
70 | run4.font.bold = True
71 |
72 | document.save('%s-工资调整通知.docx' % i)
73 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/009_Word_docx_批量把图片和表格写入Word/title002.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/009_Word_docx_批量把图片和表格写入Word/title002.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/pure.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/pure.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/pure.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 19:10
3 | # @公众号 :Python自动化办公社区
4 | # @File : pure.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | from docx import Document
9 | document = Document('pure.docx')
10 | all_paragraphs = document.paragraphs
11 | for p in all_paragraphs:
12 | print(p.text)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/word_table.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/word_table.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/010_Word_docx_读取word/word_table.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 19:10
3 | # @公众号 :Python自动化办公社区
4 | # @File : word_table.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import zipfile
9 |
10 | word_book = zipfile.ZipFile('word_table.docx')
11 | xml = word_book.read("word/document.xml").decode('utf-8')
12 | # print(xml)
13 | xml_list = xml.split('')
14 | print(xml_list)
15 | text_list = []
16 | for i in xml_list:
17 | if i.find('') + 1:
18 | text_list.append(i[:i.find('')])
19 | else:
20 | pass
21 | text = "".join(text_list)
22 | print(text)
23 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/012_Word_word转pdf/test.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/012_Word_word转pdf/test.docx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/012_Word_word转pdf/word2pdf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 20:47
3 | # @公众号 :Python自动化办公社区
4 | # @File : word2pdf.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | from win32com.client import Dispatch,constants,gencache
9 |
10 | doc_path = 'test.docx'
11 | pdf_path = 'test.pdf'
12 |
13 | gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}',0,8,4)
14 | wd = Dispatch("Word.Application")
15 | doc = wd.Documents.Open(doc_path,ReadOnly=1)
16 | doc.ExportAsFixedFormat(pdf_path,constants.wdExportFormatPDF,Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
17 | wd.Quit(constants.wdDoNotSaveChanges)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/013_Word_word批量转pdf,效率提高10倍/words2pdfs.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/20 22:52
3 | # @公众号 :Python自动化办公社区
4 | # @File : words2pdfs.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import os
9 | from win32com.client import Dispatch,constants,gencache
10 |
11 |
12 |
13 | from docx import Document
14 | from docx.enum.text import WD_ALIGN_PARAGRAPH
15 | from docx.shared import Pt
16 | from docx.oxml.ns import qn
17 |
18 | import time
19 |
20 | price = input('请输入工资调整金额:')
21 | # 全体员工姓名
22 | company_list = ['员工1', '员工1', '员工2', '员工3', '员工4', '员工5', '员工6', '员工7', '员工8', '员工9', '员工10' ]
23 | # 当天的日期
24 | today = time.strftime("%Y{y}%m{m}%d{d}", time.localtime()).format(y='年', m='月', d='日')
25 |
26 | for i in company_list:
27 | document = Document()
28 | # 设置文档的基础字体
29 | document.styles['Normal'].font.name = u'宋体'
30 | # 识别中文
31 | document.styles['Normal'].element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
32 |
33 | # 建立一个自然段
34 | p1 = document.add_paragraph()
35 | # 对齐方式为居中,没有这句的话默认左对齐
36 | p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
37 | run1 = p1.add_run('关于%s工资调整的通知' % (today))
38 | run1.font.name = '微软雅黑'
39 | run1.element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
40 | run1.font.size = Pt(21)
41 | run1.font.bold = True
42 | p1.space_after = Pt(5)
43 | p1.space_before = Pt(5)
44 |
45 | p2 = document.add_paragraph()
46 | run2 = p2.add_run(i + ':')
47 | run2.font.name = '宋体'
48 | run2.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
49 | run2.font.size = Pt(16)
50 | run2.font.bold = True
51 |
52 | p3 = document.add_paragraph()
53 | run3 = p3.add_run('因为疫情影响,我们很抱歉的通知您,您的工资调整为每月%s元,特此通知' % price)
54 | run3.font.name = '宋体'
55 | run3.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
56 | run3.font.size = Pt(14)
57 |
58 | p4 = document.add_paragraph()
59 | p4.alignment = WD_ALIGN_PARAGRAPH.RIGHT
60 | run4 = p4.add_run('人事:王小姐 电话:686868')
61 | run4.font.name = '宋体'
62 | run4.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
63 | run4.font.size = Pt(14)
64 | run4.font.bold = True
65 |
66 |
67 | document.save('%s-工资调整通知.docx' % i)
68 |
69 | doc_path = '%s-工资调整通知.docx' % i
70 | pdf_path = '%s-工资调整通知.pdf' % i
71 |
72 | gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}',0,8,4)
73 | wd = Dispatch("Word.Application")
74 | doc = wd.Documents.Open(doc_path,ReadOnly=1)
75 | doc.ExportAsFixedFormat(pdf_path,constants.wdExportFormatPDF,Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
76 | wd.Quit(constants.wdDoNotSaveChanges)
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/02word/textbook.md:
--------------------------------------------------------------------------------
1 | - python-docx
2 | - 说明文档:https://python-docx.readthedocs.io/en/latest/#api-documentation
3 |
4 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/pdf_rd.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/21 20:04
3 | # @公众号 :Python自动化办公社区
4 | # @File : pdf_rd.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 |
9 | # pip install pdfminer3k
10 | from io import StringIO
11 | from pdfminer.pdfinterp import PDFResourceManager,process_pdf
12 | from pdfminer.converter import TextConverter
13 | from pdfminer.layout import LAParams
14 |
15 | # 打开pdf文件
16 | pdf_file = open('静夜思.pdf', 'rb')
17 |
18 | ########默认操作#######
19 | rsrcmgr = PDFResourceManager()
20 | retstr = StringIO()
21 | laparams = LAParams()
22 | device = TextConverter(rsrcmgr=rsrcmgr,outfp=retstr,laparams=laparams)
23 | process_pdf(rsrcmgr=rsrcmgr,device=device,fp=pdf_file)
24 | device.close()
25 | content = retstr.getvalue()
26 | retstr.close()
27 | pdf_file.close()
28 | ########默认操作#######
29 |
30 | print(content)
31 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.doc
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/03pdf/14_PDF_识别并读取PDF中的文字/静夜思.pdf
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/15_PPT_pptx_在PPT中写入文字/ppt_wt.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/21 20:13
3 | # @公众号 :Python自动化办公社区
4 | # @File : ppt_wt.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # pip install python-pptx
9 | from pptx import Presentation
10 | from pptx.util import Inches,Pt
11 |
12 | ppt = Presentation()
13 | slide = ppt.slides.add_slide(ppt.slide_layouts[1])# 在PPT中插入一个幻灯片
14 |
15 | body_shape = slide.shapes.placeholders
16 | # body_shape[0].text = '这是占位符0'
17 | # body_shape[1].text = '这是占位符1'
18 | #
19 | title_shape = slide.shapes.title
20 | title_shape.text = '这是标题'
21 | # subtitle = slide.shapes.placeholders[1] #取出本页第二个文本框
22 | # subtitle.text = '这是文本框'
23 | #
24 | # new_paragraph = body_shape[1].text_frame.add_paragraph()
25 | # new_paragraph.text = '新段落'
26 | # new_paragraph.font.bold = True
27 | # new_paragraph.font.italic = True
28 | # new_paragraph.font.size = Pt(15)
29 | # new_paragraph.font.underline = True
30 | #
31 | left = Inches(2)
32 | top = Inches(2)
33 | width = Inches(3)
34 | height = Inches(3)
35 | #
36 | #
37 | #
38 | textbox = slide.shapes.add_textbox(left,top,width,height)
39 | textbox.text = 'new textbox'
40 | # 如何在文本框里添加第二段文字?
41 | # new_para = textbox.text_frame.add_paragraph()
42 | # new_para.text = '第二段文字'
43 | #
44 |
45 |
46 | ppt.save('test.pptx')
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/15_PPT_pptx_在PPT中写入文字/test.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/15_PPT_pptx_在PPT中写入文字/test.pptx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/img.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/img.jpg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/ppt_img.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/22 10:03
3 | # @公众号 :Python自动化办公社区
4 | # @File : ppt_img.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # pip install python-pptx
9 | from pptx import Presentation
10 | from pptx.util import Inches,Pt
11 |
12 | ppt = Presentation()
13 | slide = ppt.slides.add_slide(ppt.slide_layouts[1])# 在PPT中插入一个幻灯片
14 |
15 | # left = Inches(1)
16 | # top = Inches(1)
17 | # width = Inches(2)
18 | # height = Inches(2)
19 | #
20 | # img = slide.shapes.add_picture('img.jpg',left,top,width,height)
21 |
22 | rows = 2
23 | cols = 2
24 | left = Inches(1)
25 | top = Inches(1)
26 | width = Inches(4)
27 | height = Inches(4)
28 |
29 | table = slide.shapes.add_table(rows,cols,left,top,width,height).table
30 | table.columns[0].width = Inches(1)
31 | table.columns[1].width = Inches(3)
32 | table.cell(0,0).text = '00'
33 | table.cell(0,1).text = '01'
34 | table.cell(1,0).text = '10'
35 | table.cell(1,1).text = '11' #二进制的11,代表十进制的多少?
36 |
37 | ppt.save('text.pptx')
38 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/text.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/16_PPT_pptx_在PPT中写入图片和表格/text.pptx
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/17_PPT_pptx_设置统一格式/text.txt:
--------------------------------------------------------------------------------
1 | 见笔记:textbook.md,
2 | 需要单独的一门课,需要的话,弹幕:666,
3 | 数量够多,我另外录制。
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/04ppt/textbook.md:
--------------------------------------------------------------------------------
1 | - python-pptx说明文档
2 | - https://pypi.org/project/python-pptx/
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/06_email/23_用Python发送普通的文字邮件.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:15
3 | # @公众号 :Python自动化办公社区
4 | # @File : 23_用Python发送普通的文字邮件.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | import smtplib
9 | from smtplib import SMTP_SSL
10 | from email.mime.text import MIMEText
11 | from email.mime.multipart import MIMEMultipart
12 | from email.header import Header
13 |
14 | host_server = 'smtp.sina.com'
15 | sender_sina = 'your_email@sina.com'
16 | pwd = 'your_pwd'
17 |
18 | sender_sina_mail = 'your_email@sina.com'
19 | receiver = 'others_email@sina.com'
20 | mail_title = '这是标题'
21 | mail_content = '这是正文'
22 | msg = MIMEMultipart()
23 | msg['Subject'] = Header(mail_title, 'utf-8')
24 | msg['From'] = sender_sina_mail
25 | msg['To'] = Header('mail_title', 'utf-8')
26 | msg.attach(MIMEText(mail_content, 'plain', 'utf-8'))
27 |
28 | smtp = SMTP_SSL(host_server)
29 | smtp.login(sender_sina,pwd)
30 | smtp.sendmail(sender_sina_mail,receiver,msg.as_string())
31 | smtp.quit()
32 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/06_email/24_用Python发送带附件的邮件.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:22
3 | # @公众号 :Python自动化办公社区
4 | # @File : 24_用Python发送带附件的邮件.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # -*- coding: utf-8 -*-
9 | # @Time : 2020/8/23 2:15
10 | # @公众号 :Python自动化办公社区
11 | # @File : 23_用Python发送普通的文字邮件.py
12 | # @Software: PyCharm
13 | # @Description:
14 |
15 | import smtplib
16 | from smtplib import SMTP_SSL
17 | from email.mime.text import MIMEText
18 | from email.mime.multipart import MIMEMultipart
19 | from email.mime.application import MIMEApplication
20 | from email.header import Header
21 |
22 | host_server = 'smtp.sina.com'
23 | sender_sina = 'your_email@sina.com'
24 | pwd = 'your_pwd'
25 |
26 | sender_sina_mail = 'your_email@sina.com'
27 | receiver = 'others_email@sina.com'
28 | mail_title = '这是标题'
29 | mail_content = '这是正文'
30 | msg = MIMEMultipart()
31 | msg['Subject'] = Header(mail_title, 'utf-8')
32 | msg['From'] = sender_sina_mail
33 | msg['To'] = Header('mail_title', 'utf-8')
34 | msg.attach(MIMEText(mail_content, 'html', 'utf-8'))
35 | # 添加附件
36 | attachment = MIMEApplication(open('student.xls', 'rb').read())
37 | attachment.add_header('Content-Disposition', 'attachment', filename='student.xls')
38 | msg.attach(attachment)
39 | try:
40 | smtp = SMTP_SSL(host_server)
41 | smtp.set_debuglevel(1)
42 | smtp.ehlo(host_server)
43 | smtp.login(sender_sina, pwd)
44 | smtp.sendmail(sender_sina_mail, receiver, msg.as_string())
45 | smtp.quit()
46 | print('success')
47 | except smtplib.SMTPException:
48 | print('error')
49 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/06_email/student.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/06_email/student.xls
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/07web/25_web_入门教程看这里.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:16
3 | # @公众号 :Python自动化办公社区
4 | # @File : 25_web_入门教程看这里.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # django极简入门教程:https://www.bilibili.com/video/BV1zi4y1t7YU
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/08wxpy/26_wxpy_用Python玩微信:可视化统计好友地理位置.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:24
3 | # @公众号 :Python自动化办公社区
4 | # @File : 26_wxpy_用Python玩微信:可视化统计好友地理位置.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # pip install wxpy
9 | from wxpy import *
10 |
11 | # 初始化一个机器人对象
12 | # cache_path缓存路径,给定值为第一次登录生成的缓存文件路径
13 | bot = Bot()
14 | # 获取好友列表(包括自己)
15 | my_friends = bot.friends(update=False)
16 | '''
17 | stats_text 函数:帮助我们简单统计微信好友基本信息
18 | 简单的统计结果的文本
19 | :param total: 总体数量
20 | :param sex: 性别分布
21 | :param top_provinces: 省份分布
22 | :param top_cities: 城市分布
23 | :return: 统计结果文本
24 | '''
25 | print(my_friends.stats_text())
26 |
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/08wxpy/27_wxpy_20行Python代码,获取全部微信好友头像.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:25
3 | # @公众号 :Python自动化办公社区
4 | # @File : 27_wxpy_20行Python代码,获取全部微信好友头像.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | from wxpy import *
9 | import os,sys
10 |
11 | # 初始化机器人,扫码登陆微信,适用于Windows系统
12 | bot = Bot()
13 | # # Linux系统,执行登陆请调用下面的这句
14 | # bot = Bot(console_qr=2, cache_path="botoo.pkl"
15 | # 获取当前路径信息
16 | image_dir = os.getcwd()+'\\' + "FriendImgs\\"
17 | # 如果保存头像的FriendImgs目录不存在就创建一个
18 | if not os.path.exists(image_dir):
19 | os.mkdir(image_dir)
20 | os.popen('explorer ' + image_dir)
21 | my_friends = bot.friends(update=True)
22 | # 获取好友头像信息并存储在FriendImgs目录中
23 | n = 0
24 | for friend in my_friends:
25 | print(friend)
26 | image_name = image_dir + str(n) + '.jpg'
27 | friend.get_avatar(image_name)
28 | n = n + 1
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/08wxpy/28_Python聊天机器人.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:25
3 | # @公众号 :Python自动化办公社区
4 | # @File : 28_Python聊天机器人.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # 展示
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/09spider/31_spider_Python爬虫教程.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Time : 2020/8/23 2:20
3 | # @公众号 :Python自动化办公社区
4 | # @File : 31_spider_Python爬虫教程.py
5 | # @Software: PyCharm
6 | # @Description:
7 |
8 | # 爬虫案例和源代码:https://www.bilibili.com/video/BV15E411P7ey
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/更多Python学习资源.md:
--------------------------------------------------------------------------------
1 | - 免费获取精选Python技术资源
2 | https://mp.weixin.qq.com/s/-4mPV9G5_vgAD0fBg74asg
--------------------------------------------------------------------------------
/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/答疑群.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/CourseCode/Python自动化办公(可能是B站内容最全的!有源代码 ,适合小白~)/答疑群.jpg
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 程序员晚枫
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python自动化办公学习指南
2 |
3 | ### 项目介绍
4 | 本项目旨在整理所有Python + 自动化办公的技术资料。
5 | 创建人:[程序员晚枫](https://mp.weixin.qq.com/s/brapCp8aZxIOjgE8qLWs3A) , 个人网站:www.python4office.cn
6 | 欢迎大家提交PR(pull request),一起来丰富这个项目!
7 |
8 | ### 主要内容
9 |
10 | #### Excel
11 | Python操作Excel的库最多,一共有9个~
12 | - [Python操作Excel的9个库,你觉得哪个更好呢?](https://mp.weixin.qq.com/s/elkIG3doSityx2n0AmjT_Q)
13 | - 参考资料:https://www.python-excel.org/
14 | ------
15 | - xlrd
16 | - [下载](https://pypi.org/project/xlrd/)
17 | - [文字教程](http://xlrd.readthedocs.io/en/latest/)
18 | - [视频教程](https://www.bilibili.com/video/BV1y54y1i78U?p=13)
19 | - xlwt
20 | - [下载](https://pypi.python.org/pypi/xlwt)
21 | - [文字教程](https://xlwt.readthedocs.io/en/latest/)
22 | - [视频教程](https://www.bilibili.com/video/BV1y54y1i78U?p=13)
23 | - xlutils
24 | - [下载](https://pypi.python.org/pypi/xlutils)
25 | - [文字教程](https://xlutils.readthedocs.io/en/latest/)
26 | - [视频教程](https://www.bilibili.com/video/BV1y54y1i78U?p=14)
27 | - xlwings
28 | - [下载](https://pypi.org/project/xlwings/)
29 | - [文字教程](https://docs.xlwings.org/en/stable/)
30 | - [视频教程](https://www.bilibili.com/video/BV1my4y1x7NQ)
31 | - openpyxl
32 | - [下载](https://pypi.python.org/pypi/openpyxl)
33 | - [文字教程](https://openpyxl.readthedocs.io/en/stable/)
34 | - [视频教程](https://www.bilibili.com/video/BV1eM4y1A7JR)
35 | - xlswriter
36 | - [下载](https://pypi.python.org/pypi/XlsxWriter)
37 | - [文字教程](https://xlsxwriter.readthedocs.io/)
38 | - [视频教程](https://www.bilibili.com/video/BV1y54y1i78U?p=18)
39 | - pandas
40 | - [下载]()
41 | - [文字教程](https://pandas.pydata.org/)
42 | - [视频教程](https://www.bilibili.com/video/BV1hk4y1C73S)
43 | - PyXLL
44 | - [下载](https://www.pyxll.com/download.html)
45 | - [文字教程](https://mp.weixin.qq.com/s/eczI5fe2xg42563ksDGcxA)
46 | - 拓展
47 | - Go语言处理Excel:https://github.com/qax-os/excelize
48 | #### Word
49 |
50 | - python-docx
51 | - [下载](http://pypi.python.org/pypi/python-docx)
52 | - [文字教程](https://python-docx.readthedocs.io/en/latest/)
53 | - [视频教程](https://www.bilibili.com/video/BV1hy4y187eQ)
54 |
55 | #### PPT
56 |
57 | - python-pptx
58 | - [下载](http://pypi.python.org/pypi/python-pptx)
59 | - [文字教程](https://python-pptx.readthedocs.io/en/latest/)
60 | - [视频教程](https://www.bilibili.com/video/BV1564y127Ws)
61 |
62 | #### PDF
63 |
64 | - [PyPDF2](https://www.bilibili.com/video/BV18V411J7Cy)
65 | - [下载](https://pypi.org/project/PyPDF2/)
66 | - [文字教程](https://pypdf2.readthedocs.io/en/latest/)
67 | - [视频教程](https://www.bilibili.com/video/BV18V411J7Cy)
68 |
69 | #### 爬虫
70 |
71 | - scrapy
72 | - [文字教程](https://scrapy.org/)
73 | - [视频教程](https://www.bilibili.com/video/BV1LV411m7Ym)
74 |
75 | #### 网站开发
76 | - django
77 | - [文字教程](https://www.djangoproject.com/)
78 | - [视频教程](https://mp.weixin.qq.com/s/2BPiuy_gRA4j6CTWG7jVtQ)
79 |
80 | #### 数据分析 & 数据可视化
81 | - pandas
82 | - [下载]()
83 | - [文字教程](https://pandas.pydata.org/)
84 | - [视频教程](https://www.bilibili.com/video/BV1hk4y1C73S)
85 | #### 个人网站
86 | - hexo
87 | - [中文文档](https://hexo.io/zh-cn/)
88 |
89 | #### 拓展技术
90 |
91 |
--------------------------------------------------------------------------------
/img/WeChatPay.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/img/WeChatPay.png
--------------------------------------------------------------------------------
/pip/python4office/python4office/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhaofeng092/python4office/1906af89a0dce607f744386fadd88c67b5cd16ca/pip/python4office/python4office/__init__.py
--------------------------------------------------------------------------------
/pip/python4office/python4office/hello-world.py:
--------------------------------------------------------------------------------
1 | def hello():
2 | print(('Hello %(name)s!' % ({'name': 'World'})))
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pip/python4office/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-*- coding:utf-8 -*-
3 |
4 | #############################################
5 | # File Name: setup.py
6 | # Author: python4office
7 | # Mail: 1957875073@qq.com
8 | # Created Time: 2022-1-5 10:17:34
9 | #############################################
10 |
11 | from setuptools import setup, find_packages #这个包没有的可以pip一下
12 |
13 | setup(
14 | name = "python4office", #这里是pip项目发布的名称
15 | version = "0.0.1", #版本号,数值大的会优先被pip
16 | keywords = ("pip", "python4office"),
17 | description = "python for office",
18 | long_description = "",
19 | license = "MIT Licence",
20 |
21 | url = "http://python4office.cn/upload-pip/", #项目相关文件地址,一般是github
22 | author = "python4office",
23 | author_email = "1957875073@qq.com",
24 |
25 | packages = find_packages(),
26 | include_package_data = True,
27 | platforms = "any",
28 | install_requires = ['pandas'] #这个项目需要的第三方库
29 | )
30 |
31 |
--------------------------------------------------------------------------------