# Path: openpyxl/reader/iter_worksheet.py
# class IterableWorksheet(Worksheet):
# 
#     def __init__(self, parent_workbook, title, workbook_name, 
#             sheet_codename, xml_source):
# 
#         Worksheet.__init__(self, parent_workbook, title)
#         self._workbook_name = workbook_name
#         self._sheet_codename = sheet_codename
#         self._xml_source = xml_source
# 
#     def iter_rows(self, range_string = '', row_offset = 0, column_offset = 0):
#         """ Returns a squared range based on the `range_string` parameter, 
#         using generators.
#         
#         :param range_string: range of cells (e.g. 'A1:C4')
#         :type range_string: string
#         
#         :param row: row index of the cell (e.g. 4)
#         :type row: int
# 
#         :param column: column index of the cell (e.g. 3)
#         :type column: int
#         
#         :rtype: generator
#         
#         """
# 
#         return iter_rows(workbook_name = self._workbook_name,
#                          sheet_name = self._sheet_codename,
#                          xml_source = self._xml_source,
#                          range_string = range_string,
#                          row_offset = row_offset,
#                          column_offset = column_offset)
# 
#     def cell(self, *args, **kwargs):
# 
#         raise NotImplementedError("use 'iter_rows()' instead")
# 
#     def range(self, *args, **kwargs):
# 
#         raise NotImplementedError("use 'iter_rows()' instead")
#     
#     def calculate_dimension(self):
#         
#         raise NotImplementedError("'calculate_dimension()' not implemented for IterableWorksheet Class")


    from xml.etree.cElementTree import iterparse
    from xml.etree.ElementTree import iterparse
from itertools import ifilter
from StringIO import StringIO
from openpyxl.cell import Cell, coordinate_from_string
from openpyxl.worksheet import Worksheet
from openpyxl.reader.iter_worksheet import IterableWorksheet
    source = _get_xml_iter(xml_source) 

    it = iterparse(source)

    for event, element in ifilter(filter_cells, it):

        value = element.findtext('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}v')

        if value is not None:

            coordinate = element.get('r')
            data_type = element.get('t', 'n')
            style_id = element.get('s')

            if data_type == Cell.TYPE_STRING:
                value = string_table.get(int(value))

            ws.cell(coordinate).value = value

            if style_id is not None:
                ws._styles[coordinate] = style_table.get(int(style_id))

        # to avoid memory exhaustion, clear the item after use
        element.clear()


def read_worksheet(xml_source, parent, preset_title, string_table,
                   style_table, workbook_name = None, sheet_codename = None):
    """Read an xml worksheet"""
    if workbook_name and sheet_codename:

# Path: openpyxl/reader/iter_worksheet.py
# class IterableWorksheet(Worksheet):
# 
#     def __init__(self, parent_workbook, title, workbook_name, 
#             sheet_codename, xml_source):
# 
#         Worksheet.__init__(self, parent_workbook, title)
#         self._workbook_name = workbook_name
#         self._sheet_codename = sheet_codename
#         self._xml_source = xml_source
# 
#     def iter_rows(self, range_string = '', row_offset = 0, column_offset = 0):
#         """ Returns a squared range based on the `range_string` parameter, 
#         using generators.
#         
#         :param range_string: range of cells (e.g. 'A1:C4')
#         :type range_string: string
#         
#         :param row: row index of the cell (e.g. 4)
#         :type row: int
# 
#         :param column: column index of the cell (e.g. 3)
#         :type column: int
#         
#         :rtype: generator
#         
#         """
# 
#         return iter_rows(workbook_name = self._workbook_name,
#                          sheet_name = self._sheet_codename,
#                          xml_source = self._xml_source,
#                          range_string = range_string,
#                          row_offset = row_offset,
#                          column_offset = column_offset)
# 
#     def cell(self, *args, **kwargs):
# 
#         raise NotImplementedError("use 'iter_rows()' instead")
# 
#     def range(self, *args, **kwargs):
# 
#         raise NotImplementedError("use 'iter_rows()' instead")
#     
#     def calculate_dimension(self):
#         
#         raise NotImplementedError("'calculate_dimension()' not implemented for IterableWorksheet Class")


# Path: openpyxl/reader/worksheet.py
    from xml.etree.cElementTree import iterparse
    from xml.etree.ElementTree import iterparse
from itertools import ifilter
from StringIO import StringIO
from openpyxl.cell import Cell, coordinate_from_string
from openpyxl.worksheet import Worksheet
from openpyxl.reader.iter_worksheet import IterableWorksheet

    source = _get_xml_iter(xml_source) 

    it = iterparse(source)

    for event, element in ifilter(filter_cells, it):

        value = element.findtext('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}v')

        if value is not None:

            coordinate = element.get('r')
            data_type = element.get('t', 'n')
            style_id = element.get('s')

            if data_type == Cell.TYPE_STRING:
                value = string_table.get(int(value))

            ws.cell(coordinate).value = value

            if style_id is not None:
                ws._styles[coordinate] = style_table.get(int(style_id))

        # to avoid memory exhaustion, clear the item after use
        element.clear()


def read_worksheet(xml_source, parent, preset_title, string_table,
                   style_table, workbook_name = None, sheet_codename = None):
    """Read an xml worksheet"""
    if workbook_name and sheet_codename:

        ws = IterableWorksheet(parent, preset_title, workbook_name, 