Skip to content

Commit 69f46f9

Browse files
committed
mayuan
1 parent 695b581 commit 69f46f9

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: mayuan/Test.docx

158 KB
Binary file not shown.

Diff for: mayuan/mayuan.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import xlrd
2+
import xlwt
3+
import docx
4+
document = docx.Document()
5+
i = 1
6+
7+
8+
def read():
9+
data = xlrd.open_workbook("~/Documents/课程题库复习资料 1905.xls")
10+
table = data.sheets()[0]
11+
nrows = table.nrows # 行数
12+
# ncols = table.ncols
13+
for i in range(1, nrows):
14+
line = table.row_values(i)
15+
if line[1] == '判断题':
16+
# line[2] 题干 line[3] 答案 line[7] 正确 line[8] 错误
17+
# print(line[1])
18+
judge(line[2], line[3])
19+
if line[1] == '单选题':
20+
# line[2] 题干 line[3] 答案 line[7] A line[8] B line[9] C line[10 D]
21+
single(line[2], line[3], line[7], line[8], line[9], line[10])
22+
# print(line[1])
23+
if line[1] == '多选题':
24+
single(line[2], line[3], line[7], line[8], line[9], line[10])
25+
# # line[2] 题干 line[3] 答案 line[7] A line[8] B line[9] C line[10 D]
26+
# print(line[1])
27+
28+
29+
def single(question, answer, A, B, C, D):
30+
global i
31+
document.add_paragraph(str(i) + "、" + question)
32+
i += 1
33+
document.add_paragraph("A."+A)
34+
document.add_paragraph("B."+B)
35+
document.add_paragraph("C."+C)
36+
document.add_paragraph("D." + D)
37+
document.add_paragraph("答案:" + answer)
38+
document.add_paragraph()
39+
40+
41+
def judge(question, answer):
42+
global i
43+
flag = "正确" if answer == "A" else "错误"
44+
document.add_paragraph(str(i) + "、" + question)
45+
i += 1
46+
# document.add_paragraph('正确 错误')
47+
document.add_paragraph("答案:" + flag)
48+
document.add_paragraph()
49+
50+
# b.add_run('dolor sit amet.')
51+
52+
53+
if __name__ == "__main__":
54+
read()
55+
document.save("mayuan/Test.docx")

0 commit comments

Comments
 (0)