当前位置: 首页>>代码示例>>Python>>正文


Python xlrd.XL_CELL_ERROR属性代码示例

本文整理汇总了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 
开发者ID:alexfeng,项目名称:InternationalizationScript-iOS,代码行数:26,代码来源:runxlrd.py

示例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) 
开发者ID:Scemoon,项目名称:lpts,代码行数:25,代码来源:display.py

示例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.'),
            ) 
开发者ID:Scemoon,项目名称:lpts,代码行数:23,代码来源:test_filter.py

示例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) 
开发者ID:Scemoon,项目名称:lpts,代码行数:20,代码来源:test_filter.py

示例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]
                ) 
开发者ID:pythonanywhere,项目名称:dirigible-spreadsheet,代码行数:31,代码来源:test_importer.py

示例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 
开发者ID:pythonanywhere,项目名称:dirigible-spreadsheet,代码行数:16,代码来源:worksheet.py

示例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 
开发者ID:alexfeng,项目名称:InternationalizationScript-iOS,代码行数:14,代码来源:xlrdnameAPIdemo.py

示例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) 
开发者ID:Scemoon,项目名称:lpts,代码行数:14,代码来源:filter.py

示例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) 
开发者ID:Scemoon,项目名称:lpts,代码行数:28,代码来源:test_filter.py


注:本文中的xlrd.XL_CELL_ERROR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。