Highlighted

Report CSV file

Engaged ,
Jun 27, 2016

Copy link to clipboard

Copied

I need to create a report using CFReport for CSV format.

I can create Excel, PDF, HTML, XML, RTF and Flash, but I am asked to produce CSV format.

I search CFReport, it does not have CSV option for the format.

I would like to know if it is possible to have CSV format using CFReport or ColdFusion have any other solution for this?

Your information and help is great appreciated,

Regards,

Sourises,

CSV is a data format, not a report format. You don't need cfreport to create a CSV file.

It's worth noting that since you know how to create an Excel file, the user can open the file in Excel and export it in CSV format.

Would you like to see an example of creating a CSV file without cfreport?

Cheers

Eddie

TOPICS
Reporting

Views

795

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Report CSV file

Engaged ,
Jun 27, 2016

Copy link to clipboard

Copied

I need to create a report using CFReport for CSV format.

I can create Excel, PDF, HTML, XML, RTF and Flash, but I am asked to produce CSV format.

I search CFReport, it does not have CSV option for the format.

I would like to know if it is possible to have CSV format using CFReport or ColdFusion have any other solution for this?

Your information and help is great appreciated,

Regards,

Sourises,

CSV is a data format, not a report format. You don't need cfreport to create a CSV file.

It's worth noting that since you know how to create an Excel file, the user can open the file in Excel and export it in CSV format.

Would you like to see an example of creating a CSV file without cfreport?

Cheers

Eddie

TOPICS
Reporting

Views

796

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 27, 2016 0
Advocate ,
Jun 27, 2016

Copy link to clipboard

Copied

CSV is a data format, not a report format. You don't need cfreport to create a CSV file.

It's worth noting that since you know how to create an Excel file, the user can open the file in Excel and export it in CSV format.

Would you like to see an example of creating a CSV file without cfreport?

Cheers

Eddie

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2016 0
Engaged ,
Jun 27, 2016

Copy link to clipboard

Copied

Thanks for the information and help,

Yes, if there is any example link to create a csv file would be appreciated,

Thanks again for helping,

Regards,

Sourises,

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2016 0
Advocate ,
Jun 27, 2016

Copy link to clipboard

Copied

The following is just a demonstration. You can use the concept to do what you want:

<cfsetting showdebugoutput="false">

<cfcontent type="text/csv" reset="true">

<cfheader name="Content-Disposition" value="attachment; filename=example.csv">

<cfscript>

  db = QueryNew("TextField1, NumericField, TextField2", "VarChar, Integer, VarChar");

  queryAddRow(db, [

    {TextField1="abc", NumericField=1, TextField2="def"},

    {TextField1='g"h"i', NumericField=2, TextField2="jkl"},

    {TextField1="mno", NumericField=3, TextField2="pqr"}

  ]);

  for (rowIndex = 1; rowIndex <= db.recordCount; rowIndex++) {

    writeOutput('"');

    writeOutput(replace(db.TextField1[rowIndex], '"', '""', 'all'));

    writeOutput('",');

    writeOutput(db.NumericField[rowIndex]);

    writeOutput(',"');

    writeOutput(replace(db.TextField2[rowIndex], '"', '""', 'all'));

    writeOutput('"');

  if ( rowIndex != db.recordCount )

    writeOutput(',' & chr(13) & chr(10));

}

</cfscript>

The above is the complete text in a cfm file. No HTML is required at all. When you access the file through your browser (for example http://localhost/demo.cfm) your browser will prompt you to save a file called "example.csv" which is a plain text file.

Cheers

Eddie

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2016 0
Engaged ,
Jun 28, 2016

Copy link to clipboard

Copied

Thanks for the information and help,

You use text to hard code the data, I believe that I can use CFQUERY to replace the data and use CFLOOP to go row by row to write to CSV files.

I just wonder does CFDUMP can do the similar result, I think it write to text file, is it possible to use CFDUMP to write to a file using CSV format?

Thanks again for helping,

Regards,

Sourises,

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 28, 2016 0
Advocate ,
Jun 28, 2016

Copy link to clipboard

Copied

Unfortunately there is no way to format the output of the cfdump tag.

You will need to loop over a query result the way I demonstrated.

Cheers

Eddie

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 28, 2016 0