coldfusioncoldfusion-10cfmlrailocfspreadsheet

cfspreadsheet save as .csv, Excel says "The file format and extension of FILE.csv don't match."


I've created a cold fusion page to output a client list from MYSQL into a CSV file for easy uploading to SalesForce.com

I can generate the file with all the correct information. However, when I try to open it with excel I get the error: "The file format and extension of 'SalesForceDailyLeads-20160613125138.csv' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?" I can open it(excel for MAC), but it appears to me that CFSpreadsheet is not creating a legit .csv file and is instead making a xlsx.

    <cfset FileCSV = "SalesForceDailyLeads-#dateformat(getBatch.BATCH,"yyyymmdd")##timeformat(getBatch.BATCH,"HHmmss")#.csv" >
    <cfset filename = "/SF/#fileCSV#">



    <cfset s = spreadsheetNew() >
    <cfset spreadsheetAddRow(s, "FIRST, LAST, MIDDLE, STREET, CITY, ZIP, STATE")>

    <cfinclude template="SFgetList.cfm">

    <cfset spreadsheetAddRows(s, getList)>

    <cfspreadsheet
        action="write"
        overwrite = "true"
        format ="csv"
        name ="s"
        filename ="#filename#"
        >

If I make an XLS file I have no issues like I do with CSVs. Is this a problem with the code, CFSpreadsheet, or excel(for mac)? Can I fix it?


Solution

  • Use cffile, not cfspreadsheet to create the files. Per the documentation:

    The cfspreadsheet tag writes only XLS[X] format files. To write a CSV file, put your data in a CSV formatted string variable and use the cffile tag to write the variable contents in a file.