coding cp1251 import re string from pyExcelerator import task Workbook

 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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: cp1251 -*-
import re, string
from pyExcelerator import *
#task A
w = Workbook()
ws = w.add_sheet("Sheet")
for x in xrange (101):
ws.write(x-1,0, x)
ws.write(x-1,1, x*x)
cont="A"+str(x)+"+B"+str(x)
ws.write(x-1,2, Formula(cont))
w.save("./demo_a.xls")
#task B
w1 = Workbook()
dict = {0:"Перший",
1:"Другий",
2:"Третій",
3:"Четвертий",
4:"П'ятий",
5:"Шостий",
6:"Сьомий",
7:"Восьмий",
8:"Дев'ятий",
9:"Десятий"}
for i in xrange(10):
ws1 = w1.add_sheet(dict[i])
for x in xrange(i+1):
ws1.write(x,0, i+1)
ws1.write(0,x, i+1)
ws1.write(x+1,x+1, i)
w1.save("./demo_b.xls")
#task C
w2 = Workbook()
for i in xrange(10):
ws2 = w2.add_sheet("Таблиця додавання на число "+str(i+1))
for x in xrange(1,11):
ws2.write(x-1,0, x)
ws2.write(x-1,1, "+")
ws2.write(x-1,2, i+1)
ws2.write(x-1,3, "=")
ws2.write(x-1,4, i+x+1)
w2.save("./demo_c.xls")
#task D
f=file("./demo.txt")
content=f.read()
f.close()
w3 = Workbook()
ws3=w3.add_sheet("Символи")
for i in xrange(0,len(content)):
charNumber = 0
for ch in content:
ws3.write(i,0, content[i])
if ch == content[i]:
charNumber += 1
ws3.write(i,1, charNumber)
ws3=w3.add_sheet("Слова")
word = re.compile(r"\b\S+\b")
allWords = re.findall(word, content)
for i in xrange(0,len(allWords)):
oneWord=allWords[i]
ws3.write(i,0, oneWord)
ws3.write(i,1, len(oneWord))
w3.save("./demo_d.xls")