traport
asked on
CFFILE and leading zeros from SQL variables
When I write my SQL variable (recID) to a cffile excel, I lose the leading zeros. The field is a varchar 6 characters in length.
Any suggestions?
Any suggestions?
If you're writing the excel file using table tag, you can include this style...
<td style='mso-number-format:0 00000'>#yo urVal#</td >
<td style='mso-number-format:0
ASKER
Thanks for the responses. I'd love to do it simply through the td style. That said, it's not just numeric. It can be alphanumeric... but when there are leading zeros it loses them. But that style didn't appear to work even on the numeric. Thoughts?
No, I'm not on CF9. I wish I were.
I'm under some time constraints or I would look into Apache POI. As it is, they may have to do w/o their leading zeros.
No, I'm not on CF9. I wish I were.
I'm under some time constraints or I would look into Apache POI. As it is, they may have to do w/o their leading zeros.
Try a slight variation of gd's suggestion. The "@" symbol should force the value to be treated as text
<td style='mso-number-format:" \@";'>0123 45</td>
<td style='mso-number-format:"
You could try generating your Excel document using Apache POI ... Just drop the JARs into your CF class path (c:\coldfusion x\wwwroot\web-inf\lib).
Fyi, CF7+ already include older versions of POI. You don't need to anything extra to do basic xls files. Only if you need newer features. Bear in mind multiple versions do not always co-exist well. You may have to use the javaLoader.cfc instead or possibly replace the old version.
Fyi, CF7+ already include older versions of POI. You don't need to anything extra to do basic xls files. Only if you need newer features. Bear in mind multiple versions do not always co-exist well. You may have to use the javaLoader.cfc instead or possibly replace the old version.
ASKER
Coldfusion cffile doesn't like this at all: <td style='mso-number-format:" \@";'>0123 45</td>
I have tried double-quoting it and it's still breaking.
I have tried double-quoting it and it's still breaking.
I wouldn't try writing complex html directly, because you'll almost always run into problems with nested quotes. Try using cfsavecontent instead. Be sure to wrap it in <cfoutput> tags if the content contains #variables#
ie <cfsavecontent variable="dataToWrite">
<td style='mso-number-format:" \@";'>0123 45</td>
....
</cfsavecontent>
<cffile action="write" output="#dataToWrite#" ...>
That's assuming you actually need to write it to disk ie it's not for an on-the-fly download.
ie <cfsavecontent variable="dataToWrite">
<td style='mso-number-format:"
....
</cfsavecontent>
<cffile action="write" output="#dataToWrite#" ...>
That's assuming you actually need to write it to disk ie it's not for an on-the-fly download.
send single quote before your output... this will not change your output, but excel take it as string/text instead of number..
e.g.
'01234
I guess this should be your last solution if above all will not work.. :)
e.g.
'01234
I guess this should be your last solution if above all will not work.. :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Any luck?
You could try generating your Excel document using Apache POI (http://poi.apache.org/), which generates a "real" Excel document and lets you specify the cell types. Just drop the JARs into your CF class path (c:\coldfusion x\wwwroot\web-inf\lib).
Here's an example...
Open in new window
If you're on ColdFusion 9 there is also a <CFSPREADHEET> tag available, but I haven't used it...
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec17cba-7f87.html