Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_write_utf_and_read_back(self):
data = [
[u'白', u'日', u'依', u'山', u'尽'],
[u'黄', u'河', u'入', u'海', u'流'],
[u'欲', u'穷', u'千', u'里', u'目'],
[u'更', u'上', u'一', u'层', u'楼']
]
w = pyexcel.Writer("utf.csv")
w.write_rows(data)
w.close()
r = pyexcel.Reader("utf.csv")
expected = pyexcel.utils.to_array(r)
print(expected)
print(data)
assert expected == data
def test_slice(self):
r = pe.Reader(self.testfile)
content1 = [[1, 1, 1, 1]]
assert content1 == r.row[0:1]
content2 = [[1, 1, 1, 1], [2, 2, 2, 2]]
assert content2 == r.row[0:2]
assert content2 == r.row[:2]
content3 = [[2, 2, 2, 2], [3, 3, 3, 3]]
assert content3 == r.row[1:]
content4 = [[1, 1, 1, 1], [2, 2, 2, 2]]
assert content4 == r.row[0:2:1]
content5 = [1, 1, 1, 1]
assert [content5] == r.row[0:0]
r.row[2:1] # bang
def test_contains(self):
r = p.Reader(self.testfile)
def f(row):
return row[0] == "a" and row[1] == "b"
assert r.contains(f) is True
def test_column_at(self):
r = p.Reader(self.testfile)
value = r.column_at(1)
assert value == ["b", "f", "j"]
value = r.column_at(100) # bang
import pyexcel
# "example.csv","example.xlsx","example.ods", "example.xlsm"
spreadsheet = pyexcel.Reader("example.xls")
for value in spreadsheet:
print value
def main(base_dir):
r=Reader(os.path.join(base_dir, "tutorial_datatype_02.ods"))
to_array(r)
def cleanse_func(v):
v = v.replace(" ", "")
v = v.rstrip().strip()
return v
sf = SheetFormatter(cleanse_func)
r.add_formatter(sf)
to_array(r)
def main(base_dir):
# "example.csv","example.ods","example.xls", "example.xlsm"
spreadsheet = pyexcel.Reader(os.path.join(base_dir, "example.xlsx"))
# columns() returns column based iterator, meaning it can be iterated
# column by column
for value in spreadsheet.columns():
print(value)
import pyexcel
# "example.csv","example.xlsx","example.xls", "example.xlsm"
spreadsheet = pyexcel.Reader("example.ods")
for value in spreadsheet.rows():
print value
def main(base_dir):
# Simple give the file name to **Reader**
# "example.xls","example.xlsx","example.ods", "example.xlsm"
spreadsheet = pyexcel.Reader(os.path.join(base_dir, "example.csv"))
# row_range() gives [0 .. number of rows]
for r in spreadsheet.row_range():
# column_range() gives [0 .. number of ranges]
for c in spreadsheet.column_range():
# cell_value(row_index, column_index)
# return the value at the specified
# position
# please note that both row_index
# and column_index starts from 0
print(spreadsheet.cell_value(r, c))