Example #1
0
def main(base_dir):
    reader = SeriesReader(os.path.join(base_dir, "tutorial_datatype_01.xls"))
    print(to_dict(reader))
    #{u'userid': [10120.0, 10121.0, 10122.0], u'name': [u'Adam', u'Bella', u'Cedar']}
    formatter = ColumnFormatter(0, str)
    reader.add_formatter(formatter)
    to_dict(reader)
Example #2
0
def main(base_dir):
    reader = SeriesReader(os.path.join(base_dir, "tutorial_datatype_01.xls"))
    print(to_dict(reader))
    #{u'userid': [10120.0, 10121.0, 10122.0], u'name': [u'Adam', u'Bella', u'Cedar']}
    formatter = ColumnFormatter(0, str)
    reader.add_formatter(formatter)
    to_dict(reader)
Example #3
0
    def __add__(self, other):
        """Override operator +

        example::

            book3 = book1 + book2
            book3 = book1 + book2["Sheet 1"]

        """
        content = {}
        current_dict = utils.to_dict(self)
        for k in current_dict.keys():
            new_key = k
            if len(current_dict.keys()) == 1:
                new_key = "%s_%s" % (self.filename, k)
            content[new_key] = current_dict[k]
        if isinstance(other, Book):
            other_dict = utils.to_dict(other)
            for l in other_dict.keys():
                new_key = l
                if len(other_dict.keys()) == 1:
                    new_key = other.filename
                if new_key in content:
                    uid = utils.local_uuid()
                    new_key = "%s_%s" % (l, uid)
                content[new_key] = other_dict[l]
        elif isinstance(other, Sheet):
            new_key = other.name
            if new_key in content:
                uid = utils.local_uuid()
                new_key = "%s_%s" % (other.name, uid)
            content[new_key] = other.to_array()
        else:
            raise TypeError
        output = Book()
        output.load_from_sheets(content)
        return output
Example #4
0
# please install pyexcel-ods
from pyexcel.ext import ods3
from pyexcel import SeriesReader, FilterableReader
from pyexcel.utils import to_dict, to_array
from pyexcel.filters import OddRowFilter, EvenColumnFilter
from pyexcel import Writer
import json

# print all in json
#
# 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
Example #5
0
from pyexcel import SeriesReader
from pyexcel.utils import to_dict
from pyexcel.formatters import ColumnFormatter
from pyexcel.formatters import STRING_FORMAT

reader = SeriesReader("tutorial_datatype_01.xls")
print to_dict(reader)
#{u'userid': [10120.0, 10121.0, 10122.0], u'name': [u'Adam', u'Bella', u'Cedar']}
formatter = ColumnFormatter(0, STRING_FORMAT)
reader.add_formatter(formatter)
to_dict(reader)
#{u'userid': ['10120.0', '10121.0', '10122.0'], u'name': [u'Adam', u'Bella', u'Cedar']}
Example #6
0
# please install pyexcel-ods
from pyexcel.ext import ods3
from pyexcel import SeriesReader, FilterableReader
from pyexcel.utils import to_dict, to_array
from pyexcel.filters import OddRowFilter, EvenColumnFilter
from pyexcel import Writer
import json

# print all in json
#
# 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
Example #7
0
from pyexcel import SeriesReader
from pyexcel.utils import to_dict
from pyexcel.formatters import ColumnFormatter
from pyexcel.formatters import STRING_FORMAT


reader = SeriesReader("tutorial_datatype_01.xls")
print to_dict(reader)
#{u'userid': [10120.0, 10121.0, 10122.0], u'name': [u'Adam', u'Bella', u'Cedar']}
formatter = ColumnFormatter(0, STRING_FORMAT)
reader.add_formatter(formatter)
to_dict(reader)
#{u'userid': ['10120.0', '10121.0', '10122.0'], u'name': [u'Adam', u'Bella', u'Cedar']}
Example #8
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")