2

I have completed all the steps to generate the csv file in cakephp 3.2.Here i have generated the vendor using composer.phar ,and in vendor i got the csv plugin (friendsofcake) ,also i managed from controller to fetch data from database ,that one is also fine. Actually my problem is that data showing in csv file not looking good. i want space between header ,means in A=ID , B=invoice , C=net_totals , D=billing_date
and database data will be shown under respective column . How to use deliminator ,eof and new line

Below i have attached some of my codes.

public function export() {
        $this->response->download('export.csv');
        $data = $this->Orders->find('all')->toArray();
        $_serialize = 'data';
                  $_delimiter = ','; //tab
    $_enclosure = '"';
    $_newline = '\n';
    $_eol = '~';
    $_bom = false;
        $_header = ['ID', 'Invoice', 'net_total','billing_date'];
$_extract = ['id', 'invoice_no', 'net_total','billing_date'];
$this->set(compact('data', '_serialize', '_header', '_extract', '_delimiter'));
        $this->viewBuilder()->className('CsvView.Csv');
        return;
    }

enter image description here

sradha
  • 2,216
  • 1
  • 28
  • 48
  • It's not clear what your problem is. What output are you getting from the code shown, and what do you want it to look like? – Greg Schmidt Sep 08 '16 at 00:56
  • @GregSchmidt ,hi i have added an snap to clarify it. – sradha Sep 08 '16 at 10:40
  • 1
    @sradha Your CSV is correct. Your problem is that you're not opening the file correctly in OpenOffice. Remember your separator is comma(,). Here is the instructions on how to open a CSV: https://wiki.openoffice.org/wiki/Documentation/FAQ/Calc/Files/How_do_I_open_a_tab-delimited_file_in_OpenOffice.org_Spreadsheet%3F_What_if_I_have_a_different_type_of_delimiter%3F – Jsonras Sep 08 '16 at 11:17
  • 1
    @Jsonras thank you .I was not aware about all those things,I thought there is some thing wrong with my Codes. :) :) :) :) :) – sradha Sep 08 '16 at 12:31
  • 1
    Your CSV file is correct. Try to open this file in MS Office. – Developer Sep 08 '16 at 12:45
  • 1
    If your output will only be used in limited contexts and the process for opening it is more user-friendly when there are tab separators, you could set `$_delimiter` to the tab character instead of a comma. – Greg Schmidt Sep 08 '16 at 18:28

0 Answers0