Пример #1
1
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)
Пример #2
0
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)
Пример #3
0
# Column 1 Column 2 Column 3
# 1        4        7
# 2        5        8
# 3        6        9
reader = SeriesReader("example_series.ods")
data = to_dict(reader)
print json.dumps(data)
# output:
# {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0], "Column 1": [1.0, 2.0, 3.0]}

# get the column headers
print reader.series()
# [u'Column 1', u'Column 2', u'Column 3']

# get the content in one dimensional array
data = to_array(reader.enumerate())
print data
# [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]

# get the content in one dimensional array
# in reverse order
data = to_array(reader.reverse())
print data

# get the content in one dimensional array
# but iterate it vertically 
data = to_array(reader.vertical())
print data
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]

# get the content in one dimensional array
Пример #4
0
from pyexcel import Reader
from pyexcel.utils import to_array
from pyexcel.formatters import SheetFormatter
from pyexcel.formatters import STRING_FORMAT

r=Reader("tutorial_datatype_02.ods")
to_array(r)

def cleanse_func(v, t):
    v = v.replace(" ", "")
    v = v.rstrip().strip()
    return v

sf = SheetFormatter(STRING_FORMAT, cleanse_func)
r.add_formatter(sf)
to_array(r)
Пример #5
0
from pyexcel import Reader
from pyexcel.utils import to_array
import json

# "example.xls","example.xlsx","example.ods", "example.xlsm"
reader = Reader("example.csv")
data = to_array(reader.rows())
print json.dumps(data)
Пример #6
0
# Column 1 Column 2 Column 3
# 1        4        7
# 2        5        8
# 3        6        9
reader = SeriesReader("example_series.ods")
data = to_dict(reader)
print json.dumps(data)
# output:
# {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0], "Column 1": [1.0, 2.0, 3.0]}

# get the column headers
print reader.series()
# [u'Column 1', u'Column 2', u'Column 3']

# get the content in one dimensional array
data = to_array(reader.enumerate())
print data
# [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]

# get the content in one dimensional array
# in reverse order
data = to_array(reader.reverse())
print data

# get the content in one dimensional array
# but iterate it vertically
data = to_array(reader.vertical())
print data
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]

# get the content in one dimensional array
Пример #7
0
def main(base_dir):
    # print all in json
    #
    # Column 1 Column 2 Column 3
    # 1        4        7
    # 2        5        8
    # 3        6        9
    reader = SeriesReader(os.path.join(base_dir,"example_series.ods"))
    data = to_dict(reader)
    print(json.dumps(data))
    # output:
    # {"Column 2": [4.0, 5.0, 6.0], "Column 3": [7.0, 8.0, 9.0], "Column 1": [1.0, 2.0, 3.0]}
    
    # get the column headers
    print(reader.colnames)
    # [u'Column 1', u'Column 2', u'Column 3']
    
    # get the content in one dimensional array
    data = to_array(reader.enumerate())
    print(data)
    # [1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0]
    
    # get the content in one dimensional array
    # in reverse order
    data = to_array(reader.reverse())
    print(data)
    
    # get the content in one dimensional array
    # but iterate it vertically 
    data = to_array(reader.vertical())
    print(data)
    # [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
    
    # get the content in one dimensional array
    # but iterate it vertically in revserse
    # order
    data = to_array(reader.rvertical())
    print(data)
    #[9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]
    
    # get a two dimensional array
    data = to_array(reader.rows())
    print(data)
    #[[1.0, 4.0, 7.0], [2.0, 5.0, 8.0], [3.0, 6.0, 9.0]]
    
    # get a two dimensional array in reverse
    # order
    data = to_array(reader.rrows())
    print(data)
    # [[3.0, 6.0, 9.0], [2.0, 5.0, 8.0], [1.0, 4.0, 7.0]]
    
    # get a two dimensional array but stack columns 
    data = to_array(reader.columns())
    print(data)
    # [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]
    
    # get a two dimensional array but stack columns
    # in reverse order
    data = to_array(reader.rcolumns())
    print(data)
    #[[7.0, 8.0, 9.0], [4.0, 5.0, 6.0], [1.0, 2.0, 3.0]]
    
    # filter out odd rows and even columns
    reader.filter(OddRowFilter())
    reader.filter(EvenColumnFilter())
    data = to_dict(reader)
    print(data)
    # {u'Column 3': [8.0], u'Column 1': [2.0]}
    
    # and you can write the filtered results
    # into a file
    reader.save_as("example_series_filter.xls")
Пример #8
0
def main(base_dir):
    # "example.xls","example.xlsx","example.ods", "example.xlsm"
    reader = Reader(os.path.join(base_dir,"example.csv"))
    data = to_array(reader.rows())
    print(json.dumps(data))