cfspreadsheet alphanumeric values ending in d

<cfscript>
Workbook = Spreadsheetnew("Workbook");
SpreadSheetSetCellValue(WorkBook, "4D", 1, 1);
// displayed 4
SpreadSheetSetCellValue(WorkBook, "4C", 1, 2);
// displayed 4C
SpreadSheetSetCellValue(WorkBook, "4E", 1, 3);
// displayed 4E
SpreadSheetSetCellValue(WorkBook, "5C", 1, 4);
// displayed 5C
SpreadSheetSetCellValue(WorkBook, "5D", 1, 5);
// displayed 5
SpreadSheetSetCellValue(WorkBook, "4d", 1, 6);
// displayed 4
MYfile = "d:dwdwtestdanabc.xls";

</cfscript>
<cfspreadsheet action="write" filename="#MYFile#" name="Workbook"  
    sheet=1 overwrite=true>

ColdFusion Setttings: Version 9,0,1,274733
Edition Enterprise
Operating System Windows 2003
OS Version 5.2

Excel Version Office 2010 Version 14.0.6129.5000 (32 bit).

If you run this code on your system, do you get the same results?

More importantly, if you get the same results, do you know what to do about it?

Edit

Checking for other problematic letters:

RowNumber = 1;
for (i = 65; i <= 90; i++){
SpreadSheetSetCellValue(WorkBook, chr(i), RowNumber, 1);
SpreadSheetSetCellValue(WorkBook, "4#chr(i)#", RowNumber, 2);
RowNumber ++;
}

The string 4F also displayed the number only.


The issue here is that POI is interpreting the F and D as the single/double precision suffixes that Java has. See docs here.

I would say this is a bug with CF, as CFML does not have the concept of these suffixes (or indeed the notion of single or double precision floats), so it should make sure such strings get treated as strings when being passed to POI.


Using Dan's original code to check for troublesome characters I updated it to search for characters (to use by prepending or appending to the given text) to hide this ColdFusion feature:

WorkBook = spreadsheetNew('Test', true);
RowNumber = 1;  
for (i = 1; i <= 255; i++){
    SpreadSheetSetCellValue(WorkBook, i, RowNumber, 1);

    // what character are we displaying
    SpreadSheetSetCellValue(WorkBook, chr(i), RowNumber, 2);

    // see if appending chr(i) allows 4F to display
    SpreadSheetSetCellValue(WorkBook, "4F#chr(i)#", RowNumber, 3);

    // see if appending chr(i) allows 4F to display
    SpreadSheetSetCellValue(WorkBook, "#chr(i)#4F", RowNumber, 4);
    RowNumber ++;
}

Turns out prepending or appending nonprintable characters chr(127) and chr(160) maintain the presentation of 4F or 4D.


If Miguel answers, I'll mark it as correct. The purpose of this answer is to show various things that I tried and how they turned out.

<cfoutput>
<cfscript>
Workbook = Spreadsheetnew("Workbook");
RowNumber = 1;
for (i = 1; i <= 26; i++){
ThisUpperCaseLetter = chr(i + 64);
ThisLowerCaseLetter = chr(i  + 96);
SpreadSheetSetCellValue(WorkBook, ThisUpperCaseLetter, RowNumber, 1);
SpreadSheetSetCellValue(WorkBook, "4#ThisUpperCaseLetter#", RowNumber, 2);
SpreadSheetSetCellValue(WorkBook, ThisLowerCaseLetter, RowNumber, 3);
SpreadSheetSetCellValue(WorkBook, "4#ThisLowerCaseLetter#", RowNumber, 4);
SpreadSheetSetCellValue(WorkBook, "'4#ThisLowerCaseLetter#'", RowNumber, 5);
 // SpreadSheetSetCellFormula(WorkBook, "'4#ThisLowerCaseLetter#'", RowNumber, 6);  
/*
The line above threw this error
org.apache.poi.ss.formula.FormulaParser$FormulaParseException: 
Parse error near char 0 ''' in specified formula ''4a''. 
Expected number, string, or defined name 
*/

SpreadSheetSetCellValue(WorkBook, """4#ThisLowerCaseLetter#""", RowNumber, 6);
SpreadSheetSetCellValue(WorkBook, "'4#ThisLowerCaseLetter#'", RowNumber, 7);
      // the next line is the only one that will achieve the desired result
SpreadSheetSetCellFormula(WorkBook, """4#ThisLowerCaseLetter#""", RowNumber, 8);
RowNumber ++;
}
MYfile = "d:dwdwtestdanabc.xls";

</cfscript>
</cfoutput>
<cfspreadsheet action="write" filename="#MYFile#" name="Workbook"  
    sheet=1 overwrite=true>

Anything with SpreadsheetCellValue would display the quotes, plus the backslash I used to attempt to escape them. As indicated above, SpreadsheetSetCellFormula with triple quotes is the only way that appears to give expected results 100% of the time.

More Info In my actual application, I use cfheader/cfcontent to offer the file. If I select Open, with IE9, Excel shows a dangerous content warning and offers me a button to Enable Editing. Also, any cells created with SpreadSheetSetCellFormula() display the number 0. Selecting the cell shows the actual value in the excel value box, or whatever that's called. Also, enabling editing changes the display to the expected values.

链接地址: http://www.djcxy.com/p/70180.html

上一篇: onAttach活动为空

下一篇: 以d结尾的cfspreadsheet字母数字值