Jump to content

Export to CSV -- FIXED!

Guest CoastalData

Recommended Posts

Guest CoastalData

Hello, I've tried several times to use the Export to CSV function in CC, but it has never produced acceptable output, so today I went in and made several modifications that have fixed the problem, I think, entirely.

The first problem I found seems a little too obvious, maybe there was some kind of corruption in my install??? Can't imagine why this worked at all...

Starting at line 199 of export.inc.php, I found this code:

			$name = str_replace(array(" ","\t","\r","\n","\0","\x0B","


$name = str_replace(" ","",$name);

$desc = str_replace(array(" ","\t","\r","\n","\0","\x0B","


$desc = str_replace(" ","",$desc);

Notice the bad line breaks... I dunno, maybe PHP just ignores the white space before the semi, as does Perl, but it really should be this:

			$name = str_replace(array(" ","\t","\r","\n","\0","\x0B",""),"",strip_tags($results[$i]['name']));

$name = str_replace(" ","",$name);

$desc = str_replace(array(" ","\t","\r","\n","\0","\x0B",""),"",strip_tags($results[$i]['description']));

$desc = str_replace(" ","",$desc);

The next problem I found/fixed was that if the description field contains any quotes, this will screw things up, so I converted those to HTML entities like this:

			$desc = str_replace("  ","",$desc);

$desc = str_replace("\"",""",$desc);

Finally, I'm a Windows guy, so I want the file to be more easily usable in Excel, so I changed this:

			$ccContent .= $name.",".$results[$i]['productCode'].",".$desc.",".$results[$i]['price'].",".$results[$i]['sale_price'].",".$results[$i]['image'].",".$results[$i]['stock_level'].",".$results[$i]['useStockLevel'].",".$results[$i]['cat_id']."\r\n";

To this:

			$ccContent .= "\"".$name."\",\"".$results[$i]['productCode']."\",\"".$desc."\",\"".$results[$i]['price']."\",\"".$results[$i]['sale_price']."\",\"".$results[$i]['image']."\",\"".$results[$i]['stock_level']."\",\"".$results[$i]['useStockLevel']."\",\"".$results[$i]['cat_id']."\"\r\n";

Basically all that does is to wrap each and every field in double quotes, the way Excel likes it. OpenOffice may not have the same preferences for quoting, but I'm sure it'll deal with it equally well.

Now, I'm not so sure the import function will handle these modifications without further modification to the import module... Maybe the "right" thing to do here would be to add a new option to the drop down menu like "Export to CSV (Excel)" and then add the appropriate "else if" to the code so that the existing format can still work as is, while simply adding on the new format.

Either way, at the bare minimum, however, I think that the HTML entity for the quotes should be a fix for all to use.

Hope this helps!


Link to comment
Share on other sites

Guest CoastalData

Hmm, Okay, cool -- How can I quickly get my running version #? I know I am running CC4, but not sure which release...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...