# 首先了解xlrd模块
#data = xlrd.open_workbook(‘文件名‘) 打开Excel文件
#ret = data.sheet_names() 获取所有工作表名
#sheet = data.sheet_by_name(ret) 获取ret工作表中所有数据
#sheet.neows 获取行数
#sheet.ncols 获取列数
#sheet.cell_value(1,2) 获取0行1列单元格数据
import xlrd
data = xlrd.open_workbook("./ces4.xls")
txt = open("4.xml", "a") # 文件读写方式是追加
count = data.sheet_names() # 统计所有的应用名
# print(‘------------------------‘)
number = len(count) # 获取又多少个表单
a = ‘‘‘<?xml version=‘1.0‘ encoding=‘UTF-8‘?>
\n‘‘‘
Text = a
txt.write(Text)
# print(sheet.cell_value(2, 3))
for i in range(number):
sheet_name = data.sheet_names()[i] # 第一个应用的名字
sheet = data.sheet_by_name(sheet_name) # 获取第一个表格里的数据
ret = sheet.nrows # 每个表的行数
# print(ret)
# print(i+1)
for i in range(ret):
if sheet.cell_value(i+1, 3) == ‘数据类型‘:
a=‘‘‘\n\n
\n
\n
‘‘‘ % sheet_name
print(sheet_name) # 打印统计的表格名
Text = a
txt.write(Text)
elif sheet.cell_value(i+1, 3) == ‘文本‘:
Text = "\n" %(sheet.cell_value(i+1, 5), sheet.cell_value(i+1, 2),‘text‘)
txt.write(Text)
elif sheet.cell_value(i + 1, 3) == ‘字典‘:
Text = "\n" % (
sheet.cell_value(i + 1, 5), sheet.cell_value(i + 1, 2), ‘dist‘, sheet.cell_value(i + 1, 6) )
txt.write(Text)
elif sheet.cell_value(i + 1, 3) == ‘部门‘:
Text = "\n" % (
sheet.cell_value(i + 1, 5), sheet.cell_value(i + 1, 2), ‘bumen‘)
txt.write(Text)
elif sheet.cell_value(i + 1, 3) == ‘日期‘:
Text = "\n" % (
sheet.cell_value(i + 1, 5), sheet.cell_value(i + 1, 2), ‘time‘)
txt.write(Text)
elif sheet.cell_value(i + 1, 3) == ‘引用‘:
Text = "\n" % (
sheet.cell_value(i + 1, 5), sheet.cell_value(i + 1, 2), ‘time‘, sheet.cell_value(i + 1, 6), sheet.cell_value(i + 1, 5))
txt.write(Text)
elif sheet.cell_value(i + 1, 3) == ‘‘:
end = ‘\n‘
txt.write(end)
break
a = ‘\n‘
Text = a
txt.write(Text)
txt.close()