def test_excel_comments(self): book = open_workbook(from_this_dir('test_comments_excel.xlsx')) sheet = book.sheet_by_index(0) note_map = sheet.cell_note_map self.assertEqual(len(note_map), 1) self.assertEqual(note_map[(0, 1)].text, 'hello')
def test_merged_cells(self): book = xlrd.open_workbook(from_this_dir('xf_class.xls'), formatting_info=True) sheet3 = book.sheet_by_name('table2') row_lo, row_hi, col_lo, col_hi = sheet3.merged_cells[0] self.assertEqual(sheet3.cell(row_lo, col_lo).value, 'MERGED') self.assertEqual((row_lo, row_hi, col_lo, col_hi), (3, 7, 2, 5))
def test_excel_comments_with_multi_sheets(self): book = open_workbook(from_this_dir('test_comments_excel_sheet2.xlsx')) sheet = book.sheet_by_index(1) note_map = sheet.cell_note_map self.assertEqual(len(note_map), 1) self.assertEqual(note_map[(1, 1)].text, 'Note lives here') self.assertEqual(len(book.sheet_by_index(0).cell_note_map), 0)
def test_read_ragged(self): book = xlrd.open_workbook(from_this_dir('ragged.xls'), ragged_rows=True) sheet = book.sheet_by_index(0) self.assertEqual(sheet.row_len(0), 3) self.assertEqual(sheet.row_len(1), 2) self.assertEqual(sheet.row_len(2), 1) self.assertEqual(sheet.row_len(3), 4) self.assertEqual(sheet.row_len(4), 4)
def test_for_github_issue_101(self): # Test for non-Excel file with forward slash file separator # https://github.com/python-excel/xlrd/issues/101 workbook = xlrd.open_workbook( from_this_dir('self_evaluation_report_2014-05-19.xlsx')) worksheet = workbook.sheet_by_index(0) # Test reading sample data from the worksheet. cell = worksheet.cell(0, 0) self.assertEqual(cell.value, 'one') self.assertEqual(cell.ctype, xlrd.book.XL_CELL_TEXT)
def test_for_github_issue_150(self): # Test for non-Excel file with a non-lowercase worksheet filename. # https://github.com/python-excel/xlrd/issues/150 workbook = xlrd.open_workbook(from_this_dir('issue150.xlsx')) worksheet = workbook.sheet_by_index(0) # Test reading sample data from the worksheet. cell = worksheet.cell(0, 1) self.assertEqual(cell.value, 'Cycle') self.assertEqual(cell.ctype, xlrd.book.XL_CELL_TEXT) cell = worksheet.cell(1, 1) self.assertEqual(cell.value, 1) self.assertEqual(cell.ctype, xlrd.book.XL_CELL_NUMBER)
def test_for_github_issue_96(self): # Test for non-Excel file with forward slash file separator and # lowercase names. https://github.com/python-excel/xlrd/issues/96 workbook = xlrd.open_workbook(from_this_dir('apachepoi_49609.xlsx')) worksheet = workbook.sheet_by_index(0) # Test reading sample data from the worksheet. cell = worksheet.cell(0, 1) self.assertEqual(cell.value, 'Cycle') self.assertEqual(cell.ctype, xlrd.book.XL_CELL_TEXT) cell = worksheet.cell(1, 1) self.assertEqual(cell.value, 1) self.assertEqual(cell.ctype, xlrd.book.XL_CELL_NUMBER)
def test_for_github_issue_75(self): # Test <cell> inlineStr attribute without <si> child. # https://github.com/python-excel/xlrd/issues/75 workbook = xlrd.open_workbook(from_this_dir('apachepoi_52348.xlsx')) worksheet = workbook.sheet_by_index(0) # Test an empty inlineStr cell. cell = worksheet.cell(0, 0) self.assertEqual(cell.value, '') self.assertEqual(cell.ctype, xlrd.book.XL_CELL_EMPTY) # Test a non-empty inlineStr cell. cell = worksheet.cell(1, 2) self.assertEqual(cell.value, 'Category') self.assertEqual(cell.ctype, xlrd.book.XL_CELL_TEXT)
def test_merged_cells_xlsx(self): book = xlrd.open_workbook(from_this_dir('merged_cells.xlsx')) sheet1 = book.sheet_by_name('Sheet1') expected = [] got = sheet1.merged_cells self.assertEqual(expected, got) sheet2 = book.sheet_by_name('Sheet2') expected = [(0, 1, 0, 2)] got = sheet2.merged_cells self.assertEqual(expected, got) sheet3 = book.sheet_by_name('Sheet3') expected = [(0, 1, 0, 2), (0, 1, 2, 4), (1, 4, 0, 2), (1, 9, 2, 4)] got = sheet3.merged_cells self.assertEqual(expected, got) sheet4 = book.sheet_by_name('Sheet4') expected = [(0, 1, 0, 2), (2, 20, 0, 1), (1, 6, 2, 5)] got = sheet4.merged_cells self.assertEqual(expected, got)
def setUp(self): self.book = xlrd.open_workbook(from_this_dir('profiles.xls'), formatting_info=True) self.sheet = self.book.sheet_by_name('PROFILEDEF')
def test_err_cell_empty(self): # For cell with type "e" (error) but without inner 'val' tags open_workbook(from_this_dir('err_cell_empty.xlsx'))
def test_xlsx(self): # For now, we just check this doesn't raise an error. open_workbook(from_this_dir('reveng1.xlsx'))
def test_xlsx_simple(self): # For now, we just check this doesn't raise an error. open_workbook(from_this_dir('text_bar.xlsx'))
def test_BYTES_X00(self): # For now, we just check this doesn't raise an error. open_workbook(from_this_dir('picture_in_cell.xls'), formatting_info=True)
def test_ragged_rows_tidied_with_formatting(self): # For now, we just check this doesn't raise an error. open_workbook(from_this_dir('issue20.xls'), formatting_info=True)
def setUp(self): self.book = xlrd.open_workbook(from_this_dir('Formate.xls'), formatting_info=True) self.sheet = self.book.sheet_by_name(u('Blätt1'))
def test_tidy_dimensions(self): book = xlrd.open_workbook(from_this_dir('merged_cells.xlsx')) for sheet in book.sheets(): for rowx in xrange(sheet.nrows): self.assertEqual(sheet.row_len(rowx), sheet.ncols)
def test_excel_comments_multiline(self): book = open_workbook(from_this_dir('test_comments_excel.xlsx')) sheet = book.sheet_by_index(1) note_map = sheet.cell_note_map self.assertEqual(note_map[(1, 2)].text, '1st line\n2nd line')
def test_excel_comments_no_t_elements(self): book = open_workbook(from_this_dir('test_comments_excel.xlsx')) sheet = book.sheet_by_index(3) note_map = sheet.cell_note_map self.assertEqual(note_map[(0, 0)].text, '')
def setUp(self): self.book = xlrd.open_workbook(from_this_dir('profiles.xls'), formatting_info=True)
def setUp(self): book = xlrd.open_workbook(from_this_dir('formula_test_names.xls')) self.sheet = book.sheet_by_index(0)
def test_names_demo(self): # For now, we just check this doesn't raise an error. open_workbook( from_this_dir(os.path.join('..', 'examples', 'namesdemo.xls')), )
def test_tilde_path_expansion(self): with tempfile.NamedTemporaryFile(suffix='.xlsx', dir=os.path.expanduser('~')) as fp: shutil.copyfile(from_this_dir('text_bar.xlsx'), fp.name) # For now, we just check this doesn't raise an error. open_workbook(os.path.join('~', os.path.basename(fp.name)))
def setUp(self): self.book = open_workbook(from_this_dir('profiles.xls'))
def setUp(self): path = from_this_dir('biff4_no_format_no_window2.xls') self.book = open_workbook(path) self.sheet = self.book.sheet_by_index(0)