Is there a way to check whether an Excel file has a header or not?
Hi!
I'm currently using POI Utility to read and write Excel files.
You normally use the HasHeaderRow = true / false to specify whether the file has a header or not.
Now, let's say I have a program that needs to read Excel files from a directory, some have headers, some don't.
Is there a way to know dynamically whether a header has been defined or not?
Then, for those having headers, the flag will be set as true, while for those which don't have any header, the flag will be set as false.
E.g.
<!--- Create an instance of the POIUtility.cfc. --->
<cfset objPOI = CreateObject(
"component",
"POIUtility"
).Init()
/>
<!--- Set directory --->
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "newDir">
<!--- Check whether the directory exists. --->
<cfif DirectoryExists(variables.currentDirectory)>
<!--- Read files from the specified directory --->
<cfdirectory action="list" directory="#variables.currentDirectory#" type="file" filter="*.xls" name="qDirectory">
<!--- Check if the directory has any Excel file --->
<cfif variables.qDirectory.recordcount gt 0>
<!--- Loop query --->
<cfloop query="variables.qDirectory">
<!--- Check if header is present in each of the file --->
IF headerExists THEN
headerFlag = true
ELSE
headerFlag = false
END IF
<!--- Read Excel File --->
<cfset objSheet = objPOI.ReadExcel(FilePath = #variables.qDirectory.name#, HasHeaderRow = #variables.headerFlag#, SheetIndex = 0) />
</cfloop>
</cfif>
</cfif>
Any help would be most welcome.
Thanks and regards,
Yogesh Mahadnac
