Every line of 'how to import excel 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.
30 def import_openpyxl(self): 31 """Import the requests module """ 32 try: 33 import openpyxl 34 from openpyxl import load_workbook 35 except ImportError: 36 print("openpyxl module is not installed"\ 37 "Please install openpyxl module to"\ 38 "perform any activities related to parsing xl sheets") 39 else: 40 self.openpyxl = openpyxl 41 self.load = load_workbook
126 @classmethod 127 def do_import_excel(cls, workbook, models, logger): 128 raise NotImplementedError("Not implemented for %s" % cls)
11 def processExcel(filePath, fileName): 12 if "." in fileName: 13 fileName = fileName.split('.') 14 fileName = fileName[0] 15 data = xlrd.open_workbook(filePath) 16 table = data.sheets()[0] 17 nrows = table.nrows 18 ncols = table.ncols 19 20 cs_fields_index = []#filed index 21 golang_fields_index = []#filed index 22 tableKeysIndex = [] 23 24 if table.nrows == 0 or table.ncols == 0: 25 print("empty file:" + fileName) 26 27 for index in range(ncols): 28 CS_row = table.cell(1, index).value 29 if CS_row == "C" or CS_row == "CS": 30 cs_fields_index.append(index) 31 32 if CS_row == "S" or CS_row == "CS": 33 golang_fields_index.append(index) 34 35 if len(cs_fields_index) > 0: 36 cs_files.append(fileName) 37 GenCSTableManagerFile(fileName, cs_fields_index, table) 38 GenCSTableData(fileName, cs_fields_index, table) 39 40 if len(golang_fields_index) > 0: 41 go_files.append(fileName) 42 GenGoTableManagerFile(fileName, golang_fields_index, table) 43 GenGolangTableData(fileName, golang_fields_index, table)
399 def excel_import(self): 400 self.current_project.excel_import()
56 def 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')
16 def copy_excel(excelpath1, excelpath2): 17 """复制excel,把 excelpath1 数据复制到 excelpath2""" 18 wb2 = openpyxl.Workbook() 19 wb2.save(excelpath2) 20 # 读取数据 21 wb1 = openpyxl.load_workbook(excelpath1) 22 wb2 = openpyxl.load_workbook(excelpath2) 23 sheets1 = wb1.sheetnames 24 sheets2 = wb2.sheetnames 25 sheet1 = wb1[sheets1[0]] 26 sheet2 = wb2[sheets2[0]] 27 max_row = sheet1.max_row # 最大行数 28 max_column = sheet1.max_column # 最大列数 29 for m in list(range(1, max_row + 1)): 30 for n in list(range(97, 97 + max_column)): # chr(97)='a' 31 n = chr(n) # ASCII字符 32 i = '%s%d' % (n, m) # 单元格编号 33 cell1 = sheet1[i].value # 获取data单元格数据 34 sheet2[i].value = cell1 # 赋值到test单元格 35 wb2.save(excelpath2) # 保存数据 36 wb1.close() # 关闭excel 37 wb2.close()
44 def 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
488 def excel(self): 489 """Query data base and build nsf and doe excels.""" 490 rc = self.rc 491 if not rc.people: 492 sys.exit("please rerun specifying --people PERSON") 493 if isinstance(rc.people, str): 494 rc.people = [rc.people] 495 since_date = get_since_date(rc) 496 target = rc.people[0] 497 query_results = self.query_ppl(target, since_date=since_date) 498 self.render_template1(**query_results) 499 self.render_template2(**query_results)
68 def worksheet_from_excel(excel_sheet): 69 worksheet = Worksheet() 70 for col in range(excel_sheet.ncols): 71 for row in range(excel_sheet.nrows): 72 cell = excel_sheet.cell(row, col) 73 if cell.ctype == XL_CELL_ERROR: 74 formula = '=%s' % (error_text_from_code[cell.value], ) 75 elif cell.ctype == XL_CELL_DATE: 76 formula = '=DateTime(%s, %s, %s, %s, %s, %s)' % xldate_as_tuple( 77 cell.value, excel_sheet.book.datemode) 78 else: 79 formula = unicode(excel_sheet.cell(row, col).value) 80 worksheet[col + 1, row + 1].formula = formula 81 return worksheet
34 def 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)