1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
import csv import xlrd import pandas as pd
listargs = ['绩效结果','岗位名称','绩效分数','合同单位']
wb = xlrd.open_workbook('input.xlsx') get_sheet_name = wb.sheet_names()[0] nameArr = []
for a in range(0,len(wb.sheet_names())): nameArr.append(wb.sheet_names()[a])
def is_number(s): try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def getRowsDatas(str,sh,nameRow): can = -1 for num in range(0, sh.ncols): if (sh.row_values(nameRow)[num] == str): can = num break return can
def save(data): with open('output.csv', 'w', newline='') as csv_file: f_csv = csv.writer(csv_file) f_csv.writerows(data) def openSheet(name): print(name) sh = wb.sheet_by_name(name) nameCol = 0 nameRow = 0 var1 = [] for a in range(0,len(listargs)): var1.append([]) for i in range(sh.nrows): for num in range(0,sh.ncols): if(sh.row_values(i)[num] == '姓名'): nameRow = i nameCol = num break for index,a in enumerate(listargs): print(a,index) var1[index] = getRowsDatas(a, sh, nameRow) print(var1[index])
for line in range(nameRow+1,sh.nrows): if(is_number(sh.row_values(line)[0])): arr = [] arr.append(sh.row_values(line)[nameCol]) for a in var1: if(a == -1): arr.append('') else: arr.append(sh.row_values(line)[a]) datasNames.append(arr)
datasNames = []
for name in nameArr: openSheet(name) print(datasNames) save(datasNames) input()
|