Skip to content

Commit 76f6568

Browse files
committed
更新了基础部分的部分内容
1 parent 34e5513 commit 76f6568

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1473
-0
lines changed

Day01-15/Appendix-A/code/excel1.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
3+
创建Excel文件
4+
5+
Version: 0.1
6+
Author: 骆昊
7+
Date: 2018-03-26
8+
9+
"""
10+
11+
from openpyxl import Workbook
12+
from openpyxl.worksheet.table import Table, TableStyleInfo
13+
14+
workbook = Workbook()
15+
sheet = workbook.active
16+
data = [
17+
[1001, '白元芳', '男', '13123456789'],
18+
[1002, '白洁', '女', '13233445566']
19+
]
20+
sheet.append(['学号', '姓名', '性别', '电话'])
21+
for row in data:
22+
sheet.append(row)
23+
tab = Table(displayName="Table1", ref="A1:E5")
24+
25+
tab.tableStyleInfo = TableStyleInfo(
26+
name="TableStyleMedium9", showFirstColumn=False,
27+
showLastColumn=False, showRowStripes=True, showColumnStripes=True)
28+
sheet.add_table(tab)
29+
workbook.save('./res/全班学生数据.xlsx')

Day01-15/Appendix-A/code/excel2.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
3+
读取Excel文件
4+
5+
Version: 0.1
6+
Author: 骆昊
7+
Date: 2018-03-26
8+
9+
"""
10+
11+
from openpyxl import load_workbook
12+
from openpyxl import Workbook
13+
14+
workbook = load_workbook('./res/学生明细表.xlsx')
15+
print(workbook.sheetnames)
16+
sheet = workbook[workbook.sheetnames[0]]
17+
print(sheet.title)
18+
for row in range(2, 7):
19+
for col in range(65, 70):
20+
cell_index = chr(col) + str(row)
21+
print(sheet[cell_index].value, end='\t')
22+
print()

Day01-15/Appendix-A/code/pdf1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
3+
创建PDF文件
4+
5+
Version: 0.1
6+
Author: 骆昊
7+
Date: 2018-03-26
8+
9+
"""
10+
11+
import PyPDF2

Day01-15/Appendix-A/code/pdf2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
3+
读取PDF文件
4+
5+
Version: 0.1
6+
Author: 骆昊
7+
Date: 2018-03-26
8+
9+
"""
10+
11+
from PyPDF2 import PdfFileReader
12+
13+
with open('./res/Python课程大纲.pdf', 'rb') as f:
14+
reader = PdfFileReader(f, strict=False)
15+
print(reader.numPages)
16+
if reader.isEncrypted:
17+
reader.decrypt('')
18+
current_page = reader.getPage(5)
19+
print(current_page)
20+
print(current_page.extractText())
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
3+
使用pillow操作图像
4+
5+
Version: 0.1
6+
Author: 骆昊
7+
Date: 2018-03-26
8+
9+
"""
10+
11+
from PIL import Image
12+
13+
img = Image.open('./res/guido.jpg')
14+
print(img.size)
15+
print(img.format)
16+
print(img.format_description)
17+
img.save('./res/guido.png')
18+
19+
img2 = Image.open('./res/guido.png')
20+
img3 = img2.crop((335, 435, 430, 615))
21+
for x in range(4):
22+
for y in range(5):
23+
img2.paste(img3, (95 * y , 180 * x))
24+
img2.resize((img.size[0] // 2, img.size[1] // 2))
25+
img2.rotate(90)
26+
img2.save('./res/guido2.png')
11.4 MB
Binary file not shown.
59 KB
Loading
6.72 KB
Binary file not shown.
Binary file not shown.

Day01-15/Appendix-A/code/word1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
3+
创建Word文件
4+
5+
Version: 0.1
6+
Author: 骆昊
7+
Date: 2018-03-26
8+
9+
"""
10+

0 commit comments

Comments
 (0)