Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cfsimplicity committed Jun 22, 2024
2 parents 826cf89 + 9653c63 commit bf8f54d
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 40 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@ on:
[ workflow_dispatch, workflow_call ]

jobs:
testbox:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
cfengine: [ "lucee@5", "adobe@2018", "adobe@2021", "adobe@2023" ]
container:
image: foundeo/cfml-ci-tools:latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Install the ortus security key
run: curl -fsSl https://downloads.ortussolutions.com/debs/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/ortussolutions.gpg > /dev/null

- name: Add the commandbox source
run: echo "deb [signed-by=/usr/share/keyrings/ortussolutions.gpg] https://downloads.ortussolutions.com/debs/noarch /" | sudo tee /etc/apt/sources.list.d/commandbox.list

- name: Update apt and install commandbox
run: sudo apt-get update && sudo apt-get install apt-transport-https commandbox

- name: Install dependencies
run: box install

- name: Start a server
run: box server start cfengine=${{ matrix.cfengine }} port=8080

- name: Install ACF packages
if: ${{ matrix.cfengine == 'adobe@2021' || matrix.cfengine == 'adobe@2023' }}
run: box run-script cfpmInstall

- name: Run TestBox Tests
run: box testbox run "http://localhost:8080/test/index.cfm"
run: box testbox run runner="http://localhost:8080/test/index.cfm"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 4.1.0 - 22 June 2024

- Enhancements
- \#369 Add moveSheet()
- \#370 Add sheet position to sheetInfo() properties

- Maintenance
-\#371 Upgrade excel-streaming-reader to 4.3.1

## 4.0.0 - 6 March 2024

- Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component{
this.author = "Julian Halliwell";
this.webURL = "https://github.com/cfsimplicity/spreadsheet-cfml";
this.description = "CFML Spreadsheet Library";
this.version = "4.0.0";
this.version = "4.1.0";
this.autoMapModels = false;

function configure(){
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ You may wish to place the spreadsheet library files in a central location with a
* [isRowHidden](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/isRowHidden)
* [isStreamingXmlFormat](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/isStreamingXmlFormat)
* [isXmlFormat](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/isXmlFormat)
* [moveSheet](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/moveSheet)
* [newStreamingXlsx](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/newStreamingXlsx)
* [newXls](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/newXls)
* [newXlsx](https://github.com/cfsimplicity/spreadsheet-cfml/wiki/newXlsx)
Expand Down
38 changes: 26 additions & 12 deletions Spreadsheet.cfc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
component accessors="true"{

//"static"
property name="version" default="4.0.0" setter="false";
property name="osgiLibBundleVersion" default="5.2.5.1" setter="false"; //first 3 octets = POI version; increment 4th with other jar updates
property name="version" default="4.1.0" setter="false";
property name="osgiLibBundleVersion" default="5.2.5.3" setter="false"; //first 3 octets = POI version; increment 4th with other jar updates
property name="osgiLibBundleSymbolicName" default="spreadsheet-cfml" setter="false";
property name="exceptionType" default="cfsimplicity.spreadsheet" setter="false";
//configurable
Expand Down Expand Up @@ -800,7 +800,10 @@ component accessors="true"{
}

public string function getCellAddress( required workbook, required numeric row, required numeric column ){
return getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column ).getAddress().formatAsString();
var cell = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column );
if( IsNull( cell ) )
getExceptionHelper().throwInvalidCellException( arguments.row, arguments.column );
return cell.getAddress().formatAsString();
}

public any function getCellComment( required workbook, numeric row, numeric column ){
Expand All @@ -812,6 +815,8 @@ component accessors="true"{
if( !arguments.KeyExists( "row" ) )
return getCellComments( arguments.workbook );// row and column weren't provided so return all the comments as an array of structs
var cell = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column );
if( IsNull( cell ) )
getExceptionHelper().throwInvalidCellException( arguments.row, arguments.column );
var commentObject = cell.getCellComment();
if( IsNull( commentObject ) )
return {};
Expand Down Expand Up @@ -840,9 +845,10 @@ component accessors="true"{
}

public struct function getCellFormat( required workbook, required numeric row, required numeric column ){
if( !getCellHelper().cellExists( arguments.workbook, arguments.row, arguments.column ) )
Throw( type=this.getExceptionType() & ".invalidCell", message="Invalid cell", detail="There doesn't appear to be a cell at row #row#, column #column#" );
var cellStyle = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column ).getCellStyle();
var cell = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column );
if( IsNull( cell ) )
getExceptionHelper().throwInvalidCellException( arguments.row, arguments.column );
var cellStyle = cell.getCellStyle();
var cellFont = arguments.workbook.getFontAt( cellStyle.getFontIndexAsInt() );
var rgb = getColorHelper().getRGBFromCellFont( arguments.workbook, cellFont );
return {
Expand Down Expand Up @@ -876,9 +882,9 @@ component accessors="true"{
public any function getCellFormula( required workbook, numeric row, numeric column ){
if( !arguments.KeyExists( "row" ) || !arguments.KeyExists( "column" ) )
return getSheetHelper().getAllSheetFormulas( arguments.workbook );
if( !getCellHelper().cellExists( arguments.workbook, arguments.row, arguments.column ) )
return "";
var cell = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column );
if( IsNull( cell ) )
return "";
if( getCellHelper().cellIsOfType( cell, "FORMULA" ) )
return cell.getCellFormula();
return "";
Expand All @@ -890,16 +896,16 @@ component accessors="true"{
}

public string function getCellType( required workbook, required numeric row, required numeric column ){
if( !getCellHelper().cellExists( arguments.workbook, arguments.row, arguments.column ) )
return "";
var cell = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column );
if( IsNull( cell ) )
return "";
return cell.getCellType().toString();
}

public any function getCellValue( required workbook, required numeric row, required numeric column, boolean returnVisibleValue=true ){
if( !getCellHelper().cellExists( arguments.workbook, arguments.row, arguments.column ) )
return "";
var cell = getCellHelper().getCellAt( arguments.workbook, arguments.row, arguments.column );
if( IsNull( cell ) )
return "";
if( arguments.returnVisibleValue && !getCellHelper().cellIsOfType( cell, "FORMULA" ) )
return getCellHelper().getFormattedCellValue( cell );
return getCellHelper().getCellValueAsType( arguments.workbook, cell );
Expand Down Expand Up @@ -1060,6 +1066,14 @@ component accessors="true"{
return this;
}

public Spreadsheet function moveSheet( required workbook, required string sheetName, required numeric newPosition ){
getSheetHelper()
.validateSheetExistsWithName( arguments.workbook, arguments.sheetName )
.validateSheetNumber( arguments.workbook, arguments.newPosition )
.moveSheet( arguments.workbook, arguments.sheetName, arguments.newPosition-1 );
return this;
}

public any function new(
string sheetName="Sheet1"
,boolean xmlFormat=( getDefaultWorkbookFormat() == "xml" )
Expand Down
10 changes: 5 additions & 5 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "Spreadsheet CFML",
"slug" : "spreadsheet-cfml",
"version" : "4.0.0",
"version" : "4.1.0",
"shortDescription" : "CFML spreadsheet library",
"author" : "Julian Halliwell",
"location" : "forgeboxStorage",
Expand All @@ -24,11 +24,11 @@
"devDependencies" : {
"testbox" : ">=5.0.0"
},
"installPaths":{
"testbox":"test/testbox/"
},
"type" : "modules",
"keywords" : [ "cfspreadsheet", "coldfusion", "lucee", "module", "spreadsheet", "csv" ],
"private" : "false",
"ignore" : [ ".github", "build", "src", "test", ".gitattributes", "CHANGELOG.md", "README.md" ]
"ignore" : [ ".github", "build", "src", "test", ".gitattributes", "CHANGELOG.md", "README.md" ],
"scripts":{
"cfpmInstall": "cfpm install image"
}
}
6 changes: 3 additions & 3 deletions build/lib-osgi.mf
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spreadsheet CFML
Bundle-SymbolicName: spreadsheet-cfml
Bundle-Version: 5.2.5.1
Bundle-Version: 5.2.5.3
Bundle-ClassPath: commons-codec-1.16.0.jar,
commons-collections4-4.4.jar,
commons-compress-1.25.0.jar,
commons-csv-1.10.0.jar,
commons-io-2.15.0.jar,
commons-math3-3.6.1.jar,
excel-streaming-reader-4.2.1.jar,
excel-streaming-reader-4.3.1.jar,
log4j-api-2.22.0.jar,
poi-5.2.5.jar,
poi-ooxml-5.2.5.jar,
poi-ooxml-full-5.2.5.jar,
slf4j-api-2.0.9.jar,
slf4j-api-2.0.13.jar,
SparseBitSet-1.3.jar,
spreadsheet-cfml.jar,
xmlbeans-5.2.0.jar
14 changes: 7 additions & 7 deletions helpers/cell.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ component extends="base"{
return variables.cellUtil;
}

boolean function cellExists( required workbook, required numeric rowNumber, required numeric columnNumber ){
var checkRow = getRowHelper().getRowFromActiveSheet( arguments.workbook, arguments.rowNumber );
var columnIndex = ( arguments.columnNumber -1 );
return !IsNull( checkRow ) && !IsNull( checkRow.getCell( JavaCast( "int", columnIndex ) ) );
any function getReferenceObject( required cell ){
return library().createJavaObject( "org.apache.poi.ss.util.CellReference" ).init( arguments.cell );
}

any function getReferenceObjectByAddressString( required string address ){
return library().createJavaObject( "org.apache.poi.ss.util.CellReference" ).init( arguments.address );
}

boolean function cellIsOfType( required cell, required string type ){
Expand All @@ -30,10 +32,8 @@ component extends="base"{
}

any function getCellAt( required workbook, required numeric rowNumber, required numeric columnNumber ){
if( !cellExists( argumentCollection=arguments ) )
Throw( type=library().getExceptionType() & ".invalidCell", message="Invalid cell", detail="The requested cell [#arguments.rowNumber#,#arguments.columnNumber#] does not exist in the active sheet" );
var columnIndex = ( arguments.columnNumber -1 );
return getRowHelper().getRowFromActiveSheet( arguments.workbook, arguments.rowNumber ).getCell( JavaCast( "int", columnIndex ) );
return getRowHelper().getRowFromActiveSheet( arguments.workbook, arguments.rowNumber )?.getCell( JavaCast( "int", columnIndex ) );
}

any function getCellFormulaValue( required workbook, required cell, boolean forceEvaluation=false ){
Expand Down
4 changes: 3 additions & 1 deletion helpers/exception.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ component extends="base"{
Throw( type=library().getExceptionType() & ".parallelOptionNotSupported", message="Parallel threads option not supported", detail="Your ColdFusion engine does not support parallel processing of loops via threads" );
}


void function throwInvalidCellException( required numeric rowNumber, required numeric columnNumber ){
Throw( type=library().getExceptionType() & ".invalidCell", message="Invalid cell", detail="The requested cell [#arguments.rowNumber#,#arguments.columnNumber#] does not exist in the active sheet" );
}

}
1 change: 1 addition & 0 deletions helpers/sheet.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ component extends="base"{
,name: sheet.getSheetName()
,numberOfDataValidations: sheet.getDataValidations().Len()
,numberOfMergedRegions: sheet.getNumMergedRegions()
,position: getSheetIndexFromName( arguments.workbook, sheet.getSheetName() )+1
,printsFitToPage: sheet.getFitToPage()
,printsGridlines: sheet.isPrintGridlines()
,printsHorizontallyCentered: sheet.getHorizontallyCenter()
Expand Down
5 changes: 1 addition & 4 deletions helpers/streamingReader.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ component extends="base"{
arguments.sheetToQueryArgs.workbook = getBuilder( arguments.builderOptions ).open( file );
return getSheetHelper().sheetToQuery( argumentCollection=arguments.sheetToQueryArgs );
}
catch( org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException exception ){
getExceptionHelper().throwInvalidFileForReadLargeFileException();
}
catch( org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException exception ){
catch( com.github.pjfanning.xlsx.exceptions.ReadException exception ){
getExceptionHelper().throwInvalidFileForReadLargeFileException();
}
finally{
Expand Down
Binary file modified lib-osgi.jar
Binary file not shown.
Binary file removed lib/excel-streaming-reader-4.2.1.jar
Binary file not shown.
Binary file added lib/excel-streaming-reader-4.3.1.jar
Binary file not shown.
Binary file added lib/slf4j-api-2.0.13.jar
Binary file not shown.
Binary file removed lib/slf4j-api-2.0.9.jar
Binary file not shown.
Binary file modified lib/spreadsheet-cfml.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion objects/ConditionalFormatting.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ component{
var evaluator = variables.library.createJavaObject( "org.apache.poi.ss.formula.ConditionalFormattingEvaluator" ).init( variables.workbook, provider );
evaluator.clearAllCachedValues();
var cellReferenceWithSheetName = addSheetNameToCellReference( arguments.cellReference );
var cellReferenceObject = variables.library.createJavaObject( "org.apache.poi.ss.util.CellReference" ).init( cellReferenceWithSheetName );
var cellReferenceObject = variables.library.getCellHelper().getReferenceObjectByAddressString( cellReferenceWithSheetName );
return evaluator.getConditionalFormattingForCell( cellReferenceObject );
}

Expand Down
6 changes: 6 additions & 0 deletions objects/SpreadsheetChainable.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ component{
return this;
}

public SpreadsheetChainable function moveSheet( required string sheetName, required numeric newPosition ){
addWorkbookArgument( arguments );
variables.library.moveSheet( argumentCollection=arguments );
return this;
}

public any function read(
required string src
,string format
Expand Down
2 changes: 2 additions & 0 deletions objects/WriteCsv.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ component extends="BaseCsv" accessors="true"{
}

public WriteCsv function toFile( required string path ){
if( arguments.path.Left( 4 ) == "ram:" )
Throw( type=variables.library.getExceptionType() & ".vfsNotSupported", message="Invalid file path", detail="Virtual File System (RAM) paths are not supported for writing to CSV. Try just returning the CSV string and then using FileWrite() to write to the VFS path" );
variables.filepath = arguments.path;
return this;
}
Expand Down
49 changes: 49 additions & 0 deletions test/specs/moveSheet.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<cfscript>
describe( "moveSheet", function(){
beforeEach( function(){
variables.workbooks = [ s.newXls(), s.newXlsx() ];
});
it( "Moves the named sheet to the specified position", function(){
workbooks.Each( function( wb ){
s.createSheet( wb, "sheet2" );
s.setActiveSheet( wb, "sheet2" );
expect( s.sheetInfo( wb ).position ).toBe( 2 );
s.moveSheet( wb, "sheet2", 1 );
expect( s.sheetInfo( wb ).position ).toBe( 1 );
});
});
it( "Is chainable", function(){
workbooks.Each( function( wb ){
s.newChainable( wb )
.createSheet("sheet2" )
.setActiveSheet( "sheet2" )
.moveSheet( "sheet2", 1 );
expect( s.sheetInfo( wb ).position ).toBe( 1 );
});
});
describe( "moveSheet throws an exception if", function(){
it( "the sheet name doesn't exist", function(){
workbooks.Each( function( wb ){
expect( function(){
s.moveSheet( wb, "test", 1 );
}).toThrow( type="cfsimplicity.spreadsheet.invalidSheetName" );
});
});
it( "the new position is invalid", function(){
workbooks.Each( function( wb ){
expect( function(){
s.moveSheet( wb, "sheet1", 10 );
}).toThrow( type="cfsimplicity.spreadsheet.invalidSheetNumber" );
});
});
});
});
</cfscript>
3 changes: 3 additions & 0 deletions test/specs/sheetInfo.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe( "sheetInfo", function(){
,name: "Sheet1"
,numberOfDataValidations: 0
,numberOfMergedRegions: 0
,position: 1
,printsFitToPage: ( type == "xls" )//xlsx=false xls=true
,printsGridlines: false
,printsHorizontallyCentered: false
Expand All @@ -31,6 +32,8 @@ describe( "sheetInfo", function(){
var actual = chainable.sheetInfo();
expect( actual ).toBe( defaults );
var sheet = s.getSheetHelper().getActiveSheet( wb );
// position
expect( chainable.sheetInfo().position ).toBe( 1 );
// displaysAutomaticPageBreaks
sheet.setAutoBreaks( JavaCast( "boolean", true ) );
expect( chainable.sheetInfo().displaysAutomaticPageBreaks ).toBeTrue();
Expand Down
8 changes: 8 additions & 0 deletions test/specs/writeCsv.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ describe( "writeCsv", function(){
}
);
it( "the file path specified is VFS", function(){
expect( function(){
var data = [ [ "a", "b" ], [ "c", "d" ] ];
var path = "ram://temp.csv";
s.writeCsv().fromData( data ).toFile( path ).execute();
}).toThrow( type="cfsimplicity.spreadsheet.vfsNotSupported" );
});
});
});
Expand Down
Loading

0 comments on commit bf8f54d

Please sign in to comment.