How to use columns attribute when read a CSV file in ColdFusion

cfhttp - columns attribute when reading a csv file

employee1.csv


1, Jenny, Jones
2, Anne, Joli
3, Sonia, Fara

cfhttpColumns.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfhttp: how to use columns attribute when read a csv file in coldfusion</title>
</head>

<body>
<h2 style="color:IndianRed; font-style:italic">cfhttp tag example: how to use columns attribute</h2>
<hr width="500" align="left" color="IndianRed" />
<br />

<cfhttp 
  method="get"
    url="http://localhost:8500/cfexample/employee1.csv" 
    name="EmployeeData"
    columns="EmpID,FirstName,LastName"
    firstRowAsHeaders="no"
    >
</cfhttp>

<table border="1" cellpadding="5" cellspacing="0" bordercolor="IndianRed">
    <tr bgcolor="Crimson" style="color:White; font-weight:bold">
        <td>
            Employee ID
        </td>
        <td>
            First Name
        </td>
        <td>
            Last Name
        </td>
    </tr>
 <cfoutput query="EmployeeData">
     <tr bgcolor="Snow" style="color:IndianRed; font-weight:normal">
         <td>
                #EmpID#
            </td>
         <td>
                #FirstName#
            </td>
         <td>
                #LastName#
            </td>
        </tr>
    </cfoutput>
</table>

</body>
</html>






More ColdFusion examples

How to use get method in cfhttp in ColdFusion

cfhttp - get method

employee2.csv


EmpID, FirstName, LastName
1, Jenny, Jones
2, Mona, Lisa
3, Faria, Ruma
4, Suria, Sen

cfhttpGetMethod.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfhttp: how to use get method in cfhttp tag in coldfusion</title>
</head>

<body>
<h2 style="color:DarkSeaGreen; font-style:italic">cfhttp tag example: how to use get method</h2>
<hr width="425" align="left" color="DarkSeaGreen" />
<br />

<cfhttp 
 method="get"
    url="http://localhost:8500/cfexample/employee2.csv" 
    name="EmployeeList"
    >
</cfhttp>

<table border="1" cellpadding="5" cellspacing="0" bordercolor="CornFlowerBlue">
    <tr bgcolor="DodgerBlue" style="color:Snow; font-weight:bold">
        <td>
            Employee ID
        </td>
        <td>
            First Name
        </td>
        <td>
            Last Name
        </td>
    </tr>
 <cfoutput query="EmployeeList">
     <tr bgcolor="Snow" style="color:RoyalBlue; font-weight:normal">
         <td>
                #EmpID#
            </td>
         <td>
                #FirstName#
            </td>
         <td>
                #LastName#
            </td>
        </tr>
    </cfoutput>
</table>

</body>
</html>





More ColdFusion examples

CFhttp - Using delimiter when reading a CSV file in ColdFusion

cfhttp - delimiter attribute

employee.csv


Emp_ID; FirstName; LastName
1; Jenny; Jones
2; Anne; Patel
3; Sonia; Akter


cfhttpDelimiter.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfhttp: how to use delimiter attribute when read a csv file in coldfusion</title>
</head>

<body>
<h2 style="color:DeepPink; font-style:italic">cfhttp tag example: how to use delimiter attribute</h2>
<hr width="500" align="left" color="OrangeRed" />
<br />

<cfhttp 
 method="get"
    url="http://localhost:8500/cfexample/employee.csv" 
    name="EmployeeData"
    delimiter=";"
    >
</cfhttp>

<table border="1" cellpadding="5" cellspacing="0" bordercolor="Crimson">
    <tr bgcolor="OrangeRed" style="color:Snow; font-weight:bold">
        <td>
            Employee ID
        </td>
        <td>
            First Name
        </td>
        <td>
            Last Name
        </td>
    </tr>
 <cfoutput query="EmployeeData">
     <tr bgcolor="Snow" style="color:Crimson; font-weight:normal">
         <td>
                #Emp_ID#
            </td>
         <td>
                #FirstName#
            </td>
         <td>
                #LastName#
            </td>
        </tr>
    </cfoutput>
</table>

</body>
</html>





More ColdFusion examples