Copy link to clipboard
Copied
I was given a task to convert around 32,000 Excel spreadsheets to HTML fomat. I had them changed to CSV format, then used a ColdFusion script to do it, but now I have to create an index page for each of the directories. The aforementioned pages are grouped into around 15 directories, so I decided to use cfdirectory to build the initial index page, after which I copy/paste the generated code into a static page.
It was working great until they decided they wanted the Excel files to live in the directory with the cfm files. So now I need to make a table with a column for the cfm file, and a column for the xls. This means running two cfdirectory tags (one for the cfm files, and one for the xls files). The problem with this is that I can't nest the outputs from these.
Here's the code I'm working with (btw, there are two cfm files for each Excel):
<cfdirectory directory="#expandpath("./")#" name="getcfm" action="list" filter="part*.cfm">
<cfdirectory directory="#expandpath("./")#" name="getxls" action="list" filter="Part*.xls"><table border="1" cellspacing="0" cellpadding="5">
<tr>
<th scope="col">Location</th>
<th scope="col" colspan="3">Format</th>
</tr>
<cfoutput query="getcfm"><tr>
<th scope="row" class="row">#rereplace(listfirst(mid(getcfm.name,15,50),"_"),"(\b\w)","\u\1","ALL")#</th>
<td>HTML, <a href="#getcfm.name#">Number</a>
<td>HTML, <a href="#replace(getcfm.name,"number","pct")#">Pct</a></td></td>
<td><a href="#getxls.name#">Excel</a></td>
</tr>
</cfoutput></table>
This builds the table with the proper CFM files, but it gives me the same Excel file over and over. What I really need is a loop within the loop, but nothing I try works. Any ideas?
I guess my other option is to just make two tables, but I'd rather do just the one.
Copy link to clipboard
Copied
<cfoutput query...> is a specific purpose loop control. It makes outputing a record set dirt easy, but it is not required.
Just to give you one possible idea. GIve this a try.
<cfoutput>
<cfloop from="1" to="5" index="i">
#getCFM["name"]# -- #getXLS["name"]#<br>
</cfloop>
</cfoutput>
I leave it up to you to learn more about the fully qualified record set variable, loops and how to tie it all together for your desired output.
Copy link to clipboard
Copied
Another variation just because I'm waiting on some long running code to finish.
<cfoutput query="getCMS">
#getCMS.name# --- #getXLS["name"][getCMS.currentRow]#
</cfoutput>
Copy link to clipboard
Copied
Thanks, I'll try these. I tried a cfloop inside the cfoutput like that, but it just froze up. I'll try it the way you posted and report back.
Copy link to clipboard
Copied
Ok! That second one worked well. My only problem is that I have to somehow control the row number because I have twice as many cfm files as Excel files, so I need to somehow skip every other row in one column and not in the other.