ColdFusion (9) mysteriously removes characters 'D' and 'F' after numbers when exporting to Microsoft Excel (2007)

后端 未结 4 865
伪装坚强ぢ
伪装坚强ぢ 2020-12-21 00:59

Here\'s some code snippets for an example:

theSheet = SpreadsheetNew(\"Rates\",\"True\");
SpreadsheetAddRow(theSheet,\"4A,4B,4C,4D,4E,4F,4G,4H,4I,4J\");
Spre         


        
相关标签:
4条回答
  • 2020-12-21 01:28

    It seems that a workaround is to set the cell formula to be the literal "4D".

    theSheet = SpreadsheetNew("Rates","True");
    SpreadsheetAddRow(theSheet,"4A,4B,4C,,4E,,4G,4H,4I,4J");
    SpreadsheetSetCellFormula(theSheet, """4D""", 1, 4);
    SpreadsheetSetCellFormula(theSheet, """4F""", 1, 6);
    SpreadsheetAddRow(theSheet,"4K,4L,4M,4N,4O,4P,4Q,4R,4S,4T");
    SpreadsheetAddRow(theSheet,"4U,4V,4W,4X,4Y,4Z,4D4,4F4");
    

    I still don't know why this is happening, but my idea is that SpreadsheetAddRow() and SpreadsheetSetCell() are interpreting 4D and 4F as numeric and are interpreting the D and F and suffixes standing for Double and Float, and stripping them out after conversion.

    You can submit the bug to Adobe by going to https://bugbase.adobe.com/index.cfm.

    0 讨论(0)
  • 2020-12-21 01:31

    You might try the old spreadsheet trick -- going back to Lotus days -- of coercing values to text by starting the entry with a single quote: '4D.

    0 讨论(0)
  • 2020-12-21 01:31

    I updated code from a related stack question 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

    Related stack question I mentioned: cfspreadsheet alphanumeric values ending in d

    0 讨论(0)
  • You should try to use D char code explicitly chr(68) instead of "D".

    0 讨论(0)
提交回复
热议问题