3
3
4
4
5
5
def create_sample_file1 (file ):
6
- w = pyexcel .Writer (file )
7
6
data = ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 1.1 , 1 ]
8
7
table = []
9
8
table .append (data [:4 ])
10
9
table .append (data [4 :8 ])
11
10
table .append (data [8 :12 ])
12
- w .write_array (table )
13
- w .close ()
11
+ pyexcel .save_as (array = table , dest_file_name = file )
14
12
15
13
16
14
class PyexcelHatWriterBase :
@@ -24,10 +22,8 @@ class PyexcelHatWriterBase:
24
22
}
25
23
26
24
def test_series_table (self ):
27
- w = pyexcel .Writer (self .testfile )
28
- w .write_dict (self .content )
29
- w .close ()
30
- r = pyexcel .SeriesReader (self .testfile )
25
+ pyexcel .save_as (adict = self .content , dest_file_name = self .testfile )
26
+ r = pyexcel .get_sheet (file_name = self .testfile , name_columns_by_row = 0 )
31
27
actual = pyexcel .utils .to_dict (r )
32
28
assert actual == self .content
33
29
@@ -47,40 +43,19 @@ class PyexcelWriterBase:
47
43
]
48
44
49
45
def _create_a_file (self , file ):
50
- w = pyexcel .Writer (file )
51
- w .write_array (self .content )
52
- w .close ()
46
+ pyexcel .save_as (dest_file_name = file ,array = self .content )
53
47
54
48
def test_write_array (self ):
55
49
self ._create_a_file (self .testfile )
56
- r = pyexcel .Reader ( self .testfile )
50
+ r = pyexcel .get_sheet ( file_name = self .testfile )
57
51
actual = pyexcel .utils .to_array (r .rows ())
58
52
assert actual == self .content
59
53
60
- def test_write_reader (self ):
61
- """
62
- Use reader as data container
63
-
64
- this test case shows the file written by pyexcel
65
- can be read back by itself
66
- """
67
- self ._create_a_file (self .testfile )
68
- r = pyexcel .Reader (self .testfile )
69
- w2 = pyexcel .Writer (self .testfile2 )
70
- w2 .write_reader (r )
71
- w2 .close ()
72
- r2 = pyexcel .Reader (self .testfile2 )
73
- r2 .format (int )
74
- actual = pyexcel .utils .to_array (r2 .rows ())
75
- assert actual == self .content
76
-
77
54
78
55
class PyexcelMultipleSheetBase :
79
56
80
57
def _write_test_file (self , filename ):
81
- w = pyexcel .BookWriter (filename )
82
- w .write_book_from_dict (self .content )
83
- w .close ()
58
+ pyexcel .save_book_as (bookdict = self .content , dest_file_name = filename )
84
59
85
60
def _clean_up (self ):
86
61
if os .path .exists (self .testfile2 ):
@@ -122,20 +97,6 @@ def test_iterate_through_sheets(self):
122
97
data = pyexcel .utils .to_array (s )
123
98
assert self .content [s .name ] == data
124
99
125
- def test_write_a_book_reader (self ):
126
- b = pyexcel .BookReader (self .testfile )
127
- bw = pyexcel .BookWriter (self .testfile2 )
128
- for s in b :
129
- data = pyexcel .utils .to_array (s )
130
- sheet = bw .create_sheet (s .name )
131
- sheet .write_array (data )
132
- sheet .close ()
133
- bw .close ()
134
- x = pyexcel .BookReader (self .testfile2 )
135
- for s in x :
136
- data = pyexcel .utils .to_array (s )
137
- assert self .content [s .name ] == data
138
-
139
100
def test_random_access_operator (self ):
140
101
r = pyexcel .BookReader (self .testfile )
141
102
value = r ["Sheet1" ][0 ,1 ]
0 commit comments