コード例 #1
0
ファイル: _ods.py プロジェクト: derHahn/SBtab
def detect(stream):
    """Returns True if given stream is a readable excel file."""
    try:
        opendocument.load(BytesIO(stream))
        return True
    except:
        pass
コード例 #2
0
def detect(stream):
    """Returns True if given stream is a readable excel file."""
    try:
        opendocument.load(BytesIO(stream))
        return True
    except:
        pass
コード例 #3
0
ファイル: _ods.py プロジェクト: razum2um/tablib
def detect(stream):
    """Returns True if given stream is a readable excel file."""
    try:
        doc = opendocument.load(stream)
        return True
    except:
        return False
コード例 #4
0
ファイル: _ods.py プロジェクト: joinourtalents/tablib
def import_set(dset, in_stream, headers=True):
    """Returns dataset from ODS stream. Default sheet 1"""
    dset.wipe()

    doc = opendocument.load(in_stream)
    sheet = doc.spreadsheet.childNodes[0]
    rows = sheet.getElementsByType(table.TableRow)
    row_count = 0
    for row in rows:
        cells = row.getElementsByType(table.TableCell)
        arrCells = []
        cell_count = 0
        for cell in cells:
            # repeated value?
            repeat = cell.getAttribute("numbercolumnsrepeated")
            if(not repeat):
                repeat = 1

            ps = cell.getElementsByType(text.P)
            textContent = ""

            # for each text node
            for p in ps:
                c = p.firstChild  # TODO: Where is it used?
                textContent = textContent + unicode(p)

            if textContent and textContent[0] != "#": # ignore comments cells
                for rr in range(int(repeat)): # repeated?
                    arrCells.append(textContent)
                    cell_count += 1
            else:
                arrCells.append("")

        if row_count == 0 and headers:
            dset.headers = arrCells
        elif cell_count > 1:
            # empty cells are needed, but last string == ['']
            dset.append(arrCells)
        else:
            pass
        row_count += 1
コード例 #5
0
ファイル: _ods.py プロジェクト: derHahn/SBtab
 def __init__(self, file):
     self.doc = opendocument.load(file)
     self.SHEETS = {}
     for sheet in self.doc.spreadsheet.getElementsByType(table.Table):
         self.readSheet(sheet)
コード例 #6
0
 def __init__(self, file):
     self.doc = opendocument.load(file)
     self.SHEETS = {}
     for sheet in self.doc.spreadsheet.getElementsByType(table.Table):
         self.readSheet(sheet)