import io from openpyxl import Workbook from openpyxl drawing image im

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import io
from openpyxl import Workbook
from openpyxl.drawing.image import Image
from openpyxl.styles import Alignment
from openpyxl.utils import get_column_letter
wb = Workbook()
ws = wb.active
fileName = 'Lsqltext.200131231859'
path = '/Users/entropy/TEST/' + fileName
file = open(path, 'r')
rows = file.read().split('}}')
ws.column_dimensions['A'].width = 25
ws.cell(column=1, row=1, value='Date')
ws.cell(column=2, row=1, value='Time')
ws.cell(column=3, row=1, value='IP')
ws.cell(column=4, row=1, value='User ID')
ws.cell(column=5, row=1, value='Task ID')
ws.cell(column=6, row=1, value='Code')
row = 2
for row in rows[0:-1]:
tmp0 = row.split(' ', 5)
tmp1 = tmp0[2].split('\t')
total = tmp0[0: 2] + tmp1 + tmp0[3:]
ws.cell(column=1, row=row, value=total[0])
ws.cell(column=2, row=row, value=total[1])
ws.cell(column=3, row=row, value=total[2])
ws.cell(column=4, row=row, value=total[3])
ws.cell(column=5, row=row, value=total[4])
ws.cell(column=6, row=row, value=total[5])
row += 1
wb.close()