excel 工具完善

dev_chengFeng
gaoxin 2020-07-06 10:56:55 +08:00
parent d62d808e80
commit 5a2a3f83d2
5 changed files with 1764 additions and 3493 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -181,13 +181,13 @@ class Test():
def WriteXlsxDataByCol(self, content, path, fileName, colName, rowNums):
_savePath = path + fileName +'.xlsx'
_rBook = xlrd.open_workbook(_savePath)
_wBook = copy.copy(_rBook)
_workSheet = _wBook.get_sheet(0)
# _rBook = xlrd.open_workbook(_savePath)
_wBook = openpyxl.load_workbook(_savePath)#copy.copy(_rBook)
_workSheet = _wBook.worksheets[0]
_colNum = self.ColToNum(colName)
for row in rowNums:
_workSheet.write(row, _colNum, content)
_workSheet.cell(row + 1, _colNum + 1, content)
_wBook.save(_savePath)
@ -257,9 +257,9 @@ class Test():
_filePath = path + fileName + ".xlsx"
_rBook = xlrd.open_workbook(_filePath)
_wBook = copy.copy(_rBook)
_rSheet = _rBook.sheet_by_index(0)
_wSheet = _wBook.get_sheet(0)
_wBook = openpyxl.load_workbook(_filePath)#copy.copy(_rBook)
_wSheet = _wBook.worksheets[0]
_cData = _rSheet.col_values(_colNum)
for _index in range(len(_cData)):
@ -269,7 +269,7 @@ class Test():
if self._TranslateData.has_key(_content):
_translateContent = self._TranslateData[_content][language].decode('utf-8')
if _translateContent and _translateContent != "":
_wSheet.write(_index, _colNum, _translateContent)
_wSheet.cell(_index + 1, _colNum + 1, _translateContent)
else:
print("no ["+ language +"] translate for :" + _content)
_wBook.save(_filePath)
@ -294,5 +294,5 @@ class Test():
t = Test()
t.init()
# t.Export()
t.ReplaceChanges()
# t.Translate("tchinese")
# t.ReplaceChanges()
# t.Translate("english")