本文整理汇总了Python中xlrd.XL_CELL_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Python xlrd.XL_CELL_ERROR属性的具体用法?Python xlrd.XL_CELL_ERROR怎么用?Python xlrd.XL_CELL_ERROR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类xlrd
的用法示例。
在下文中一共展示了xlrd.XL_CELL_ERROR属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_row_data
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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
示例2: cell_display
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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)
示例3: test_set_rdsheet_1
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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.'),
)
示例4: test_finish_resets
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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)
示例5: test_handles_excel_errors
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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]
)
示例6: worksheet_from_excel
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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
示例7: showable_cell_value
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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
示例8: cell
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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)
示例9: test_set_rdsheet_2
# 需要导入模块: import xlrd [as 别名]
# 或者: from xlrd import XL_CELL_ERROR [as 别名]
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)