simply test file

This commit is contained in:
Bill Rawlinson 2015-12-18 14:27:46 -05:00
parent 55f845df5f
commit c24b4b5cbc
2 changed files with 10 additions and 154 deletions

View File

@ -1,96 +1,8 @@
<cfcomponent
hint="extend this class with a class that implements the interface IImporter"
output="no">
<cfcomponent output="no">
<cffunction name="init" output="false" returntype="any">
<cfscript>
variables.instance = structNew();
return this;
</cfscript>
</cffunction>
<cffunction
access="private"
name="readExcelFile"
output="false"
returntype="any">
<cfargument
hint="Full path to the spreadsheet being read"
name="filepath"
required="true"
type="string"/>
<cfargument
default="1"
hint="number, 1-based, of the sheet in the workbook to read"
name="sheetNumber"
type="numeric"/>
<cfargument
default="1"
hint="if no content is found in a row by the time this column is reached then that row will be ignored"
name="ignoreColumnPoint"
type="numeric"/>
<cfargument
default=""
hint="either a numeric index of the row OR a comma separated list of headers"
name="headerRow"
type="string"/>
<cfargument
default="0"
hint="provide this if the actual data starts on a wierd row relative to the header info"
name="dataStartRow"
type="numeric"/>
<cfset var local=structNew()/>
<!--- We are decrementing by 1 so users can continue to pass the literal number they see in the Excel spreadsheet and not worry about the zero-based stuff --->
<cfif Arguments.dataStartRow GT 0>
<cfset Arguments.dataStartRow=Arguments.dataStartRow - 1>
</cfif>
<cfset local.headerRowIndex=0/>
<cfset local.headers=""/>
<cfif IsNumeric(arguments.headerRow)>
<cfset local.headerRowIndex=arguments.headerRow/>
<cfelse>
<cfset local.headers=arguments.headerRow/>
</cfif>
<cfscript>
initFormattingRules();
local.reader = createObject("component", "foo.com.ExcelReader").init(arguments.filepath, arguments.sheetNumber);
local.data = local
.reader
.read(arguments.ignoreColumnPoint, arguments.dataStartRow);
local.data = local
.reader
.fixDateAndNumericColumns(local.data, variables.instance.dateColumns, variables.instance.numberColumns);
return local.data;
</cfscript>
</cffunction>
<cffunction
hint="left pads any string with the character provided until the string is the correct length"
name="pad"
output="false"
returntype="string">
<cfargument name="inString" required="true" type="string"/>
<cfargument name="padChar" required="true" type="string"/>
<cfargument name="maxLen" required="true" type="numeric"/>
<cfset var mult=arguments.maxLen - len(arguments.inString)/>
<cfset var i=0/>
<cfloop from="1" index="i" to="#mult#"><cfset arguments.instring=arguments.padChar & arguments.instring/></cfloop>
<cfreturn arguments.inString/>
</cffunction>
<cffunction access="private" name="getDSN" output="false" returntype="string">
<cfreturn variables.instance.dsn/>
</cffunction>
<cffunction access="public" name="setDSN" output="false" returntype="void">
<cfargument name="dsn" required="true" type="string"/>
<cfset variables.instance.dsn=arguments.dsn/>
</cffunction>
</cfcomponent>
</cfcomponent>

View File

@ -1,64 +1,8 @@
<cfcomponent output="no" hint="extend this class with a class that implements the interface IImporter">
<cffunction name="init" output="false" returntype="any">
<cfscript>
variables.instance = structNew();
return this;
</cfscript>
</cffunction>
<cffunction access="private" name="readExcelFile" output="false" returntype="any">
<cfargument name="filepath" hint="Full path to the spreadsheet being read" required="true" type="string"/>
<cfargument name="sheetNumber" default="1" hint="number, 1-based, of the sheet in the workbook to read" type="numeric"/>
<cfargument name="ignoreColumnPoint" default="1" hint="if no content is found in a row by the time this column is reached then that row will be ignored" type="numeric"/>
<cfargument name="headerRow" default="" hint="either a numeric index of the row OR a comma separated list of headers" type="string"/>
<cfargument name="dataStartRow" default="0" hint="provide this if the actual data starts on a wierd row relative to the header info" type="numeric"/>
<cfset var local=structNew()/>
<!--- We are decrementing by 1 so users can continue to pass the literal number they see in the Excel spreadsheet and not worry about the zero-based stuff --->
<cfif Arguments.dataStartRow GT 0>
<cfset Arguments.dataStartRow=Arguments.dataStartRow - 1>
</cfif>
<cfset local.headerRowIndex=0/>
<cfset local.headers=""/>
<cfif IsNumeric(arguments.headerRow)>
<cfset local.headerRowIndex=arguments.headerRow/>
<cfelse>
<cfset local.headers=arguments.headerRow/>
</cfif>
<cfscript>
initFormattingRules();
local.reader = createObject("component", "foo.com.ExcelReader").init(arguments.filepath, arguments.sheetNumber);
local.data = local.reader.read(arguments.ignoreColumnPoint, arguments.dataStartRow);
local.data = local.reader.fixDateAndNumericColumns(local.data, variables.instance.dateColumns, variables.instance.numberColumns);
return local.data;
</cfscript>
</cffunction>
<cffunction
hint="left pads any string with the character provided until the string is the correct length" name="pad" output="false" returntype="string">
<cfargument name="inString" required="true" type="string"/>
<cfargument name="padChar" required="true" type="string"/>
<cfargument name="maxLen" required="true" type="numeric"/>
<cfset var mult=arguments.maxLen - len(arguments.inString)/>
<cfset var i=0/>
<cfloop from="1" index="i" to="#mult#"><cfset arguments.instring=arguments.padChar & arguments.instring/></cfloop>
<cfreturn arguments.inString/>
</cffunction>
<cffunction access="private" name="getDSN" output="false" returntype="string">
<cfreturn variables.instance.dsn/>
</cffunction>
<cffunction access="public" name="setDSN" output="false" returntype="void">
<cfargument name="dsn" required="true" type="string"/>
<cfset variables.instance.dsn=arguments.dsn/>
</cffunction>
</cfcomponent>
<cfcomponent output="no">
<cffunction name="init" output="false" returntype="any">
<cfscript>
variables.instance = structNew();
return this;
</cfscript>
</cffunction>
</cfcomponent>