Friday, April 19, 2019

Diving into Python: printing to console

I just started diving into Python.  Having enjoyed the ease of ColdFusion for so long, working with Python is like trying to resist a gag reflex.  Mostly diving into it because of the popularity of the language.  As usual, you start with the "Hello World" and work up from there learning the nuances.  somethings just don't make a whole lot of sense on why a language designer would do something so differently..

Take the print() statement for example.   to design the print statement to always perform line feed without thinking design wise, that you might want to combine multiple elements on the same line.  Having a "," at the end to do so seems awkward.   specially at a 2.x stage.  3.x is an improvement, but still "meh"

The below bit shows how you would do it depending on which version.

this would produce "hello hello hello hello hello" (with the appropriate line comments removed/added  for the version of Python you are using

for _ in range(5):
    #below is 2.x
    #below is 3.x
    #print("hello", end =" ")

 Moving to 3.x, backward compatibility was not maintained  so you have to refactor your code.  Admittedly I'm new to Python, and haven't looked at earlier 3.x releases, so this backward compatibility statement might be a bit skewed.  This very first bit of an example of the differences of a 2.x vs 3.x version would send shivers down my spine on any thought of moving an existing code base to a new version.

Friday, April 5, 2019

How to Make an Ugly Excel Document: Otherwise known as Unit Testing POIUtility 4.0 (Apache POI 4.0.1) compatible

I've been working on a revamp of Ben Nadel's excellent but aging POIUtility for the generation of Excel files.   I've been needing XLSX support so I updated the code to use Apache POI 4.0.1 and embedded Mark Mandel's JavaLoader and the needed packages for it to work standalone without java lib dependencies on the server.

Here's a summary of what I've done so far;
  • Uses Apache POI 4.0.1 with JavaLoader
  • Supports creation of both XLS and XLSX
  • RowSpan support.  Either by itself or with colSpan to create a range (see ugly image below)
  • poi:row update attribute when working with existing templates.
  • refactored the CSSRule.cfc  into cfscript, 
TODO: Work on updating the POIUtility.cfc now that the groundwork is complete.

I did yank the coldfusion_mx_7 folder, figured it's about time for people to move ahead on that one.

Tested on CommandBox with ColdFusion 2018

Go to my repo or the code

Side by side results of XLS and XLST Generation
Color, fill pattern, and region test.  (note text colors are just random selection )