import xlrd
import xlwd
import sys
filename=sys.argv[1]
file=xlrd.open_workbook(filename)
sheet1=file.sheet_by_index(0)
cols=sheet1.col_values(4)
allcols="".join(cols)
nums=allcols.count('通信')
print(nums)
----------------
for var in cols[1:]:
if int(var)==11:
i=i+1
------------------
>>> row=sheet.row_values(5)
>>> print(row)
['曹操', 11.0, 11.0, 11.0]
>>>
两种场景:
1.按照责任田统计当前sheet的问题个数
1)按照sheet分别进行统计,一个sheet是一个环境
2)逐行判断是否是责任田,字典存储环境和问题数
是的话,将相应的行号记录到该环境的全局数组中,累加该环境的问题总数
否的话,读取下一条
3)最后输出字典变量中的值
4)将该环境的全局数组中的行号对应的行写到一个out文件中对应的sheet中
2.统计一个sheet里的责任田内的不同类型问题的个数
1)列表存储所有类型的问题
2)逐行判断是否是责任田,
是的话,将相应的行号记录到全局数组中,累加到相应的数组位置上(用字典存储)
否的话,读取下一条
3)最后输出字典变量中的值
4)将全局数组中的行号对应的行写到一个out文件中
-----------------------------------------
文件写入方案
>>> import xlwt
>>> import xlrd
>>> filename=li0801.xlsx
Traceback (most recent call last):
File "
NameError: name 'li0801' is not defined
>>> filename="li0801.xlsx"
>>> file=xlrd.open_workbook(filename)
>>> sheet=file.sheet_by_index(0)
>>> row=sheet.row_values(4)
>>> print(row)
['刘备', 12.0, 12.0, 11.0]
>>> out=xlwt.Workbook()
>>> sheet1=out.add_sheet("sheet1")
>>> i=0
>>> for c in range(0, len(row)):
... sheet1.write(i, c, row[c])
...
>>> out.save("out.xlsx")
>>> out.save('out.xlsx)
File "
out.save('out.xlsx)
^
SyntaxError: EOL while scanning string literal
>>> out.save('out.xlsx')
>>> out.save('out.xls')
>>> row1=sheet.row_values(6)
>>> for c in range(0, len(row1)):
... sheet1.write(i+1, c, row[c])
...
>>> out.save('out.xls')
>>> for c in range(0, len(row1)):
... sheet1.write(i+2, c, row1[c])
...
>>> out.save('out.xls')
Traceback (most recent call last):
File "
File "C:\ProgramData\Anaconda3\lib\site-packages\xlwt\Wor
kbook.py", line 710, in save
doc.save(filename_or_stream, self.get_biff_data())
File "C:\ProgramData\Anaconda3\lib\site-packages\xlwt\Com
poundDoc.py", line 262, in save
f = open(file_name_or_filelike_obj, 'w+b')
PermissionError: [Errno 13] Permission denied: 'out.xls'
>>> out.save('out.xls')
>>>