Python xlrd.XL_CELL_ERROR Examples
The following are 14
code examples of xlrd.XL_CELL_ERROR().
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: runxlrd.py From InternationalizationScript-iOS with MIT License | 6 votes |
def get_row_data(bk, sh, rowx, colrange): result = [] dmode = bk.datemode ctys = sh.row_types(rowx) cvals = sh.row_values(rowx) for colx in colrange: cty = ctys[colx] cval = cvals[colx] if bk.formatting_info: cxfx = str(sh.cell_xf_index(rowx, colx)) else: cxfx = '' if cty == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cval, dmode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) cty = xlrd.XL_CELL_ERROR elif cty == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get(cval, '<Unknown error code 0x%02x>' % cval) else: showval = cval result.append((colx, cty, showval, cxfx)) return result
Example #2
Source File: runxlrd.py From InternationalizationScript-iOS with MIT License | 6 votes |
def get_row_data(bk, sh, rowx, colrange): result = [] dmode = bk.datemode ctys = sh.row_types(rowx) cvals = sh.row_values(rowx) for colx in colrange: cty = ctys[colx] cval = cvals[colx] if bk.formatting_info: cxfx = str(sh.cell_xf_index(rowx, colx)) else: cxfx = '' if cty == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cval, dmode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) cty = xlrd.XL_CELL_ERROR elif cty == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get(cval, '<Unknown error code 0x%02x>' % cval) else: showval = cval result.append((colx, cty, showval, cxfx)) return result
Example #3
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 #4
Source File: test_filter.py From lpts with GNU General Public License v2.0 | 6 votes |
def test_set_rdsheet_1(self,h): r = TestReader( ('Sheet1',[['S1R0C0']]), ('Sheet2',[[(XL_CELL_ERROR,0)]]), ) book = tuple(r.get_workbooks())[0][0] # fire methods on filter f = ErrorFilter() f.next = c = Mock() f.start() f.workbook(book,'new.xls') f.sheet(book.sheet_by_index(0),'new') f.cell(0,0,0,0) f.set_rdsheet(book.sheet_by_index(1)) f.cell(0,0,1,0) f.finish() compare(c.method_calls,[]) h.check( ('xlutils.filter','ERROR',"Cell A1 of sheet 'Sheet2' contains a bad value: error (#NULL!)"), ('xlutils.filter','ERROR','No output as errors have occurred.'), )
Example #5
Source File: test_filter.py From lpts with GNU General Public License v2.0 | 6 votes |
def test_finish_resets(self): # ...that's `start`s job! r = TestReader( ('Sheet1',[[(XL_CELL_ERROR,0)]]), ) book = tuple(r.get_workbooks())[0][0] # fire methods on filter f = ErrorFilter() f.next = c = Mock() f.start() f.workbook(book,'new.xls') f.sheet(book.sheet_by_index(0),'new1') f.cell(0,0,0,0) self.assertTrue(f.handler.fired) f.finish() compare(c.method_calls,[]) self.assertFalse(f.handler.fired) compare(f.temp_path,None)
Example #6
Source File: test_importer.py From dirigible-spreadsheet with MIT License | 5 votes |
def test_handles_excel_errors(self, mock_xlrd_date_as_tuple): mock_excel_worksheet = Mock() errors = { (0,0) : (0x0, '=#NULL!'), (1,0) : (0x7, '=#DIV/0!'), (2,0) : (0xf, '=#VALUE!'), (3,0) : (0x17, '=#REF!'), (4,0) : (0x1d, '=#NAME?'), (5,0) : (0x24, '=#NUM!'), (6,0) : (0x2a, '=#N/A'), } def mock_cell(row, col): mock_cell = Mock() mock_cell.ctype = xlrd.XL_CELL_ERROR mock_cell.value = errors[row, col][0] return mock_cell mock_excel_worksheet.cell.side_effect = mock_cell mock_excel_worksheet.nrows = 7 mock_excel_worksheet.ncols = 1 worksheet = worksheet_from_excel(mock_excel_worksheet) for col in range(mock_excel_worksheet.ncols): for row in range(mock_excel_worksheet.nrows): self.assertEquals( worksheet[col + 1, row + 1].formula, errors[row, col][1] )
Example #7
Source File: worksheet.py From dirigible-spreadsheet with MIT License | 5 votes |
def worksheet_from_excel(excel_sheet): worksheet = Worksheet() for col in range(excel_sheet.ncols): for row in range(excel_sheet.nrows): cell = excel_sheet.cell(row, col) if cell.ctype == XL_CELL_ERROR: formula = '=%s' % (error_text_from_code[cell.value], ) elif cell.ctype == XL_CELL_DATE: formula = '=DateTime(%s, %s, %s, %s, %s, %s)' % xldate_as_tuple( cell.value, excel_sheet.book.datemode) else: formula = unicode(excel_sheet.cell(row, col).value) worksheet[col + 1, row + 1].formula = formula return worksheet
Example #8
Source File: xlrdnameAPIdemo.py From InternationalizationScript-iOS with MIT License | 5 votes |
def showable_cell_value(celltype, cellvalue, datemode): if celltype == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cellvalue, datemode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) elif celltype == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get( cellvalue, '<Unknown error code 0x%02x>' % cellvalue) else: showval = cellvalue return showval
Example #9
Source File: xlrdnameAPIdemo.py From InternationalizationScript-iOS with MIT License | 5 votes |
def showable_cell_value(celltype, cellvalue, datemode): if celltype == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cellvalue, datemode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) elif celltype == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get( cellvalue, '<Unknown error code 0x%02x>' % cellvalue) else: showval = cellvalue return showval
Example #10
Source File: xlrdnameAPIdemo.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def showable_cell_value(celltype, cellvalue, datemode): if celltype == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cellvalue, datemode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) elif celltype == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get( cellvalue, '<Unknown error code 0x%02x>' % cellvalue) else: showval = cellvalue return showval
Example #11
Source File: xlrdnameAPIdemo.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def showable_cell_value(celltype, cellvalue, datemode): if celltype == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cellvalue, datemode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) elif celltype == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get( cellvalue, '<Unknown error code 0x%02x>' % cellvalue) else: showval = cellvalue return showval
Example #12
Source File: xlrdnameAPIdemo.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def showable_cell_value(celltype, cellvalue, datemode): if celltype == xlrd.XL_CELL_DATE: try: showval = xlrd.xldate_as_tuple(cellvalue, datemode) except xlrd.XLDateError as e: showval = "%s:%s" % (type(e).__name__, e) elif celltype == xlrd.XL_CELL_ERROR: showval = xlrd.error_text_from_code.get( cellvalue, '<Unknown error code 0x%02x>' % cellvalue) else: showval = cellvalue return showval
Example #13
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 #14
Source File: test_filter.py From lpts with GNU General Public License v2.0 | 5 votes |
def test_set_rdsheet_2(self,h): r = TestReader( ('Sheet1',[['S1R0C0']]), ('Sheet2',[[(XL_CELL_ERROR,0)]]), ) book = tuple(r.get_workbooks())[0][0] # fire methods on filter f = ErrorFilter() f.next = c = Mock() f.start() f.workbook(book,'new.xls') f.sheet(book.sheet_by_index(0),'new') f.cell(0,0,0,0) f.cell(0,0,1,0) f.finish() compare(c.method_calls,[ ('start', (), {}), ('workbook', (C('xlrd.Book'), 'new.xls'),{}), ('sheet', (C('xlrd.sheet.Sheet',name='new',strict=False), u'new'),{}), ('row', (0, 0),{}), ('cell', (0, 0, 0, 0),{}), ('row', (1, 1),{}), ('cell', (1, 0, 1, 0),{}), ('finish', (), {}) ]) self.assertEqual(len(h.records),0)