Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9039881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:50:26+00:00 2026-06-16T09:50:26+00:00

I am receiving excel files from our client and I need to create a

  • 0

I am receiving excel files from our client and I need to create a csv file from them. My issue is that the values in the excel files do not match our standards to create the csv file just by copying it. I need to get the values and put them in the correct order while I’m creating the file. I read through the livedocs for CF but I couldn’t find anything the worked.

I was thinking to create a struct and pull the data out in it and then create the csv file based on my struct but I haven’t done anything like this before and I am not sure if it is even possible. I also thought of using listGetAt instead of the struct but still haven’t tried it.

Anyone did something like this before? I’m trying to hardcode as less values as possible because I see this becoming a future problem if we get a second client with the same issue.

Update (I changed my code around a lot the past few days so this is what I have at the moment)

<cfset DataDirectory = "E:\testfolder\test.xlsx"> 

<cfspreadsheet action="read" src="#DataDirectory#" excludeHeaderRow="true" headerrow="1"  query="queryData"> 

 <cfquery name="contact" datasource="#ds#">
        select ClientBrandID 
        from ClientBrands 
        where surveyReferralID IN
                                (select surveyReferralID from clientAdmin where username = '#res#')
     </cfquery>


    <cfscript>
        dataFile = structNew();
        StructInsert(datafile,"ClientBrandID",contact.ClientBrandID);
        StructInsert(datafile,"surveyType", queryData.surveyType);  
    </cfscript>
 <cfscript> 

    ///We need an absolute path, so get the current directory path. 
    theFile=  "E:\testfolder\NewTest.csv";
    //Create a new Excel spreadsheet object and add the query data. 
    theSheet = SpreadsheetNew("PatientData"); 

    SpreadsheetAddRow(theSheet, "ClientBrandID,SurveyType,Location,ClientContactID,FirstName,LastName,HomePhone,WorkPhone,CellPhone,Email"); <!---This is the header of the new CSV --->
    SpreadsheetAddRows(theSheet, "datafile.clientbrandid, datafile.surveytype"); <!--- This is my latest failed attempt. Tried to pass in data from my struct, probably the quotes are the issue but haven't tried it without them --->
</cfscript> 

<!--- Write the spreadsheet to a file, replacing any existing file. ---> 
<cfspreadsheet action="write" filename="#theFile#" format="csv" name="theSheet" overwrite=true >

All of these operations will need to be in a cfloop in order to go through all of the files in my test folder. Right now I am hardcoding a single file to fix the issue at hand before I do anything else. Also, I am missing another loop in between that will need to go through all the values of the file. It should be something like <cfloop query='queryData'> which is the query that Im getting from cfspreadsheet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:50:28+00:00Added an answer on June 16, 2026 at 9:50 am

    You could make it accept any order but you’ll still need to hard code the expected column headers into an array or something and considering it is just for your internal use I would just add the data back to the CSV in the order it’s supposed to be in. Last time I made a spreadsheet from a query I did it like this. Perhaps it will help.

    <cfscript>
        sMySpreadSheet = spreadsheetNew();
        column = 1;
        <!--- header row --->
        <!--- Remember what is expected from SpreadsheetSetCellValue --->
        <!--- SpreadsheetSetCellValue(spreadsheetObj, value, row, column) --->
    
        spreadsheetSetCellValue(sMySpreadSheet ,"First Name",1,column); column++;
        spreadsheetSetCellValue(sMySpreadSheet ,"Last Name",1,column); column++;
        spreadsheetSetCellValue(sMySpreadSheet ,"DOB",1,column); column++;
        spreadsheetSetCellValue(sMySpreadSheet ,"Phone Number",1,column); column++;
        spreadsheetSetCellValue(sMySpreadSheet ,"Number of Kids",1,column); column++;
    
        <!--- data rows --->
        <!--- if you're not using a header row with real titles you can just use the 
              default col_x 
              example: spreadsheetSetCellValue(sMySpreadSheet , queryData.col_1[q], q+1, column); column++; --->
        for(q=1; q LTE queryData.recordCount; q++){
            column = 1;
            spreadsheetSetCellValue(sMySpreadSheet , queryData.first[q], q+1, column); column++;
            spreadsheetSetCellValue(sMySpreadSheet , queryData.last[q], q+1, column); column++;
            spreadsheetSetCellValue(sMySpreadSheet , queryData.dob[q], q+1, column); column++;
            spreadsheetSetCellValue(sMySpreadSheet , queryData.phoneNumber[q], q+1, column); column++;
            spreadsheetSetCellValue(sMySpreadSheet , queryData.kidCount[q], q+1, column); 
    
        }
        <!--- make it purdy (optional) --->
        spreadsheetFormatRow(queryData, {fgcolor="light_cornflower_blue"},1);   
    </cfscript>
    

    If you want to simply add to a CSV you can do something like this (wrap your stuff in ” if you have them qualified):

    <cfsetting enableCFoutputOnly = "Yes">
    <cfsaveContent variable = "myCSV">
    <cfset newline = #chr(13)#&#chr(10)#>
    <cfoutput>First Name,Last Name,DOB,Phone Number,Number of Kids#newline#</cfoutput>
      <cfoutput query="queryData">#queryData.first#,#queryData.last#,#queryData.dob#,#queryData.phoneNumber#,#kqueryData.idCount##newline#/cfoutput>
    </cfsaveContent>
    </cfsetting>
    <cffile action = "append" file = "[your file]" output = "#myCSV#">
    

    If cfsavecontent causes white spaces issues and cfsetting doesn’t help, here is another alternative.

    <cfset myCSV = "First Name,Last Name,DOB,Phone Number,Number of Kids#newline#">
    <cfloop query="queryData">
      <cfset myCSV &= "#queryData.first#,#queryData.last#,#queryData.dob#,#queryData.phoneNumber#,#queryData.kidCount##newline#">
    </cfloop>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After receiving very good correction from fuzzy lollipop, I amended my code to create
When uploading an excel file I am receiving this error, can anyone help me?
I am successfully receiving DDE data from the ThinkOrSwim trading platform into excel using
I am trying to solve copy pasting a column with values from excel into
I am going to be receiving an excel file on a weekly basis This
I am receiving Invalid Index COM exception when calling Excel.AddIns.Item[0] . Excel.AddIns.Count works all
I am receiving shouldstartloadwithrequest event and I need to stop request for some conditions.
I am receiving an xml feed which has values such as: <Theme>Valentine&#39;s Day</Theme> <Copyright>&#169;
I am using VBA for Excel 2010 and randomly receiving the following error: Run-time
I've got this code I'm trying to use to export data from Excel to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.