-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
2,948 additions
and
2,694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
component accessors="true"{ | ||
|
||
property name="filepath"; | ||
property name="firstRowIsHeader" type="boolean" default="false"; | ||
property name="numberOfRowsToSkip" default=0; | ||
property name="rowProcessor"; | ||
property name="sheetName"; | ||
property name="sheetNumber" default=1; | ||
property name="streamingOptions"; | ||
property name="useVisibleValues" type="boolean" default="false"; | ||
/* Internal */ | ||
property name="library" setter="false"; | ||
|
||
public ProcessLargeFile function init( required spreadsheetLibrary, required string filepath ){ | ||
variables.library = arguments.spreadsheetLibrary; | ||
variables.library.getFileHelper().throwErrorIFfileNotExists( arguments.filepath ); | ||
variables.filepath = arguments.filepath; | ||
variables.streamingOptions = {}; | ||
return this; | ||
} | ||
|
||
/* Public builder API */ | ||
|
||
public ProcessLargeFile function withFirstRowIsHeader( boolean state=true ){ | ||
variables.firstRowIsHeader = arguments.state; | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withRowProcessor( required function rowProcessor ){ | ||
variables.rowProcessor = arguments.rowProcessor; | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withPassword( required string password ){ | ||
variables.streamingOptions.password = arguments.password; | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withSheetName( required string sheetName ){ | ||
variables.sheetName = arguments.sheetName; | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withSheetNumber( required numeric sheetNumber ){ | ||
variables.sheetNumber = arguments.sheetNumber; | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withSkipFirstRows( required numeric numberOfRowsToSkip ){ | ||
if( !IsValid( "integer", arguments.numberOfRowsToSkip ) || ( arguments.numberOfRowsToSkip < 0 ) ) | ||
Throw( type=variables.library.getExceptionType() & ".invalidArgument", message="Invalid argument to method withSkipFirstRows()", detail="'#arguments.numberOfRowsToSkip#' is not a valid argument to withSkipFirstRows(). Please specify zero or a positive integer" ); | ||
variables.numberOfRowsToSkip = arguments.numberOfRowsToSkip; | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withStreamingOptions( required struct options ){ | ||
if( arguments.options.KeyExists( "bufferSize" ) ) | ||
variables.streamingOptions.bufferSize = Val( arguments.options.bufferSize ); | ||
if( arguments.options.KeyExists( "rowCacheSize" ) ) | ||
variables.streamingOptions.rowCacheSize = Val( arguments.options.rowCacheSize ); | ||
return this; | ||
} | ||
|
||
public ProcessLargeFile function withUseVisibleValues( boolean state=true ){ | ||
variables.useVisibleValues = arguments.state; | ||
return this; | ||
} | ||
|
||
// final execution | ||
public ProcessLargeFile function execute(){ | ||
lock name="#getFilepath()#" timeout=5 { | ||
try{ | ||
var file = CreateObject( "java", "java.io.FileInputStream" ).init( getFilepath() ); | ||
var workbook = getLibrary().getStreamingReaderHelper().getBuilder( getStreamingOptions() ).open( file ); | ||
var rowIterator = getSheetToProcess( workbook ).rowIterator(); | ||
var currentRecordNumber = 0; | ||
var headerRowSkipped = false; | ||
var skippedRecords = 0; | ||
var rowProcessor = getRowProcessor() | ||
var rowDataArgs = { | ||
workbook: workbook | ||
}; | ||
if( getUseVisibleValues() ) | ||
rowDataArgs.returnVisibleValues = true; | ||
while( rowIterator.hasNext() ){ | ||
rowDataArgs.row = rowIterator.next(); | ||
if( skipThisRecord( skippedRecords ) ){ | ||
skippedRecords++; | ||
continue; | ||
} | ||
if( getFirstRowIsHeader() && !headerRowSkipped ){ | ||
headerRowSkipped = true; | ||
continue; | ||
} | ||
var data = getLibrary().getRowHelper().getRowData( argumentCollection=rowDataArgs ); | ||
if( !IsNull( rowProcessor ) ) | ||
rowProcessor( data, ++currentRecordNumber ); | ||
} | ||
} | ||
catch( any exception ){ | ||
getLibrary().getExceptionHelper().throwExceptionIfFileIsInvalidForStreamingReader( exception ); | ||
rethrow; | ||
} | ||
finally{ | ||
getLibrary().getFileHelper().closeLocalFileOrStream( local, "file" ); | ||
getLibrary().getFileHelper().closeLocalFileOrStream( local, "workbook" ); | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
/* Private */ | ||
private any function getSheetToProcess( required workbook ){ | ||
if( !IsNull( getSheetName() ) ) | ||
return getLibrary().getSheetHelper().getSheetByName( arguments.workbook, getSheetName() ); | ||
return getLibrary().getSheetHelper().getSheetByNumber( arguments.workbook, getSheetNumber() ); | ||
} | ||
|
||
private boolean function skipThisRecord( required numeric skippedRecords ){ | ||
return variables.numberOfRowsToSkip && ( arguments.skippedRecords < variables.numberOfRowsToSkip ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
<cfscript> | ||
describe( "addAutoFilter", function(){ | ||
describe( "addAutoFilter", ()=>{ | ||
beforeEach( function(){ | ||
beforeEach( ()=>{ | ||
var data = QueryNew( "Header1,Header2", "VarChar,VarChar", [ [ "a", "b" ], [ "c", "d" ] ] ); | ||
var xls = s.workbookFromQuery( data ); | ||
var xlsx = s.workbookFromQuery( data=data, xmlformat=true ); | ||
variables.workbooks = [ xls, xlsx ]; | ||
}); | ||
}) | ||
it( "Doesn't error when passing valid arguments", function() { | ||
workbooks.Each( function( wb ){ | ||
it( "Doesn't error when passing valid arguments", ()=>{ | ||
workbooks.Each( ( wb )=>{ | ||
s.addAutoFilter( wb, "A1:B1" ) | ||
.addAutoFilter( wb )// default to all cols in first row if no row range passed | ||
.addAutoFilter( workbook=wb, row=2 );// allow row to be specified instead of range | ||
}); | ||
}); | ||
}) | ||
}) | ||
it( "Doesn't error when passing valid arguments with extra trailing/leading space", function() { | ||
workbooks.Each( function( wb ){ | ||
it( "Doesn't error when passing valid arguments with extra trailing/leading space", ()=>{ | ||
workbooks.Each( ( wb )=>{ | ||
s.addAutoFilter( wb, " A1:B1 " ); | ||
}); | ||
}); | ||
}) | ||
}) | ||
it( "Is chainable", function() { | ||
it( "Is chainable", ()=>{ | ||
workbooks.Each( function( wb ){ | ||
s.newChainable( wb ).addAutoFilter( " A1:B1 " ); | ||
}); | ||
}); | ||
}) | ||
}) | ||
}); | ||
}) | ||
</cfscript> |
Oops, something went wrong.