Link to home
Start Free TrialLog in
Avatar of earwig75
earwig75

asked on

Can I format excel columns with coldfusion 11? Using CFSPREADSHEET?

I have a simple ColdFusion query that returns 4 columns.  1 column may contain leading zeros. I'd like to display these numbers as text, or at least format it so the whole number shows up properly. Can someone assist?

I've read through coldfusion's documentation and looked at tons of examples but nothing works.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of earwig75
earwig75

ASKER

@AGX _ I am using this to format a date field. Is there an equivalent to preserve leading zeros, and format a number as a string?

<cfset SpreadsheetFormatColumn(sObj, {dataformat="m/d/yy h:mm"}, 4)>
Updated - Fixed code example

First, not sure if you saw the updated answer.  Assuming the query column stores values with leading zeroes, ie "0000123" or "00000", then specifying cell type "string" should accomplish what you need, without any extra formatting:

      <cfset SpreadSheetSetCellValue(sheet, qry.ZipCode, currentRow, 4, "string")>

But to answer your question, yes you can also use "@" to format a cell, row or column as text:

      <cfset SpreadsheetFormatCell(sheet, {dataFormat="@"}, currentRow, 4)>

However ... formatting doesn't always work as expected. CF has some issues with that. Sometimes CF ignores formats unless a cell(s) have values, but ... if you add the values first they get converted to  numbers. Kind of a catch 22.  

Try the updated example first. It worked for me w/CF11. If so, you can skip formatting.
I am formatting entire columns, do I just change it to the function for the column?

Would something like this work?
<cfset SpreadsheetFormatColumn(sObj, {dataformat="string"}, 4)>
Did you try the original example (updated)? Because you shouldn't need SpreadsheetFormatColumn.  The example already preserves leading zeroes in the query column values.

Would something like this work?

Maybe, but ... probably not.  Like I mentioned earlier, CF has issues with formatting. SpreadsheetFormatColumn did not work for me. That's why I recommended the code above instead.

Side note,  if you do use formatting, the correct syntax to create a "text" cell is:

         {dataFormat="@"}  

.... rather than this:

          {dataformat="string"}.
I need this ability for another page that has 50 columns, and I was hoping I wouldn't have to re-do the entire cfspreadsheet code etc.
Well without seeing the code, I can't say if it'll work or not. It didn't in this example, but you could always test it with the correct format ie {dataFormat="@"}  and see.  Unfortunately though, some of the CF spreadsheet functions are still hit or miss ...