一、代码块
import os
import xlwt,xlrd
curren_path=os.getcwd()
os.walk(curren_path)
xls_files=[]
for path,dir,files in os.walk(curren_path):
for file in files:
if "部.xls" in file:
xls_files.append(file)
company_xls = "公司财务报表.xls"
company_wb = xlwt.Workbook()
for xls in xls_files:
wb=xlrd.open_workbook(xls)
sheet = wb.sheet_by_index(0)
name = xls.replace('.xls','')
tsheet = company_wb.add_sheet(name)
for row in range(sheet.nrows):
for col in range(sheet.ncols):
value=sheet.cell_value(row,col)
tsheet.write(row,col,value)
company_wb.save(company_xls)
二、运行结果
这样一来,我们所需要整合的数据,就被放到一个表中了,表格量大的时候就可以体现出代码的好处了。
|