python write msg to the excel
def write_xls():
f = openpyxl.Workbook()
f.create_chartsheet()
sheet_names = wb2.get_sheet_names()
sheet_names = list(sheet_names)
print(sheet_names[0])
table = wb2.get_sheet_by_name(sheet_names[0])
table.cell(row=1, column=1).value = '1'
下段代码主要是对excel某一列进行排序并查出该值对应的时间
import openpyxl
import copy
wb = openpyxl.load_workbook(filename="test,xlsx")
#get sheet name for the sheet table
#return value is a tuple
sheet_names = wb.get_sheet_names()
#transfer it to the list
sheet_names = list(sheet_names)
print(sheet_names[0])
table = wb.get_sheet_by_name(sheet_names[0])
#get the max column and the row
max_cols = table.max_column
max_rows = table.max_row
ar_column_requests = []
ar_column_requests1 = []
for i in range(max_rows):
# print(table.cell(row=3+i, column=2).value)
if table.cell(row=3+i, column=2).value:
ar_column_requests.append(table.cell(row=3+i, column=2).value)
ar_column_requests1.append(table.cell(row=3+i, column=1).value)
print(ar_column_requests)
#deep copy can malloc another space to store the array
ar_info_temp = copy.deepcopy(ar_column_requests)
ar_column_requests.sort(reverse=True)
max = ar_column_requests[0]
index_msg = ar_info_temp.index(max)
print(index_msg)
print(ar_column_requests1[index_msg])
the excel is as below