-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxlwrite.py
58 lines (48 loc) · 1.64 KB
/
xlwrite.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import xlwt;
from datetime import datetime;
from xlrd import open_workbook;
from xlwt import Workbook;
from xlutils.copy import copy
from pathlib import Path
'''style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('example.xls')
'''
def output(filename, sheet,num, name, present):
my_file = Path(filename+str(datetime.now().date())+'.xls');
if my_file.is_file():
rb = open_workbook(filename+str(datetime.now().date())+'.xls');
book = copy(rb);
sh = book.get_sheet(0)
# file exists
else:
book = xlwt.Workbook()
sh = book.add_sheet(sheet)
style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',
num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
#variables = [x, y, z]
#x_desc = 'Display'
#y_desc = 'Dominance'
#z_desc = 'Test'
#desc = [x_desc, y_desc, z_desc]
sh.write(0,0,datetime.now().date(),style1);
col1_name = 'Name'
col2_name = 'Present'
sh.write(1,0,col1_name,style0);
sh.write(1, 1, col2_name,style0);
sh.write(num+1,0,name);
sh.write(num+1, 1, present);
#You may need to group the variables together
#for n, (v_desc, v) in enumerate(zip(desc, variables)):
fullname=filename+str(datetime.now().date())+'.xls';
book.save(fullname)
return fullname;