#示例2:将示例1读取的 Excel 文件内容,写入到另一个Excel中,对学校所在省份进行简单判断。第一行合并单元格显示标题。
#(1)导入模块:xlwt
import xlrd
import xlwt
#(2)读取文件内容
def read_excel(file_name): #定义读取文件函数
wb = xlrd.open_workbook(file_name) #创建读取文件的对象wb
sheet = wb.sheet_by_index(0)
schools = []
for row in range(sheet.nrows):
school = []
for col in range(sheet.ncols):
content = sheet.cell_value(row,col)
school.append(content)
schools.append(school)
return schools #提供返回值
#(3)写入文件内容
def write_excel(schools): #定义写入文件函数
#(2)构造工作簿:Workbook
wb = xlwt.Workbook(encoding = 'utf-8'