Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: gregroepersorry, that was dumb of me!
Here is the raw node, you should be able to pop it into your graph directly
node:Excel_Format_Definitions
bretype:core::Static Data
editor:Label=Excel Format Definitions
editor:sortkey=4d99fd4909216c4b
output:@40fe6c55598828e5/=
prop:StaticData=<<EOX
column:string, excelformat:string
you can leave these examples in your file, they will not harm anything
A Percentage Field,0.00%
A Float,0.00
A Currency Field,"$#,##0.00_);[Red]($#,##0.00)"
A Date Field,m/d/yy
A DateTime Field,m/d/yy h:mm AM/PM
CREATION_DATE,m/d/yy
EFFDT,m/d/yy
NRPC,0.00%
INDEXED_REVENUE,"$#,##0.00_);[Red]($#,##0.00)"
EOX
editor:XY=290,230
editor:Notes=The Magic
editor:Notes=
end:Excel_Format_Definitions
node:Formatted_Excel
bretype:extended::ExcelOutput
editor:Label=Formatted Excel
editor:sortkey=4d99f53c4df15b9c_2
input:4d99fb8f476550af/Formats=
input:4d99fb8e3267530c/Data=
prop:Filename Includes Datestamp=false
prop:Python2Implementation=<<EOX
import braininfo
from xlwt import *
from types import IntType, LongType, FloatType
import datetime
import time
def setup(brainNodeControlObj, BrainNodeClass):
class BrainNode(BrainNodeClass):
def initialize(self):
self.fileName = self.properties.getFilename('ls.brain.node.ExcelOu tput.File')
if "{{^Filename Includes Datestamp^}}" == "true":
self.DStamp = True
else:
self.DStamp = False
if "{{^Set Column Widths^}}" == "true":
self.SetWidths = True
else:
self.SetWidths = False
if "{{^Transpose^}}" == "true":
self.Transpose = True
self.SetWidths = False # if we are transposing setting widths is not allowed
else:
self.Transpose = False
self.headerBold = self.properties.getBool('ls.brain.node.ExcelOutput .HeaderBold', True)
self.rowThreshold = self.properties.getInt('ls.brain.node.ExcelOutput. RowThreshold', -1)
font = Font()
fontBold = Font()
fontBold.bold = True
fontStyle = XFStyle()
fontStyle.font = font
fontStyleBold = XFStyle()
fontStyleBold.font = fontBold
fontStyleDate = XFStyle()
fontStyleDate.num_format_str = '_(MM/DD/YYYY_) '
self.fontStyle = fontStyle
self.fontStyleBold = fontStyleBold
self.fontStyleDate = fontStyleDate
self.ExcelFormats={}
super(BrainNode, self).initialize()
def finalize(self, val):
super(BrainNode, self).finalize(val)
def pump(self, quant):
while quant.permitsRunning(self):
w = Workbook()
i=0
for input in self.inputs:
if 0 == i:
rec = input.read()
r = 1
while rec is not None:
self.ExcelFormats[rec[0].upper()] = rec[1]
rec = input.read()
else:
ws = w.add_sheet(input.name)
md = input.metadata
widthList = []
outStyles = []
for dis in md:
if dis[0].upper() in self.ExcelFormats:
outStyles.append(easyxf(num_format_str=self.ExcelF ormats[dis[0].upper()]))
else:
outStyles.append(easyxf(""))
h = 0
fontStyle = self.fontStyle
fontStyleDate = self.fontStyleDate
if self.headerBold:
fontStyle = self.fontStyleBold
while h < len(md):
if self.Transpose:
ws.write(h,0,md[h][0], fontStyle)
else:
ws.write(0,h,md[h][0], fontStyle)
if self.SetWidths:
widthList.append(len(str(md[h]))*1.2)
h += 1
rec = input.read()
cellfont = Font()
cellStyle = XFStyle()
fontStyle.font = cellfont
r = 1
while rec is not None and r < self.rowThreshold and self.rowThreshold > 0:
c = 0
while c < len(rec):
if rec[c] is not None:
if self.Transpose:
ws.write(c,r,rec[c], outStyles[c])
else:
ws.write(r,c,rec[c], outStyles[c])
if self.SetWidths:
if "bdouble" == md[c][1] or "blong" == md[c][1] or "bint" == md[c][1] or "bdate" == md[c][1]:
strlen=10
else: # guess it's a string
strlen = len(rec[c])
if widthList[c] < strlen:
widthList[c] = strlen
c += 1
r += 1
rec = input.read()
if self.SetWidths:
for thisColumn in range(len(widthList)):
ws.col(thisColumn).width = widthList[thisColumn]*200
i += 1
localtime = time.localtime(time.time())
dstring = "%04d-%02d-%02d" %(localtime[0],localtime[1],localtime[2])
if self.DStamp:
w.save(self.fileName % dstring)
else:
w.save(self.fileName)
return False
return True
return BrainNode
EOX
prop:Set Column Widths=true
prop:Transpose=false
editor:XY=390,230
editor:Doc=Outputs data to an Excel workbook. Workbook contains one sheet per input data set
editor:Doc=Formats can be any valid Excel number/date format
editor:Doc=Set Column Widths is ignored when Transpose is set to True
editor:Doc=NOTE!!! You cannot transpose if output is more than 256 lines!
editor:propdef=Filename Includes Datestamp|boolean|1||None
editor:propdef=Transpose|boolean|1||None
editor:propdef=Set Column Widths|boolean|1||None
end:Formatted_Excel