1、xlrd库打开处理excel文件,如果没有安装xlrd,可以先安装xlrd库
2、xml,可以采用dom进行处理
#!/usr/bin/python3
"""
# -*- coding: utf-8 -*-
# @Time : 2019/10/10 19:46
# @Author : husj27225
# @File : hu_exceltoxml.py
# @Software: PyCharm
"""
from imp import reload
import xlrd
import xml.dom.minidom
import os
import re
def IsChinese(contents):
flag = 0
zhPattern = re.compile(u'[\u4e00-\u9fa5]+')
# 一个小应用,判断一段文本中是否包含简体中:
match = zhPattern.search(contents)
if match:
flag = 1
return flag
# 打开execl文件,取文件中的内容
def open_excel(file):
try:
table = xlrd.open_workbook(file)
return table
except Exception as e:
print(str(e))
def translate_excel_to_xml(excel_absolute_path, name, generate_xml_dir, colnnameindex=0, by_index=0):
# 解析excel文件
table = open_excel(excel_absol