-
Notifications
You must be signed in to change notification settings - Fork 0
/
Excel.py
36 lines (29 loc) · 1.11 KB
/
Excel.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
import pandas as pd
class exceloutput:
def __init__(self):
self.data = {}
def addworksheet(self, data, name):
self.data[name] = data
def printCSV(self, report, name, outputdir):
outputdir = outputdir + "/" + name + ".csv"
report.to_csv(outputdir)
def printexcel(self, filename):
if filename:
writer = pd.ExcelWriter(filename)
#for key in self.data.keys():
# self.data[key].to_excel(writer, key)
oldworkbook = "error"
#if the file exists open it and copy each worksheet to paste it with the new ones
try:
oldworkbook = pd.ExcelFile(filename)
for sheet in oldworkbook.sheet_names:
oldworkbook.parse(sheet).to_excel(writer, sheet)
except:
print "new file"
#writing new worksheets
for key, value in self.data.iteritems():
value.to_excel(writer, key)
writer.save()
self.clear()
def clear(self):
self.data = {}