CFspreadsheet adding a % to format a column

社会主义新天地 提交于 2019-12-13 02:48:02

问题


I am using CF10 and trying to add a % sign to a spreadsheet.

I am having an issue with adding a % sign on my 5th column entries. (Only the entries starting the second row (not the header) and not the blank cells when the query is done running.

<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>

I have tried adding: '#DecimalFormat(totalChecklistsByLocPct)# %'" which then excel doesnt know the correct format.

Then I tried: <cfset spreadsheetFormatCell( objSpreadsheet, {dataformat: "0.00%"}, 2 )>

Which then just through an error:

Parameter validation error for the SPREADSHEETFORMATCELL function.

Any help on how to add this % sign to the 5 column (not the header or blank cells once the query stops) would be greatly appreciated.

EDIT

Also tried:

<cfset rowList = "'#(rnA eq 1)?assoc_name:''#','#(rnl eq 1)?trans_location:''#','#checklistsByAssocLoc#','#assocChecklistsByLoc#','#NumberFormat(totalChecklistsByAssocLocPct, '0.00')# %'">

Excel still through the error saying its formatted as text.

来源:https://stackoverflow.com/questions/46955275/cfspreadsheet-adding-a-to-format-a-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!