打开一个 excel
from xlrd import open_workbook
workbook = open_workbook(r'suppiler_data.xlsx')
查看 excel 有几张 sheet
workbook.nsheets
查看 excel 有多少 sheet,并且打印名称,行数,列数
for sheet in workbook.sheets():
print(sheet.name,sheet.nrows,sheet.ncols)
从一个 excel 的指定 sheet 读取写入一个新的 excel 的sheet
from xlrd import open_workbook
from xlwt import Workbook
# 实例化一个对象
output_workbook = Workbook()
# 为输出的工作簿加一个 sheet 名为 123 的
output_worksheet = output_workbook.add_sheet('123')
with open_workbook(r'suppiler_data.xlsx') as workbook:
# 引用此工作表中 sheet 名为 1 的
worksheet = workbook.sheet_by_name('1')
for row in range(worksheet.nrows):
for col in range(worksheet.ncols):
output_worksheet.write(row,col,worksheet.cell_value(row,col))
# 保存新的 excel
output_workbook.save(r'zjk.xlsx')