我有一个脚本,它正在从客户端读取 CSV 文件,并将值拆分为稍后将进入数据库的变量。
当 CSV 包含的列数少于所需的最小值时,这是我遇到的错误。
In function ListGetAt(list, index [, delimiters]), the value of index, 11, is not a valid as the first argument (this list has 10 elements). Valid indexes are in the range 1 through the number of elements in the list.
Expression
Invalid list index 11.
这是代码示例
<cfscript>
csvData = csvloaderCFC.loadCSVfile(csvfilename);
</cfscript>
<cfset i=0>
<!--- loop CSV Data ---->
<cfloop index="line" list="#csvData#" delimiters="#chr(10)##chr(13)#">
<!--- Ignore 1st Row ---->
<cfif i EQ 0>
<cfset i++>
<cfscript>
continue;
</cfscript>
</cfif>
<!--- Split CSV file --->
<cfscript>
line = csvloaderCFC.listfix(line);
ClientBrandID = (listgetAt('#line#',1) EQ 'NULL')?'':listgetAt('#line#',1);
SurveyType = (listgetAt('#line#',2) EQ 'NULL')?'':listgetAt('#line#',2);
Location= (listgetAt('#line#',3) EQ 'NULL')?'':listgetAt('#line#',3);
ClientContactID = (listgetAt('#line#',4) EQ 'NULL')?'':listgetAt('#line#',4);
FirstName= (listgetAt('#line#',5) EQ 'NULL')?'':listgetAt('#line#',5);
LastName= (listgetAt('#line#',6) EQ 'NULL')?'':listgetAt('#line#',6);
HomePhone= (listgetAt('#line#',7) EQ 'NULL')?'':listgetAt('#line#',7);
WorkPhone= (listgetAt('#line#',8) EQ 'NULL')?'':listgetAt('#line#',8);
CellPhone= (listgetAt('#line#',9) EQ 'NULL')?'':listgetAt('#line#',9);
Email = (listgetAt('#line#',10) EQ 'NULL')?'':listgetAt('#line#',10);
BirthDate= (listgetAt('#line#',11) EQ 'NULL')?'':listgetAt('#line#',11);
Zip= (listgetAt('#line#',12) EQ 'NULL')?'':listgetAt('#line#',12);
Gender= (listgetAt('#line#',13) EQ 'NULL')?'':listgetAt('#line#',13);
InquiryDate= (listgetAt('#line#',14) EQ 'NULL')?'':listgetAt('#line#',14);
ScheduledBy= (listgetAt('#line#',15) EQ 'NULL')?'':listgetAt('#line#',15);
ConsultServiceType= (listgetAt('#line#',16) EQ 'NULL')?'':listgetAt('#line#',16);
ConsultDate= (listgetAt('#line#',17) EQ 'NULL')?'':listgetAt('#line#',17);
ConsultantName= (listgetAt('#line#',18) EQ 'NULL')?'':listgetAt('#line#',18);
ServiceType= (listgetAt('#line#',19) EQ 'NULL')?'':listgetAt('#line#',19);
ServiceDate= (listgetAt('#line#',20) EQ 'NULL')?'':listgetAt('#line#',20);
ServiceProviderName= (listgetAt('#line#',21) EQ 'NULL')?'':listgetAt('#line#',21);
ServiceRevenue= (listgetAt('#line#',22) EQ 'NULL')?'':listgetAt('#line#',22);
LeadSource= (listgetAt('#line#',23) EQ 'NULL')?'':listgetAt('#line#',23);
</cfscript>
<!--- SQL Code begins here --->
我需要修改我的代码,以便能够处理较小的文件,以确定它们是否包含所有列,因为这些也是有价值的信息。