python是个什么东西---pyExcelerator---解析和生成不带样式的xls
# coding: UTF-8from pyExcelerator.ImportXLS import parse_xls
from pyExcelerator import Workbook
import string
class ExcelHandler():
#读取excel文件的内容,返回一个包含行列的集合
#@param file_full_name:
#@return: sheet_list[],],],]]
def read_xls(self, file_full_name):
results = []
#获得excel的所有"谢特"
sheets = parse_xls(file_full_name)
#迭代"谢特"-----------"谢特"是"谢特"的名字."谢特"是内容
for t in range(len(sheets)):
sheet = sheets
result = []
#获得谢特的长度,即,列数乘以行数的值
#已知有13个列,根据这个谢特的长度得到一共有多少行
length = len(sheet) / 13
#先创建一个满足excel格数的空数组
for ti in range(length + 1): #@UnusedVariable
result.append([" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "])
#迭代该谢特中的单元格,按照坐标插入到结果集中
for point in sheet:
str_point = str(point)
#从谢特中获得行和列
_x = string.atoi(str_point.replace(" ", "").split(',').replace("(", ""))
_y = string.atoi(str_point.replace(" ", "").split(',').replace(")", ""))
try:
if (str(_y) == '12') | (str(_y) == '1') | (str(_y) == '2') | (str(_y) == '4') | (str(_y) == '7'):
if unicode(sheet).find(".0") >= 0:
result = unicode(sheet).replace(".0", "")
continue;
result = unicode(sheet)
except:
print str(_x)+","+str(_y)+"---"+str(len(result))+"---"+str(t)
results.append(, result])
return results
#根据一个包含所有谢特的集合生成Excel文件
#@param sheet_list:sheet_list[],],],]]
#@param save_file_name:
def create_sheet_list(self, sheet_list, save_file_name):
wb = Workbook()
for sheet in sheet_list:
ws = wb.add_sheet(sheet)
# 写内容
for i in range(len(sheet)):
line = sheet
for j in range(len(line)):
item = line
ws.write(i , j, item)
wb.save(save_file_name)
#################
## 测试 读取--导出
#################
#eh = ExcelHandler()
#results = eh.read_xls('./datafiles/finallyLIYIN.xls')
#eh.create_sheet_list(results, "./hehehe.xls")
页:
[1]