This topic is locked

Can I export data to CSV without quotes around the data?

4/28/2022 8:34:04 PM
ASPRunner.NET General questions
M
MSchell author

ASP runner exports CSV file like this:
"Acct/Finance Prof and Support","","","","7892","Tax Advisor"
I need the file in this format:
Acct/Finance Prof and Support,,,,7892,Tax Advisor

Sergey Kornilov admin 4/29/2022

We do not this kind of option. The correct approach is to wrap text values with quotes, otherwise any field value with the comma in it will break the export.

J
Joe S. 5/3/2022

Be warned this is kind of hacky

had the same requirement and then some, here is what i needed:

  • No column headers
  • The file needs to have UTF-8 coding not UTF-8 with BOM, Basically CSV (MS-DOS)(*.csv).
  • Quotation marks need to be removed
  • TimeStamp in the name of the export file

You will have to modify a file called: exportpage.php
it is located in your output folder, mine is C:\Projects\projectname\output\classes

NOTE: if you make these changes they will be overwritten everytime you publish
it may be a good idea to change the master (template) file which is located
in the program directory:
e.g C:\Program Files (x86)\PHPRunner10.7\source\classes
This however will probably be replaced when updating PHPrunner

In the file exportpage.php
Find the line that says: public function ExportToCSV(.....
This is where the export file is prepared. A few tips on what i did:

No column headers

comment out these two line by adding //
//echo implode( $delimiter, $headerParts );
//echo "\r\n";

UTF-8 coding not UTF-8 with BOM

change
printBOM();
to
//printBOM();

This comments out the flag to create a file with the UTF-8 coding not UTF-8 with BOM.

Quotation marks need to be removed.

change

if( $eventRes ) {
$dataRowParts = array();
foreach( $this->selectedFields as $field ) {
$dataRowParts[] = '"'.str_replace( '"', '""', $values[ $field ] ).'"';
}
echo implode( $delimiter, $dataRowParts );
}

TO
if( $eventRes ) {
$dataRowParts = array();
foreach( $this->selectedFields as $field ) {
$dataRowParts[] = str_replace(",", " ",str_replace( '"', '""', $values[ $field ] ));
}
echo implode( $delimiter, $dataRowParts );
}

the str_repalce will remove any commas in a field value, which would break the format

TimeStamp in the name of the export file

Instead of
header("Content-Disposition: attachment;Filename=".GetTableURL($this->tName).".csv");
i use
header("Content-Disposition: attachment;Filename=".GetTableURL($this->tName).date('Ymd_H:i:s').".csv");

Sergey Kornilov admin 5/4/2022

The question was about ASPRunner.NET so unlikely this can help. But a nice approach overall for a custom export.