from 【txt】写在excel2007,CMD里按顺序打印,但是excel文件数据顺序不对
from 【txt】write in excel2007,In CMD print in right sequence, but the excel file data didn't in right sequence
openpyxl-2.5.0a1 python3.5
来自【.txt】写在excel 2007,CMD打印顺序正确,但是excel文件数据顺序不对
这里是我的代码:
import openpyxl
loadActive = open('F:\pythoncode\ActivityList.txt', encoding="utf-16")
wb = openpyxl.load_workbook('F:\pythoncode\example_1.xlsx')
dataActive = loadActive.readlines()
sheet = wb.get_active_sheet()
c = []
for i in range(len(dataActive)):
c += dataActive[i].split('\t')
j = 1
columnNum = 1
for i in range(int(len(c))):
if i < 3:
sheet.cell(row = j,column = columnNum).value = c[i]
columnNum += 1
else:
if i % 4 == 0:
j += 1
columnNum = 1
sheet.cell(row = j,column = columnNum).value = c[i]
print(sheet.cell(row = j,column = columnNum))
print(c[i])
else:
sheet.cell(row = j,column = columnNum).value = c[i]
columnNum += 1
print(sheet.cell(row = j,column = columnNum))
print(c[i])
loadActive.close()
wb.save('F:\pythoncode\example_1.xlsx')
txt文件数据:
Id ActivityId TimeDesc Remark
int_cs int_c string_c string
note Actid timessss memo
1 2 9:00-9:40 hello1
2 13 10:00-10:40 hello2
3 43 11:30-11:45 hello3
4 22 12:00-14:00 hello4
5 43 12:30-12:45 hello5
6 2 15:00-15:40 hello6
7 13 16:00-16:40 hello7
8 43 17:30-17:45 hello8
9 22 18:00-20:00 hello9
10 43 18:30-18:45 hello10
11 25 20:15 hello11
12 23 20:30-20:45 hello12
13 1 20:45-21:15 hello13
这是excel中的扭动顺序不对
在cmd中按正确的顺序打印
import openpyxl
loadActive = open('F:\pythoncode\ActivityList.txt', encoding="utf-16")
wb = openpyxl.load_workbook('F:\pythoncode\example_1.xlsx')
# ' '.join(ActiveList)
dataActive = loadActive.readlines()
print(dataActive)
sheet = wb.get_active_sheet()
c = []
#this loop to solve the \t and \n
for i in range(len(dataActive)):
c1 = dataActive[i].rstrip('\n')
c += c1.split('\t')
print(c[i])
print(c)
j = 1
columnNum = 1
for i in range(int(len(c))):
#delete simplified the logic
if i % 4 == 0:
j += 1
columnNum = 1
sheet.cell(row = j,column = columnNum).value = c[i]
columnNum += 1
loadActive.close()
wb.save('F:\pythoncode\example_1.xlsx')
另一个问题:第一行会导入一个空
openpyxl-2.5.0a1 python3.5
来自【.txt】写在excel 2007,CMD打印顺序正确,但是excel文件数据顺序不对
这里是我的代码:
import openpyxl
loadActive = open('F:\pythoncode\ActivityList.txt', encoding="utf-16")
wb = openpyxl.load_workbook('F:\pythoncode\example_1.xlsx')
dataActive = loadActive.readlines()
sheet = wb.get_active_sheet()
c = []
for i in range(len(dataActive)):
c += dataActive[i].split('\t')
j = 1
columnNum = 1
for i in range(int(len(c))):
if i < 3:
sheet.cell(row = j,column = columnNum).value = c[i]
columnNum += 1
else:
if i % 4 == 0:
j += 1
columnNum = 1
sheet.cell(row = j,column = columnNum).value = c[i]
print(sheet.cell(row = j,column = columnNum))
print(c[i])
else:
sheet.cell(row = j,column = columnNum).value = c[i]
columnNum += 1
print(sheet.cell(row = j,column = columnNum))
print(c[i])
loadActive.close()
wb.save('F:\pythoncode\example_1.xlsx')
txt文件数据:
Id ActivityId TimeDesc Remark
int_cs int_c string_c string
note Actid timessss memo
1 2 9:00-9:40 hello1
2 13 10:00-10:40 hello2
3 43 11:30-11:45 hello3
4 22 12:00-14:00 hello4
5 43 12:30-12:45 hello5
6 2 15:00-15:40 hello6
7 13 16:00-16:40 hello7
8 43 17:30-17:45 hello8
9 22 18:00-20:00 hello9
10 43 18:30-18:45 hello10
11 25 20:15 hello11
12 23 20:30-20:45 hello12
13 1 20:45-21:15 hello13
这是excel中的扭动顺序不对
在cmd中按正确的顺序打印
import openpyxl
loadActive = open('F:\pythoncode\ActivityList.txt', encoding="utf-16")
wb = openpyxl.load_workbook('F:\pythoncode\example_1.xlsx')
# ' '.join(ActiveList)
dataActive = loadActive.readlines()
print(dataActive)
sheet = wb.get_active_sheet()
c = []
#this loop to solve the \t and \n
for i in range(len(dataActive)):
c1 = dataActive[i].rstrip('\n')
c += c1.split('\t')
print(c[i])
print(c)
j = 1
columnNum = 1
for i in range(int(len(c))):
#delete simplified the logic
if i % 4 == 0:
j += 1
columnNum = 1
sheet.cell(row = j,column = columnNum).value = c[i]
columnNum += 1
loadActive.close()
wb.save('F:\pythoncode\example_1.xlsx')
另一个问题:第一行会导入一个空