Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfset showForm = true>
- <cfif structKeyExists(form, "xlsfile") and len(form.xlsfile)>
- <!--- Destination outside of web root --->
- <cfset dest = getTempDirectory()>
- <cffile action="upload" destination="#dest#" filefield="xlsfile" result="upload" nameconflict="makeunique">
- <cfif upload.fileWasSaved>
- <cfset theFile = upload.serverDirectory & "/" & upload.serverFile>
- <cfif isSpreadsheetFile(theFile)>
- <cfspreadsheet action="read" src="#theFile#" query="data" headerrow="1">
- <cffile action="delete" file="#theFile#">
- <cfset showForm = false>
- <cfelse>
- <cfset errors = "The file was not an Excel file.">
- <cffile action="delete" file="#theFile#">
- </cfif>
- <cfelse>
- <cfset errors = "The file was not properly uploaded.">
- </cfif>
- </cfif>
- <cfif showForm>
- <cfif structKeyExists(variables, "errors")>
- <cfoutput>
- <p>
- <b>Error: #variables.errors#</b>
- </p>
- </cfoutput>
- </cfif>
- <form action="test2.cfm" enctype="multipart/form-data" method="post">
- <input type="file" name="xlsfile" required>
- <input type="submit" value="Upload XLS File">
- </form>
- <cfelse>
- <style>
- .ssTable { width: 100%;
- border-style:solid;
- border-width:thin;
- }
- .ssHeader { background-color: #ffff00; }
- .ssTable td, .ssTable th {
- padding: 10px;
- border-style:solid;
- border-width:thin;
- }
- </style>
- <p>
- Here is the data in your Excel sheet (assuming first row as headers):
- </p>
- <cfset metadata = getMetadata(data)>
- <cfset colList = "">
- <cfloop index="col" array="#metadata#">
- <cfset colList = listAppend(colList, col.name)>
- </cfloop>
- <cfif data.recordCount is 1>
- <p>
- This spreadsheet appeared to have no data.
- </p>
- <cfelse>
- <table class="ssTable">
- <tr class="ssHeader">
- <cfloop index="c" list="#colList#">
- <cfoutput><th>#c#</th></cfoutput>
- </cfloop>
- </tr>
- <cfoutput query="data" startRow="2">
- <cfset hadStuff = false>
- <cfsavecontent variable="row">
- <tr>
- <cfloop index="c" list="#colList#">
- <cfif not hadStuff and len(trim(data[c][currentRow]))>
- <cfset hadStuff = true>
- </cfif>
- <td>#data[c][currentRow]#</td>
- </cfloop>
- </tr>
- </cfsavecontent>
- <cfif hadStuff>#row#</cfif>
- </cfoutput>
- </table>
- </cfif>
- </cfif>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement