Standalone library for creating and working with spreadsheets in Lucee (formerly Railo)
Julian Halliwell
Julian Halliwell Version 1.7.3
Latest commit 94e2709 Nov 7, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
javaLoader Update JavaLoader to 1.2 Mar 24, 2017
lib Upgrade to POI 3.17 Fixes #134 Sep 28, 2017
test Fix failing setCellValue test on ACF2016+ Nov 6, 2018
CHANGELOG.md Version 1.7.3 Nov 7, 2018
LICENSE Bump copyright year. Jan 15, 2017
ModuleConfig.cfc Version 1.7.3 Nov 7, 2018
README.md Bump copyright year May 13, 2018
Spreadsheet.cfc Version 1.7.3 Nov 7, 2018
box.json Version 1.7.3 Nov 7, 2018
decryption.cfc Minor formatting tweaks. Mar 9, 2017
encryption.cfc Minor formatting tweaks. Mar 9, 2017

README.md

Spreadsheet library for Lucee

Originally adapted from the https://github.com/teamcfadvance/cfspreadsheet-railo extension, this is a standalone library for reading, creating and formatting spreadsheets in Lucee Server which does not require installation as an extension.

Rationale

Unlike Adobe ColdFusion, Lucee doesn't support spreadsheet functionality out of the box. Extensions exist for both Lucee 4.5 and Lucee 5, but I decided to create a standalone library which doesn't depend on customisation of the engine.

Library vs Extension

Benefits

  • No installation required, either at the server or individual web context level.
  • read() method offers all the features of the <cfspreadsheet action="read"> tag in script in addition to the basic options of SpreadsheetRead().
  • Offers a number of additional functions and options (see below)
  • Fixes various outstanding bugs/omissions.
  • No dependency on Lucee within the included jar files.
  • Invoking the library doesn't create a workbook instance (a.k.a. Spreadsheet Object), meaning:
    • a blank workbook isn't created unnecessarily when reading an existing spreadsheet
    • the library can be stored as a singleton in application scope
  • Written entirely in CFML script.

Downsides

  • Existing code needs adapting to invoke the library. Existing CFML spreadsheet functions and the <cfspreadsheet> tag won't work with it.

Usage

Note that this is not a Lucee extension, so does not need to be installed. To use it, simply copy the files/folders to a location where Spreadsheet.cfc can be called by your application code.

The following example assumes the file containing the script is in the same directory as the folder containing the spreadsheet library files, i.e.:

  • root/
    • spreadsheetLibrary/
      • Spreadsheet.cfc
      • etc.
    • script.cfm
<cfscript>
spreadsheet = New spreadsheetLibrary.Spreadsheet();
data = QueryNew( "First,Last", "VarChar, VarChar", [ [ "Susi", "Sorglos" ], [ "Frumpo", "McNugget" ] ] );
workbook = spreadsheet.new();
spreadsheet.addRows( workbook, data );
</cfscript>

You will probably want to place the spreadsheet library files in a central location with an application mapping, and instantiate the component using its dot path (e.g. New myLibrary.spreadsheet.Spreadsheet();).

How to create mappings (StackOverflow).

Full function reference

Supported ColdFusion functions

Extra functions not available in ColdFusion

Additional Convenience methods

Enhanced Read() method

In Adobe ColdFusion, the SpreadsheetRead() script function is limited to just returning a spreadsheet object, whereas the <cfspreadsheet action="read"> tag has a range of options for reading and returning data from a spreadsheet file.

The read() method in this library allows you to read a spreadsheet file into a query and return that instead of a spreadsheet object. It includes all of the options available in <cfspreadsheet action="read">.

<cfscript>
myQuery = spreadsheet.read( src=mypath, format="query" );
</cfscript>

The read() method also features the following additional options not available in ColdFusion or the Spreadsheet Extension:

  • fillMergedCellsWithVisibleValue
  • includeHiddenColumns
  • includeRichTextFormatting
  • password to open encrypted XML (only) spreadsheets

Full documentation of read()

Date formats

The following international date masks are used by default to read and write cell values formatted as dates:

  • DATE = yyyy-mm-dd
  • DATETIME = yyyy-mm-dd HH:nn:ss
  • TIME = hh:mm:ss
  • TIMESTAMP = yyyy-mm-dd hh:mm:ss

Each of these can be overridden by passing in a struct including the value(s) to be overridden when instantiating the Spreadsheet component. For example:

<cfscript>
spreadsheet = New spreadsheetLibrary.spreadsheet( dateFormats={ DATE: "mm/dd/yyyy" } );
</cfscript>

Adobe ColdFusion

Although primarily intended for Lucee, the library can be run under ColdFusion 11 or higher. This may be useful where you want to your codebase to be cross-compatible between the two engines.

Please note though that reading or writing password-protected files only works with Lucee.

JavaLoader

If you are using Lucee 4.5 or Adobe ColdFusion, Mark Mandel's JavaLoader is required and the bundled version will be used by default.

JavaLoader is not required if using Lucee 5 or later.

For more details and options see: Loading the POI java libraries

CommandBox Installation

You can also download this library through CommandBox.

box install cfsimplicity/lucee-spreadsheet

It will download the files into a modules directory and can be used just the same as downloading the files manually.

If using ColdBox you can use either of the WireBox bindings like so:

spreadsheet = wirebox.getInstance("Spreadsheet@lucee-spreadsheet");
spreadsheet = wirebox.getInstance("LuceeSpreadsheet");

Test Suite

The automated tests require TestBox 2.1 or later. You will need to create an application mapping for /testbox

Credits

The code was originally adapted from the work of TeamCfAdvance. Ben Nadel's POI Utility was also used as a basis for parts of the read functionality.

JavaLoader is by Mark Mandel.

Legal

The MIT License (MIT)

Copyright (c) 2015-18 Julian Halliwell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.