Python xlrd.XL_CELL_EMPTY Examples
The following are 17
code examples of xlrd.XL_CELL_EMPTY().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
xlrd
, or try the search function
.
Example #1
Source File: test_read_data_from_xls.py From pyDEA with MIT License | 6 votes |
def test_has_non_empty_cells(): row = [] reader = XLSReader() assert has_non_empty_cells(reader, []) is False row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_BLANK, '')) assert has_non_empty_cells(reader, row) is False row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'x1')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'input with space')) assert has_non_empty_cells(reader, row) is True row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 10)) assert has_non_empty_cells(reader, row) is True row = [] row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 10)) assert has_non_empty_cells(reader, row) is True
Example #2
Source File: display.py From lpts with GNU General Public License v2.0 | 6 votes |
def cell_display(cell, datemode=0, encoding='ascii'): cty = cell.ctype if cty == xlrd.XL_CELL_EMPTY: return 'undefined' if cty == xlrd.XL_CELL_BLANK: return 'blank' if cty == xlrd.XL_CELL_NUMBER: return 'number (%.4f)' % cell.value if cty == xlrd.XL_CELL_DATE: try: return "date (%04d-%02d-%02d %02d:%02d:%02d)" \ % xlrd.xldate_as_tuple(cell.value, datemode) except xlrd.xldate.XLDateError: return "date? (%.6f)" % cell.value if cty == xlrd.XL_CELL_TEXT: return "text (%s)" % cell.value.encode(encoding, 'replace') if cty == xlrd.XL_CELL_ERROR: if cell.value in xlrd.error_text_from_code: return "error (%s)" % xlrd.error_text_from_code[cell.value] return "unknown error code (%r)" % cell.value if cty == xlrd.XL_CELL_BOOLEAN: return "logical (%s)" % ['FALSE', 'TRUE'][cell.value] raise Exception("Unknown Cell.ctype: %r" % cty)
Example #3
Source File: test_read_data_from_xls.py From pyDEA with MIT License | 6 votes |
def test_extract_coefficients(): row = [] row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'dmu1')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 10)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 25)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 45)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 0)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 7.9)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) reader = XLSReader() (dmu, coefficients, dmu_name) = extract_coefficients( reader, row, [4, 5, 7, 8, 10]) assert dmu == 'dmu1' assert coefficients == [10, 25, 45, 0, 7.9]
Example #4
Source File: test_read_data_from_xls.py From pyDEA with MIT License | 6 votes |
def test_extract_coefficients_with_numeric_dmu(): row = [] row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 0)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 10)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 25)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 45)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 0)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 7.9)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u' aha ')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) reader = XLSReader() (dmu, coefficients, dmu_name) = extract_coefficients( reader, row, [3, 4, 5, 6, 7, 8, 9]) assert dmu == 0 assert coefficients == [10, 25, 45, 0, 7.9, '', 'aha']
Example #5
Source File: xlrdnameAPIdemo.py From InternationalizationScript-iOS with MIT License | 5 votes |
def show_name_object(book, nobj, show_contents=0, f=sys.stdout): print("\nName: %s, scope: %s (%s)" \ % (REPR(nobj.name), REPR(nobj.scope), scope_as_string(book, nobj.scope)), file=f) res = nobj.result print("Formula eval result: %s" % REPR(res), file=f) if res is None: return # result should be an instance of the Operand class kind = res.kind value = res.value if kind >= 0: # A scalar, or unknown ... you've seen all there is to see. pass elif kind == xlrd.oREL: # A list of Ref3D objects representing *relative* ranges for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3drel(book, ref3d))), file=f) elif kind == xlrd.oREF: # A list of Ref3D objects for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3d(book, ref3d))), file=f) if not show_contents: continue datemode = book.datemode for shx in range(ref3d.shtxlo, ref3d.shtxhi): sh = book.sheet_by_index(shx) print(" Sheet #%d (%s)" % (shx, sh.name), file=f) rowlim = min(ref3d.rowxhi, sh.nrows) collim = min(ref3d.colxhi, sh.ncols) for rowx in range(ref3d.rowxlo, rowlim): for colx in range(ref3d.colxlo, collim): cty = sh.cell_type(rowx, colx) if cty == xlrd.XL_CELL_EMPTY and show_contents == 1: continue cval = sh.cell_value(rowx, colx) sval = showable_cell_value(cty, cval, datemode) print(" (%3d,%3d) %-5s: %s" % (rowx, colx, xlrd.cellname(rowx, colx), REPR(sval)), file=f)
Example #6
Source File: filter.py From lpts with GNU General Public License v2.0 | 5 votes |
def cell(self,rdrowx,rdcolx,wtrowx,wtcolx): cell = self.rdsheet.cell(rdrowx,rdcolx) if cell.ctype == xlrd.XL_CELL_EMPTY: return if cell.ctype == xlrd.XL_CELL_ERROR: logger.error("Cell %s of sheet %r contains a bad value: %s" % ( xlrd.cellname(rdrowx, rdcolx), quoted_sheet_name(self.rdsheet.name), cell_display(cell,self.rdbook.datemode), )) return BaseWriter.cell(self,rdrowx,rdcolx,wtrowx,wtcolx)
Example #7
Source File: xlrdnameAPIdemo.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def show_name_object(book, nobj, show_contents=0, f=sys.stdout): print("\nName: %s, scope: %s (%s)" % (REPR(nobj.name), REPR(nobj.scope), scope_as_string(book, nobj.scope)), file=f) res = nobj.result print("Formula eval result: %s" % REPR(res), file=f) if res is None: return # result should be an instance of the Operand class kind = res.kind value = res.value if kind >= 0: # A scalar, or unknown ... you've seen all there is to see. pass elif kind == xlrd.oREL: # A list of Ref3D objects representing *relative* ranges for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3drel(book, ref3d))), file=f) elif kind == xlrd.oREF: # A list of Ref3D objects for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3d(book, ref3d))), file=f) if not show_contents: continue datemode = book.datemode for shx in range(ref3d.shtxlo, ref3d.shtxhi): sh = book.sheet_by_index(shx) print(" Sheet #%d (%s)" % (shx, sh.name), file=f) rowlim = min(ref3d.rowxhi, sh.nrows) collim = min(ref3d.colxhi, sh.ncols) for rowx in range(ref3d.rowxlo, rowlim): for colx in range(ref3d.colxlo, collim): cty = sh.cell_type(rowx, colx) if cty == xlrd.XL_CELL_EMPTY and show_contents == 1: continue cval = sh.cell_value(rowx, colx) sval = showable_cell_value(cty, cval, datemode) print(" (%3d,%3d) %-5s: %s" % (rowx, colx, xlrd.cellname(rowx, colx), REPR(sval)), file=f)
Example #8
Source File: xlrdnameAPIdemo.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def show_name_object(book, nobj, show_contents=0, f=sys.stdout): print("\nName: %s, scope: %s (%s)" % (REPR(nobj.name), REPR(nobj.scope), scope_as_string(book, nobj.scope)), file=f) res = nobj.result print("Formula eval result: %s" % REPR(res), file=f) if res is None: return # result should be an instance of the Operand class kind = res.kind value = res.value if kind >= 0: # A scalar, or unknown ... you've seen all there is to see. pass elif kind == xlrd.oREL: # A list of Ref3D objects representing *relative* ranges for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3drel(book, ref3d))), file=f) elif kind == xlrd.oREF: # A list of Ref3D objects for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3d(book, ref3d))), file=f) if not show_contents: continue datemode = book.datemode for shx in range(ref3d.shtxlo, ref3d.shtxhi): sh = book.sheet_by_index(shx) print(" Sheet #%d (%s)" % (shx, sh.name), file=f) rowlim = min(ref3d.rowxhi, sh.nrows) collim = min(ref3d.colxhi, sh.ncols) for rowx in range(ref3d.rowxlo, rowlim): for colx in range(ref3d.colxlo, collim): cty = sh.cell_type(rowx, colx) if cty == xlrd.XL_CELL_EMPTY and show_contents == 1: continue cval = sh.cell_value(rowx, colx) sval = showable_cell_value(cty, cval, datemode) print(" (%3d,%3d) %-5s: %s" % (rowx, colx, xlrd.cellname(rowx, colx), REPR(sval)), file=f)
Example #9
Source File: io.py From libhxl-python with The Unlicense | 5 votes |
def _fix_value(cell): """Clean up an Excel value for CSV-like representation.""" if cell.value is None or cell.ctype == xlrd.XL_CELL_EMPTY: return '' elif cell.ctype == xlrd.XL_CELL_NUMBER: # let numbers be integers if possible if float(cell.value).is_integer(): return int(cell.value) else: return cell.value elif cell.ctype == xlrd.XL_CELL_DATE: # dates need to be formatted try: data = xlrd.xldate_as_tuple(cell.value, 0) return '{0[0]:04d}-{0[1]:02d}-{0[2]:02d}'.format(data) except: return cell.value elif cell.ctype == xlrd.XL_CELL_BOOLEAN: return int(cell.value) else: # XL_CELL_TEXT, or anything else return cell.value
Example #10
Source File: io.py From libhxl-python with The Unlicense | 5 votes |
def _fix_value(cell): """Clean up an Excel value for CSV-like representation.""" if cell.value is None or cell.ctype == xlrd.XL_CELL_EMPTY: return '' elif cell.ctype == xlrd.XL_CELL_NUMBER: # let numbers be integers if possible if float(cell.value).is_integer(): return int(cell.value) else: return cell.value elif cell.ctype == xlrd.XL_CELL_DATE: # dates need to be formatted try: data = xlrd.xldate_as_tuple(cell.value, 0) return '{0[0]:04d}-{0[1]:02d}-{0[2]:02d}'.format(data) except: return cell.value; elif cell.ctype == xlrd.XL_CELL_BOOLEAN: return int(cell.value) else: # XL_CELL_TEXT, or anything else return cell.value
Example #11
Source File: xlrdnameAPIdemo.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def show_name_object(book, nobj, show_contents=0, f=sys.stdout): print("\nName: %s, scope: %s (%s)" % (REPR(nobj.name), REPR(nobj.scope), scope_as_string(book, nobj.scope)), file=f) res = nobj.result print("Formula eval result: %s" % REPR(res), file=f) if res is None: return # result should be an instance of the Operand class kind = res.kind value = res.value if kind >= 0: # A scalar, or unknown ... you've seen all there is to see. pass elif kind == xlrd.oREL: # A list of Ref3D objects representing *relative* ranges for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3drel(book, ref3d))), file=f) elif kind == xlrd.oREF: # A list of Ref3D objects for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3d(book, ref3d))), file=f) if not show_contents: continue datemode = book.datemode for shx in range(ref3d.shtxlo, ref3d.shtxhi): sh = book.sheet_by_index(shx) print(" Sheet #%d (%s)" % (shx, sh.name), file=f) rowlim = min(ref3d.rowxhi, sh.nrows) collim = min(ref3d.colxhi, sh.ncols) for rowx in range(ref3d.rowxlo, rowlim): for colx in range(ref3d.colxlo, collim): cty = sh.cell_type(rowx, colx) if cty == xlrd.XL_CELL_EMPTY and show_contents == 1: continue cval = sh.cell_value(rowx, colx) sval = showable_cell_value(cty, cval, datemode) print(" (%3d,%3d) %-5s: %s" % (rowx, colx, xlrd.cellname(rowx, colx), REPR(sval)), file=f)
Example #12
Source File: xlrdnameAPIdemo.py From InternationalizationScript-iOS with MIT License | 5 votes |
def show_name_object(book, nobj, show_contents=0, f=sys.stdout): print("\nName: %s, scope: %s (%s)" \ % (REPR(nobj.name), REPR(nobj.scope), scope_as_string(book, nobj.scope)), file=f) res = nobj.result print("Formula eval result: %s" % REPR(res), file=f) if res is None: return # result should be an instance of the Operand class kind = res.kind value = res.value if kind >= 0: # A scalar, or unknown ... you've seen all there is to see. pass elif kind == xlrd.oREL: # A list of Ref3D objects representing *relative* ranges for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3drel(book, ref3d))), file=f) elif kind == xlrd.oREF: # A list of Ref3D objects for i in range(len(value)): ref3d = value[i] print("Range %d: %s ==> %s"% (i, REPR(ref3d.coords), REPR(xlrd.rangename3d(book, ref3d))), file=f) if not show_contents: continue datemode = book.datemode for shx in range(ref3d.shtxlo, ref3d.shtxhi): sh = book.sheet_by_index(shx) print(" Sheet #%d (%s)" % (shx, sh.name), file=f) rowlim = min(ref3d.rowxhi, sh.nrows) collim = min(ref3d.colxhi, sh.ncols) for rowx in range(ref3d.rowxlo, rowlim): for colx in range(ref3d.colxlo, collim): cty = sh.cell_type(rowx, colx) if cty == xlrd.XL_CELL_EMPTY and show_contents == 1: continue cval = sh.cell_value(rowx, colx) sval = showable_cell_value(cty, cval, datemode) print(" (%3d,%3d) %-5s: %s" % (rowx, colx, xlrd.cellname(rowx, colx), REPR(sval)), file=f)
Example #13
Source File: excelloader.py From pytablereader with MIT License | 5 votes |
def __is_header_row(self, row_idx): try: from excelrd import XL_CELL_EMPTY except ImportError: from xlrd import XL_CELL_EMPTY return XL_CELL_EMPTY not in self._worksheet.row_types( row_idx, self._start_col_idx, self._end_col_idx + 1 )
Example #14
Source File: service_sheet.py From oopt-gnpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse_row(row, fieldnames): return {f: r.value for f, r in zip(fieldnames, row[0:SERVICES_COLUMN]) if r.ctype != XL_CELL_EMPTY}
Example #15
Source File: test_read_data_from_xls.py From pyDEA with MIT License | 5 votes |
def test_extract_numeric_categories(): row = [] row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 5)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, 15)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_NUMBER, -100)) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'x1')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) reader = XLSReader() categories, indexes = extract_categories(reader, row) assert categories == [5, 15, -100, 'x1']
Example #16
Source File: test_read_data_from_xls.py From pyDEA with MIT License | 5 votes |
def test_extract_categories(): row = [] row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'x1')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_EMPTY, '')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'x2')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'input with space')) row.append(xlrd.sheet.Cell(xlrd.XL_CELL_TEXT, u'output starts with space')) reader = XLSReader() categories, indexes = extract_categories(reader, row) assert categories == ['x1', 'x2', 'input with space', 'output starts with space']
Example #17
Source File: excelloader.py From pytablereader with MIT License | 5 votes |
def __is_empty_cell_types(cell_types): try: from excelrd import XL_CELL_EMPTY except ImportError: from xlrd import XL_CELL_EMPTY return all([cell_type == XL_CELL_EMPTY for cell_type in cell_types])