def dstFile(self): """ 导出文件路径 """ if self.__dstFile is None: return None path = os.path.join(CustomConfig().dstRoot, self.__dstFile) return Path.normalizePath(path)
def getWorkbook(self, fileName, encoding): """ 获取 Excel 工作簿 Excel 文件不存在,或者 Excel 在操作中,则引起 ExcelComException fileName 的编码必须与本程序脚本使用的编码一致 """ fileName = Path.normalizePath(fileName) if fileName in self.__wbooks: return self.__wbooks[fileName] sysFileName = script2sys(fileName) sysFileName = Path.normalizePath(sysFileName) if not os.path.exists(sysFileName): raise ExcelFixException("errUnexist", file=fileName) try: wbook = xlrd.open_workbook(sysFileName) self.__wbooks[fileName] = wbook return wbook except xlrd.XLRDError, err: raise ExcelFixException("errUnexist", file=fileName)
def getSrcFullName(srcFile): """ 获取数据源文件全路径 """ for root in CustomConfig().srcRoots: fullName = os.path.join(root, srcFile) fullName = Path.normalizePath(fullName) if os.path.exists(script2sys(fullName)): return fullName return srcFile
def getSheet(self, fileName, encoding): """ 获取一个 CSV 表格 fileName 的编码必须与本程序脚本使用的编码一致 """ fileName = Path.normalizePath(fileName) sysFileName = script2sys(fileName) if fileName in self.__sheets: return self.__sheets[fileName] if not os.path.exists(sysFileName): raise CSVFixException("errUnexist", file=fileName) try: file = open(sysFileName, "rb") except Exception, err: raise DataSourceException(sys2script(err.__str__()))
def fileName(self): return Path.normalizePath(self.__sheet.fileName)