示例#1
0
    def getColumns(self):
        '''
        See :meth:`.DataImport.getColumns`.
        '''
        if not self.__columns:
            # No user-defined columns, so the first row of data defines the
            # column names.
            self.__columns = self.__readRange(self.__cellRange).next()

            headerRowIdx = self.__cellRange.getFirstRowIndex()
            headerStartColIdx = self.__cellRange.getFirstColIndex()
            emptyCells = [
                Cell.FromIndices(headerRowIdx, headerStartColIdx + i)
                for i, col in enumerate(self.__columns) if not col
            ]
            if emptyCells:
                errorMsg = "".join((
                    "Found empty cells ({0}) in header row. Fix input data or ",
                    "configure column names explicitly."))

                raise DataImportError(
                    errorMsg.format(", ".join(
                        (str(cell) for cell in emptyCells))))

        return self.__columns
示例#2
0
    def __detectRangeEnd(self, start, endCol=None):
        '''
        Finds the last cell of usable data in the worksheet. This is used
        for cases where the caller has supplied an open-ended start cell to work
        with.
        '''
        firstRow = start.getRowIndex()
        firstCol = start.getColIndex()

        if not endCol:
            # Find the last non-empty column in the first row of data.
            endCol = self.__ws.ncols - 1
            for col in range(firstCol, self.__ws.ncols):
                if self.__emptyCell(self.__ws.cell(firstRow, col)):
                    endCol = col - 1
                    break

        # Find the last non-empty row in the first column of data.
        endRow = self.__ws.nrows - 1
        for row in range(firstRow, self.__ws.nrows - 1):
            if self.__emptyCell(self.__ws.cell(row, firstCol)):
                endRow = row - 1
                break

        return Cell.FromIndices(endRow, endCol)
示例#3
0
 def __detectRangeStart(self):
     '''
     Finds the first range of usable data in the worksheet. This is used
     for cases where the caller hasn't supplied a range to work with.
     '''
     # 1. find the first row where non blank data exists
     # 2. find the first column where non blank data exists
     for row in range(self.__ws.nrows):
         for col in range(self.__ws.ncols):
             if not self.__emptyCell(self.__ws.cell(row, col)):
                 return Cell.FromIndices(row, col)
示例#4
0
    def getRows(self):
        '''
        See :meth:`.DataImport.getRows`.
        '''
        row = self.__cellRange.getFirstRowIndex()
        if self.__useFirstRowAsHeader:
            row += 1

        start = Cell.FromIndices(row, self.__cellRange.getFirstColIndex())
        end = self.__cellRange.getEndCell()

        return self.__readRange(CellRange(start, end))