378 发表于 2017-4-26 09:47:27

python读写xls

读取xls:
 
xls_data = xlrd.open_workbook('D:\\delete\\aaaaaa.xls')
sheetName = xls_data.sheet_names();
print sheetName
 
table = xls_data.sheets()
 
rownum = table.nrows;
colnum = table.ncols;
 
print rownum
i=0
while i<rownum:
    rowValue = table.row_values(i);
    j = 0
    while j<colnum:
        print rowValue
        j = j+1;
    print table.row_values(i)
    i = i+1
    
 
    
for i in range(0,rownum-1):
    for j in range(0,colnum-1):
        print table.cell(i,j).value
 
写xls:
 
  file = xlwt.Workbook(encoding='utf-8',style_compression=0)
  table = file.add_sheet('bbbb',cell_overwrite_ok=True)
  table.write(0,0,'bbbb_张博')
  file.save('D:\\delete\\bbbb.xls');
 
 
 
 
 
页: [1]
查看完整版本: python读写xls