我正在使用CF10并尝试在电子表格中添加%符号。
我在第5列条目中添加%符号时出现问题。 (查询完成后,只有开始第二行(不是标题)的条目而不是空白单元格。
<cftry>
<cfset objSpreadsheet = SpreadsheetNew()>
<cfset assocRows = ''>
<!--- Create and format the header row. --->
<cfset SpreadsheetAddRow( objSpreadsheet, "Associate Name,Location,Checklists Generated by Associate,Checklists Generated by Selected Location(s),Associate Percentage of Location Total" )>
<cfset rowNumber = 1 />
<cfoutput query="GetEmployeeInfo">
<cfset rowNumber++ />
<cfset rowList = "'#(rnA eq 1)?assoc_name:''#','#(rnl eq 1)?trans_location:''#','#checklistsByAssocLoc#','#assocChecklistsByLoc#','#DecimalFormat(totalChecklistsByAssocLocPct)#'">
<!--- Make list of rows --->
<cfif (rnA eq 1)>
<cfset assocRows = ListAppend(assocRows, rowNumber)>
</cfif>
<cfset SpreadsheetAddRow( objSpreadsheet, rowList)>
<cfif rnTotAssoc EQ 1>
<cfset rowNumber++ />
<cfset rowList = "'Associate Total','','#totalChecklistsByAssoc#','#totalAssocChecklistsByAllFilteredLoc#','#DecimalFormat(totalChecklistsByLocPct)#'" >
<cfset SpreadsheetAddRow( objSpreadsheet, rowList )>
</cfif>
</cfoutput>
<cfset SpreadSheetSetColumnWidth(objSpreadsheet,1,25)>
<cfset SpreadSheetSetColumnWidth(objSpreadsheet,2,25)>
<cfset SpreadSheetSetColumnWidth(objSpreadsheet,3,25)>
<cfset SpreadSheetSetColumnWidth(objSpreadsheet,4,25)>
<cfset SpreadSheetSetColumnWidth(objSpreadsheet,5,25)>
<!--- Move the line here --->
<cfset SpreadsheetFormatRow( objSpreadsheet, {bold=true, textwrap="true", alignment="center"}, 1 )>
<cfloop list="#assocRows#" index="i">
<cfset SpreadsheetFormatCell(objSpreadsheet, {'bold' : 'true'}, i, 1)>
</cfloop>
<cfheader name="Content-Disposition" value="inline; filename=CS_#Dateformat(NOW(),'MMDDYYYY')#.xls">
<cfcontent type="application/vnd.ms-excel" variable="#SpreadsheetReadBinary( objSpreadsheet )#">
<cfcatch type = "any">
#rowList#
<cfabort>
</cfcatch>
</cftry>
我尝试过添加:
'#DecimalFormat(totalChecklistsByLocPct)# %'"
然后excel不知道正确的格式。
然后我试过:
<cfset spreadsheetFormatCell( objSpreadsheet, {dataformat: "0.00%"}, 2 )>
然后只是出错:
SPREADSHEETFORMATCELL函数的参数验证错误。
任何有关如何将此%符号添加到5列的帮助(一旦查询停止,不是标题或空白单元格)将不胜感激。
修改
也尝试过:
<cfset rowList = "'#(rnA eq 1)?assoc_name:''#','#(rnl eq 1)?trans_location:''#','#checklistsByAssocLoc#','#assocChecklistsByLoc#','#NumberFormat(totalChecklistsByAssocLocPct, '0.00')# %'">
Excel仍然通过错误将其格式化为文本。