I am doing data exporting by CSV format.
Problem : When data contains white space then it jumps column in csv file
In Image check at customer_id = 8
in address1 correct value is "starline appartment" But "starline" stay in address1 and "appartment" goes in address2.
This is controller code
$em = $this->getDoctrine()->getManager('db1');
$connection = $em->getConnection();
$query = "SELECT *
FROM customers
ORDER BY customer_id ASC
LIMIT 10";
$statement = $connection->prepare($query);
$statement->execute();
$rows = $statement->fetchAll();
$columns = $em->getClassMetadata('AdminSporteventsBundle:Customers')->getFieldNames();
foreach ($columns as $value) {
$finalcolumns[] = strtolower(preg_replace('/\B([A-Z])/', '_$1', $value));
}
//echo "<pre>";print_r($rows);echo "</pre>";die;
$response = $this->render('AdminSporteventsBundle:Export:export.csv.twig', array('data' => $rows));
$filename = "export_".date("Y_m_d_His").".csv";
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
return $response;
And this is my view file code
cusromer_id, email_id, facebook_id, password, forname, surname, house_no, address1, address2, town, country, postcode, mobile, telepnone, created_date, updated_date
{% for customer in data %}
{{ customer.customer_id }}, {{ customer.email_id }}, {{ customer.facebook_id }}, {{ customer.password }}, {{ customer.forname }}, {{ customer.surname }}, {{ customer.house_no }}, {{ customer.address1 }}, {{ customer.address2 }}, {{ customer.town }}, {{ customer.country }}, {{ customer.postcode }}, {{ customer.mobile }}, {{ customer.telepnone }}, {{ customer.created_date }}, {{ customer.updated_date }}
{% endfor %}
So what can I do to solved this ?