ColdFusion TIPS PLUS
Issue 00118 http://www.cftipsplus.com
I. My CommentsII. ColdFusion In Context: Paste Spreadsheets
By R. Martin Ladner
martin.ladner@charter.net
III. ColdFusion Components (CFC's) Beginners Only
By Nathan Stanford
Advanced, Intensive ColdFusion Training!Visit this site. If you have plans to get training here is a company
that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus
I. Comments:
Methodologies: Other then FuseBox and CFObjects what other methodologies are in use out there? If your using a different methodology please let me know.
If you have a ColdFusion Question you would like answered please send it to me and I will try to get too it. Questions on ColdFusion MX, ColdFusion Coding, HTML, JavaScript, or any other send them in.
Keep Coding,
Nathan Stanford
http://www.cftipsplus.com
If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:
NathanS<at>nsnd.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name known in the
ColdFusion Community.
II. ColdFusion in Context: Paste Spreadsheets
By R. Martin Ladner
martin.ladner@charter.net
Suppose your customer needs to replace tables of a page or two in size on the customer's Web site frequently. They might be grade reports. They might be poll results. Perhaps neither you nor your customer wants to hassle with uploading files. Manually retyping the data is not an option.
This tip shows that your customer can simply paste spreadsheets to the Web site and have them automatically converted to HTML tables.
Code
When you copy a rectangle of cells from Excel and paste them into a simple word processor, you get tab-delimited rows. Each row ends in a linefeed.
Put the code to accept data from the user into paste.cfm. Begin by setting a empty default for the input variable. Then set the ASCII value for a horizontal tab (9) to a variable; since it's less familiar than the value for linefeed and you need to leave a breadcrumb trail for those who will follow you.
If the input variable is not empty, build a table from its contents. To do this, set an outer loop delimited by the linefeed character, chr(10), to control the placement of tr tags. Then, set an inner loop delimited by the tab character to place the row data one piece at a time within td tags. Wrap all of this effort within a table tag, and be sure to give the table a border.
<cfparam name="form.Pastein" default="">
<cfset Tab="#chr(9)#">
<cfif len(trim(form.Pastein))>
<cfoutput>
<table border="1">
<cfloop list="#form.Pastein#"
index="TheRow" delimiters="#chr(10)#">
<tr>
<cfloop list="#TheRow#"
index="TheCol" delimiters="#Tab#">
<td>#TheCol#</td>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
</cfif>
Create a simple form that contains a textarea tag and a submit button. Let the value for the textarea tag be the previously submitted value (or an empty default). Use a cfoutput tag to expand it. When the Read button is selected, the page is submitted to itself.
<form name="paste" action="paste.cfm" method="post">
<cfoutput><textarea name="Pastein" rows="10" cols="70">
#form.Pastein#</textarea></cfoutput>
<input type="submit" name="do" value="Read">
</form>
Test
Open an Excel spreadsheet. Highlight and copy data. Paste it into paste.cfm, and press the Read button. If all goes well, you'll see the same data above the textarea as you copied from the spreadsheet. If you didn't get all the data you wanted, copy it again (or edit it in the textarea field) and press Read. Repeat until satisfied.
Extend
It only takes one more button and a few more lines to save the information to tab-delimited files for later parsing and display. Indeed, if the spreadsheet has an agreed-upon format, you can even use this technique to parse and post dozens of rows to a database all at once. If you can parse it, it's yours.
=Marty=
III. ColdFusion Components (CFC's) Beginners Only
By Nathan Stanford
As has been requested. I am going to try to explain CFC's and while at it explain a few other things along the way. I am going to oversimplify them for this article.
File 'sample.cfc'
<CFCOMPONENT>
<!--- Function Test1 --->
<cffunction name="Test1" access="public" returntype="string" hint="This will explain what I do">
<!--- Query that gets the List of Employees by Department. --->
<CFQUERY name="HRDeptEmployeesList" datasource="testdsn">
select *
from Employees
where Dept = '#arguments.Dept#'
</CFQUERY>
<CFRETURN HRDeptEmployeesList>
</cffunction>
<!--- Function Testxxx --->
<cffunction name="Testxxx" access="public" returntype="string" hint="This will explain what I do">
.........
More Functions
.........
</cffunction>
</CFCOMPONENT>
File 'test.cfm'
<CFINVOKE component="sample" method="Test1" returnvariable="foo">
<CFINVOKEARGUMENT name="Dept" value="PayRoll">
</CFINVOKE>
<CFOUTPUT query="foo">
#FirstName# #LastName# #ext#<BR>
</CFOUTPUT>
If you have questions please send them in I may or may not get to all of them. However I will do the best I can.
SPONSOR ADS:
This e-mail is sponsored by the following ads.
Advanced, Intensive ColdFusion Training!Visit this site. If you have plans to get training here is a company
that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus
Publisher and Creator:
Nathan Stanford,
NathanS<at>nsnd.com
http://www.cftipsplus.com
Macromedia and ColdFusion are U.S. registered trademarks.
Copyright (c) 2000 - 2002
CFTIPSPLUS.COM and NSND.COM
Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.