# coding=utf-8
__author__ = ''
import xlrd
import os
import sys
import re
import time
reload(sys)
sys.setdefaultencoding('utf8')
currentFilePath = os.path.realpath(__file__);
currentDir = os.path.dirname(currentFilePath);
def findKeyRow(sheetV):
rowIndex = 0;
for row in range(1,sheetV.nrows):
cellType = sheetV.cell_type(row,0);
if cellType == 1:
rowIndex = row;
break;
return rowIndex
def getLanguageStr(fileName):
keyStr = ""
if fileName.endswith(".js") :
keyStr = "\t%s\t:\t%s"
elif fileName.endswith(".lua") :
keyStr = "\t%s\t=\t%s"
return keyStr
def readTitleListFromExcelSheet(sheetV,outPutList,fileName):
sheetKeyRow = findKeyRow(sheetV);
temp = os.path.splitext(fileName)
filePrefix = temp[0];
fileSuffix = temp[1];
filePrefix +="DB";
outPutList.append(time.strftime("//该文件有对应的excel读取:Date:%y-%m-%d\n\n",time.localtime(time.time())));
if fileSuffix == ".js":
outPutList.append("var %s = {}\n\n"%filePrefix);
outPutList.append('Object.defineProperty(%s,"%s",{//%s\n\tValue:%s,\n\tenumerable:false\n})\n\n'%(filePrefix,"rowLength","行数",sheetV.nrows))
outPutList.append('Object.defineProperty(%s,"%s",{//%s\n\tValue:%s,\n\tenumerable:false\n})\n\n'%(filePrefix,"cowLength","列数",sheetV.ncols))
elif fileSuffix == ".lua":
outPutList.append("local %s = {}\n\n"%filePrefix);
for col in range(sheetV.ncols):
key = sheetV.cell_value(sheetKeyRow,col);
titleValue = sheetV.cell_value(0,col);
if key!="":
cellType = sheetV.cell_type(sheetKeyRow,col);
cellValue = sheetV.cell_value(sheetKeyRow,col);
tempStr = "";
if cellType == 1:
cellValue = "%s"�llValue;
elif cellType ==2:
cellValue = "%d"�llValue;
if fileSuffix == ".js":
tempStr = 'Object.defineProperty(%s,"%s",{//%s\n\tValue:%s,\n\tenumerable:false\n})\n\n'%(filePrefix,cellValue,titleValue,0);
elif fileSuffix == ".lua":
tempStr = "-- %s : %s\n\n"%(cellValue,titleValue);
outPutList.append(tempStr)
def readValueListFromExcelSheet(sheetV,outPutList,fileName):
sheetKeyRow = findKeyRow(sheetV);
keyStr = getLanguageStr(fileName);
temp = os.path.splitext(fileName)
filePrefix = temp[0]+"DB";
fileSuffix = temp[1];
for row in range(sheetKeyRow+1,sheetV.nrows):
if sheetV.cell_value(row,0)=="":
continue
outPutList.append('%s[%d]=\n{\n'%(filePrefix,sheetV.cell_value(row,0)));
maxCol = sheetV.ncols;
for col in range(sheetV.ncols):
key = sheetV.cell_value(sheetKeyRow,col);
if key!="" and key!=0 :
cellType = sheetV.cell_type(row,col);
cellValue = sheetV.cell_value(row,col);
tempStr = ""
if cellType == 1:
if cellValue == "":
cellValue = '" " '
cellValue = '"%s"'�llValue
elif cellType ==2:
if cellValue == "":
cellValue = 0;
cellValue = "%d"�llValue
else: