1 Excel工作包读取
windows xlrd,xlwt excel相关包安装;
pip install xlrd
pip install xlwt
vi 1excel_introspect_workbook.py
#encoding=utf8
#!/usr/bin/env python3
import sys
from xlrd import open_workbook
input_file=sys.argv[1]
workbook=open_workbook(input_file)
print('Number of worksheets:',workbook.nsheets)
for worksheet in workbook.sheets():
print("Workbook name:",worksheet.name,"\tRows:",worksheet.nrows,"\tColumns:",worksheet.ncols)
--需要安装依赖: 安装xlrd模块。
yum install libffi-devel -y
unzip xlrd-master.zip
cd xlrd-master
python3 setup.py install
C:\Users\4201.HJSC>python C:\Users\4201.HJSC\PycharmProjects\pythonProject\1excel_introspect_workbook.py \
C:\Users\4201.HJSC\Desktop\Python_exercise\sales_2013.xls
Number of worksheets: 3
Workbook name: january_2013 Rows: 7 Columns: 5
Workbook name: february_2013 Rows: 7 Columns: 5
Workbook name: march_2013 Rows: 7 Columns: 5
#需要注意的是:xlrd 只支持xls 格式。不支持:xlsx
#结果linux;
[root@oracle1 python]# python3 1excel_introspect_workbook.py sales_2013.xls
Number of worksheets: 3
Workbook name: january_2013 Rows: 7 Columns: 5
Workbook name: february_2013 Rows: 7 Columns: 5
Workbook name: march_2013 Rows: 7 Columns: 5
2.总结
#需要注意的是:xlrd 只支持xls 格式。不支持:xlsx