Repository navigation
Expand file tree
/
Copy pathtest_Workbook.py
More file actions
173 lines (149 loc) · 4.02 KB
/
Copy pathtest_Workbook.py
File metadata and controls
173 lines (149 loc) · 4.02 KB
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
88
89
90
91
92
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from ..Workbook import Workbook
from ..Color import Color
import time
import nose
import os
from datetime import datetime
from nose.tools import eq_, raises
from .utils import get_output_path
def test_get_xml_data():
wb = Workbook()
ws = wb.new_sheet("Test")
ws[1][1].value = 1
eq_(ws[1][1].value, 1)
ws[1][3].value = 3
eq_(ws[1][3].value, 3)
def test_save():
ROWS = 65
COLUMNS = 100
wb = Workbook()
testData = [[1] * COLUMNS] * ROWS
stime = time.clock()
ws = wb.new_sheet("Test 1", data=testData)
wb.save(get_output_path("test.xlsx"))
def test_formulas():
wb = Workbook()
ws = wb.new_sheet("test")
ws[1]['A'].value = 1
ws[1][2].value = 2
ws[1][3].value = '=SUM(A1,B1)'
ws[1][4].value = datetime.now()
ws[1][5].value = datetime(1900,1,1,1,0,0)
ws[1][6].value = True
wb.save(get_output_path("formula-test.xlsx"))
def test_merge():
wb = Workbook()
ws = wb.new_sheet("test")
ws[1][1].value = "asdf"
ws.range("A1", "B1").merge()
eq_(ws[1][2].value, ws[1][1].value)
ws[1][2].value = "qwer"
eq_(ws[1][2].value, ws[1][1].value)
wb.save(get_output_path("merge-test.xlsx"))
def test_cell():
wb = Workbook()
ws = wb.new_sheet("test")
ws.cell("C3").value = "test"
eq_(ws[3][3].value, "test")
def test_range():
wb = Workbook()
ws = wb.new_sheet("test")
ws.range("B2", "D3").value = [[1, 2, 3], [4, 5, 6]]
eq_(ws[2][2].value, 1)
eq_(ws[2][3].value, 2)
eq_(ws[2][4].value, 3)
eq_(ws[3][2].value, 4)
eq_(ws[3][3].value, 5)
eq_(ws[3][4].value, 6)
def test_numpy_range():
try:
import numpy
except ImportError:
raise nose.SkipTest('numpy not installed')
wb = Workbook()
ws = wb.new_sheet("test")
ws.range("A1", "GN13").value = numpy.zeros((13,196))
wb.save(get_output_path("numpy-range-test.xlsx"))
def test_none():
testData = [[1,2,None]]
wb = Workbook()
ws = wb.new_sheet("Test 1", data=testData)
ws[1][1].style.font.bold = True
wb.save(get_output_path("none-test.xlsx"))
@raises(Exception)
def test_name_length():
wb = Workbook()
ws = wb.new_sheet('12345678901234567890123456789012')
def test_name_length_force():
wb = Workbook()
ws = wb.new_sheet('12345678901234567890123456789012', force_name=True)
@raises(Exception)
def test_name_duplicate():
wb = Workbook()
ws = wb.new_sheet('1234')
ws = wb.new_sheet('1234')
def test_name_no_duplicate():
wb = Workbook()
ws = wb.new_sheet('1234')
ws = wb.new_sheet('12356')
def test_multi_save():
excel_file = Workbook()
excel_report = excel_file.new_sheet("Format Test")
excel_report[1][1].value = "Format"
excel_report[1][2].value = "Result"
excel_file.save(get_output_path("test.xlsx"))
excel_report[3][2].style.fill.background = Color(0, 176, 80)
excel_file.save(get_output_path("test.xlsx"))
def test_number_precision():
try:
import xlrd
except ImportError:
raise nose.SkipTest('xlrd not installed')
filename = get_output_path('precision.xlsx')
sheetname = 'Sheet1'
nums = [
1,
1.2,
1.23,
1.234,
1.2345,
1.23456,
1.234567,
1.2345678,
1.23456789,
1.234567890,
1.2345678901,
1.23456789012,
1.234567890123,
1.2345678901234,
1.23456789012345,
]
write_workbook = Workbook()
write_worksheet = write_workbook.new_sheet(sheetname)
for index, value in enumerate(nums):
write_worksheet[index + 1][1].value = value
write_workbook.save(filename)
read_workbook = xlrd.open_workbook(filename)
read_worksheet = read_workbook.sheet_by_name(sheetname)
for row_num in range(len(nums)):
expected = nums[row_num]
got = read_worksheet.cell(row_num, 0).value
eq_(got, expected)
if os.path.exists(filename):
os.remove(filename)
#def test_column_select():
# wb = Workbook()
# ws = wb.new_sheet("Test")
# print(ws[1:3])
# ws[1:3][1].style.fill.background = Color(255, 0, 0)
def test_show_grid_lines():
wb = Workbook()
ws = wb.new_sheet('without_grid_lines')
ws[1][1].value = 'some data'
ws.show_grid_lines = False
ws = wb.new_sheet('with_grid_lines')
ws[1][1].value = 'some other data'
ws.show_grid_lines = True
ws = wb.new_sheet('default_with_grid_lines')
ws[1][1].value = 'even more data'
wb.save(get_output_path("grid_lines.xlsx"))