LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only

Formatted Excel Output

  • 1.  Formatted Excel Output

    Employee
    Posted 08-28-2009 21:09

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: roeperg

    A slight variation on the theme. This node checks the data type and sets the Excel cell format accordingly for bdate, bint, blong, bdouble, and boolean. It defaults to string if the data type is not one of those.
    Attachments:
    FormattedExcelOutput.brg


  • 2.  RE: Formatted Excel Output

    Employee
    Posted 10-01-2009 07:39

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Actually, the next release of our LAE, 4.1.5, will have similar functionality built right into the Excel node in core...I like the posting of ideas and nodes to the board though for sharing; great idea, please keep it up!

    Thanks
    Rich


  • 3.  RE: Formatted Excel Output

    Employee
    Posted 12-26-2011 06:15

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dvs79

    Originally posted by: rboccuzzi
    					

    Actually, the next release of our LAE, 4.1.5, will have similar functionality built right into the Excel node in core...I like the posting of ideas and nodes to the board though for sharing; great idea, please keep it up!

    Thanks
    Rich
    Hello!

    Has this functionality been realized already? How can I define a format for each output field?


  • 4.  RE: Formatted Excel Output

    Employee
    Posted 12-28-2011 08:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    It has, it is the parameter "FormatOutput" that attempts to set the data type correctly in Excel, as your code did, I believe. It doesn't have any formatting for each field, specifically. If you want that, you probably should use the BRAINscript "format" function in a filter, and then output just strings to Excel.

    Cheers
    Rich


  • 5.  RE: Formatted Excel Output

    Employee
    Posted 12-30-2011 02:43

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dvs79

    Sorry, it's just come home to me that I'd chosen the wrong thread for my question
    What I was interested is whether I can INPUT data from Excel-source, keeping right formats of the fields.
    E.g. when I import data from the field in Date-Time format, I get it as a unicode field in Excel Node and what make it worse I lose time-part. Can it be solved?


  • 6.  RE: Formatted Excel Output

    Employee
    Posted 12-30-2011 06:29

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    Regarding the prolem whereby the time information is missing, this will be resolved in the upcoming 4.5.3 release.

    For the general problem of maintaining the format within Excel, this is more complex.

    Since Excel worksheets are cell based, rather than record based, you can have a cell in one column in a worksheet that has a particular format (e.g. numeric), while the cell in the next row of the same column can have a different format (e.g. string).

    True "auto-detection" of field type would then mean that all cells need to be analyzed prior to determining what the metadata should be - basically, implying two-passes over the data in order to prevent huge amounts of memory being required. A two-pass over the data obviously would lead to the node operating much slower (probably less than half as quick as curently).

    Therefore, any form of sensible "auto-detection" of these column types would probably involve analyzing at least the first few rows, then trying to find a common base type across those rows. Then if no common base type can be found, reverting to String or Unicode type. Even still, additional node parameters would be required to tell the node how many rows (or maybe it just checks the first), and what to do in the case that it auto-detects a column as a numeric field, and then somewhere a thousand rows later, it encounters a cell in the same column with a string type.

    Probably the best way to handle this is to allow the user to specify a column type in the WorkbookSpec parameter. Although even in this case, the additional node parameters may be required to specify what the node should do in the case that the data does not match the user-specified type (Error, Ignore, Output As Null, etc).

    The latter option seems to me to be the most practical, and I will look into raising this as an enhancement request.

    Tim.


  • 7.  RE: Formatted Excel Output

    Employee
    Posted 01-03-2012 08:30

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dvs79

    Tim, thanks a lot!

    I think the last solution is the best, either. Look forward to it.


  • 8.  RE: Formatted Excel Output

    Employee
    Posted 05-29-2012 20:01

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: GreggB

    I'm putting hyperlink strings in my Excel output. The problem is that Excel treats them as strings becase they are formatted as strings. I really need to be able to tell Excel to treat them as hyperlinks. I think having full control over how the spreadsheet is formatted would make this possible.

    Looking forward to this feature.

    Gregg.


  • 9.  RE: Formatted Excel Output

    Employee
    Posted 06-06-2012 10:06

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gregroeper

    I changed my original node to be more flexible by allowing formats to be customized via a static node. This version allows me to use any valid excel format on a column basis. It also has the ability to transpose data.
    Attachments:
    formatted excel.brg


  • 10.  RE: Formatted Excel Output

    Employee
    Posted 06-17-2012 15:47

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: bsmith817

    Hi Greg,

    I opened up your latest version but it seems to be looking for the "extended.brg" library. Can you assist this newbie?

    Thanks,
    Brandon


  • 11.  RE: Formatted Excel Output

    Employee
    Posted 08-28-2012 07:54

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gregroeper

    sorry, 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


  • 12.  RE: Formatted Excel Output

    Employee
    Posted 11-26-2012 04:18

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Hi!

    I'd be very interested to try out the Formatted Excel Output project as it's a feature I would need on a daily basis. The project is, however, still asking for extended.brg library? Could anyone help?


  • 13.  RE: Formatted Excel Output

    Employee
    Posted 11-29-2012 12:27

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Aop, I can't provide you with the code above, it wasn't posted properly; the library that is missing has the actual code needed. Unfortunately, even the code posted directly above still relies on things in that missing library.

    However, I can tell you that we are coming out with a new Output Excel node in the next LAE minor release (4.6) which will allow you to use an existing spreadsheet as a template. This will give you complete control over the formatting, as we take that spreadsheet and drop the data in on top of the setup formatting. Hopefully this functionality will give you what you are looking for. The next minor release is due out soon, potentially by the end of the year or early next year.

    Cheers
    Rich


  • 14.  RE: Formatted Excel Output

    Employee
    Posted 12-03-2012 04:08

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Great to hear, I'm looking forward to the improvements in the upcoming version! So far I've had somewhat similar approach by using a VBA script to load the BRE output to a spreadsheet and matching the loaded data to formatting defined on my report template. It has worked fairly well but I have also situations where the field content varies a bit from time to time and in these cases modifying the static format template in Excel is time consuming. In these situations I'd prefer having the possibility to define field formatting based on column names like is the idea in the example provided in this thread.