python 表格排序
import xlwt
import xlrd
import xlrd
workbook=xlwt.Workbook(encoding='utf-8')
sheet=workbook.add_sheet('工作表')
sheet=workbook.add_sheet('工作表')
dic={}
data=xlrd.open_workbook('表1.xlsx')
all_sheet_list=data.sheet_names()
print(all_sheet_list)
table=data.sheet_by_name(all_sheet_list[0])
data=xlrd.open_workbook('表1.xlsx')
all_sheet_list=data.sheet_names()
print(all_sheet_list)
table=data.sheet_by_name(all_sheet_list[0])
row_txt_list=table.row_values(0)#行内容列表
a=0
for i in row_txt_list:
sheet.write(0,a,i)#行,列,文字
a+=1
for i in row_txt_list:
sheet.write(0,a,i)#行,列,文字
a+=1
nrows=table.nrows
print(nrows)
col_txt_list=table.col_values(0)#列内容列表
print(col_txt_list)
count=0
for i in col_txt_list:
if i=='vid':continue
count+=1
dic[i]=count
print(dic)
col_txt_list.sort()
print(nrows)
col_txt_list=table.col_values(0)#列内容列表
print(col_txt_list)
count=0
for i in col_txt_list:
if i=='vid':continue
count+=1
dic[i]=count
print(dic)
col_txt_list.sort()
hang=1
for i in col_txt_list:
if i=='vid':continue
row_list=table.row_values(dic[i])#行内容列表
b=0
for j in row_list:
sheet.write(hang,b,str(j))
b+=1
hang+=1
for i in col_txt_list:
if i=='vid':continue
row_list=table.row_values(dic[i])#行内容列表
b=0
for j in row_list:
sheet.write(hang,b,str(j))
b+=1
hang+=1
workbook.save('result.csv')

浙公网安备 33010602011771号