8 examples of 'read xls file in python' in Python

Every line of 'read xls file in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
8def read(self):
9 workbook = self.open_workbook()
10 worksheet = self.get_worksheet(workbook)
11
12 data = self.extract_data(worksheet)
13 data = data[self.options.get('skip', 0):]
14
15 headers = self.options.get('headers', True)
16 if headers is True:
17 headers, data = data[0], data[1:]
18 if headers:
19 return [dict(zip(headers, row)) for row in data]
20 else:
21 return data
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

34def read_excel_file(f):
35 dialect = csv.Sniffer().sniff(codecs.EncodedFile(f, "utf-8").read(1024))
36 #f.open()
37 return UnicodeCsvReader(codecs.EncodedFile(f, "utf-8"),
38 "utf-8", dialect=dialect)
90def open_content(self, file_content, skip_hidden_sheets=True, **keywords):
91 self._keywords = keywords
92 self._file_content = file_content
93 self.__skip_hidden_sheets = skip_hidden_sheets
20def test_xls_with_sheet(self):
21 with open('examples/sheets.xls', 'rb') as f:
22 output = xls.xls2csv(f, sheet='data')
23
24 with open('examples/testxls_converted.csv', 'r') as f:
25 self.assertEquals(f.read(), output)
44def get_xls_to_list(excelname, sheetname):
45 """
46 读取excel表,返回一个list,只是返回第一列的值
47 return [1,2,3,4,5]
48 """
49 datapath = os.path.join(data_path, excelname)
50 excel = xlrd.open_workbook(datapath)
51 table = excel.sheet_by_name(sheetname)
52 result = [table.row_values(i)[0].strip() for i in range(1,table.nrows)]
53 return result
81def parse_workbook(self):
82 raise NotImplementedError
54def __init__(self, filename, module, sheet_index=0):
55 super(Parser, self).__init__()
56
57 self.key_name = getattr(module, "KEY_NAME", "ID")
58 self.is_multi_key = getattr(module, "MULTI_KEY", False)
59
60 self.filename = filename
61 self.config = getattr(module, "CONFIG", None)
62
63 self.header = None
64 self.sheet_types = {}
65 self.converters = None
66 self.sheet = {}
67
68 self.field_2_col = {}
69 self.header_2_config = {}
70
71 self.sheet_index = sheet_index
72 self.header_row_index = 2
73 self.type_row_index = 3
74 self.data_row_index = 4
75
76 self.header_data = None
77 self.type_data = None
78
79 self.set_module(module)
56def open_excel_input_file(self, path):
57 if not path or path == '-':
58 if six.PY2:
59 return six.BytesIO(sys.stdin.read())
60 else:
61 return six.BytesIO(sys.stdin.buffer.read())
62 else:
63 return open(path, 'rb')

Related snippets