cakedc csvimport从csv文件中取不到任何记录

时间:2014-12-22 21:59:29

标签: excel cakephp csv cakedc

我有以下CSV文件,第一行是标题:

admission_no;first_name;last_name;gender;date_of_birth;join_date;form_id;stream_id;school_photo
1003;"cavin";"cavin";"cavin";"male";1992-11-02;2007-01-25;1;1
1004;"joshua";"joshua";"joshua";"male";1992-11-03;2007-01-26;1;1
1005;"elijah";"elijah";"elijah";"male";1992-11-04;2007-01-27;1;1
1006;"lawrent";"lawrent";"lawrent";"male";1992-11-05;2007-01-28;1;1
1007;"steven";"steven";"steven";"male";1992-11-06;2007-01-29;1;2
1008;"javan";"javan";"javan";"male";1992-11-07;2007-01-30;1;2
1009;"miller";"miller";"miller";"male";1992-11-08;2007-01-31;1;2
1010;"javis";"javis";"javis";"male";1992-11-09;2007-02-01;1;2
1011;"fredrick";"fredrick";"fredrick";"male";1992-11-10;2007-02-02;1;3
1012;"fredrick";"fredrick";"fredrick";"male";1992-11-11;2007-02-03;1;3
1013;"nahashon";"nahashon";"nahashon";"male";1992-11-12;2007-02-04;1;3
1014;"nelson";"nelson";"nelson";"male";1992-11-13;2007-02-05;1;3
1015;"martin";"martin";"martin";"male";1992-11-14;2007-02-06;1;4
1016;"felix";"felix";"fwlix";"male";1992-11-15;2007-02-07;1;4
1017;"tobias";"tobias";"tobias";"male";1992-11-16;2007-02-08;1;4
1018;"dennis";"dennis";"dennis";"male";1992-11-17;2007-02-09;1;4
1019;"bildad";"bildad";"bildad";"male";1992-11-18;2007-02-10;1;5
1020;"syslvester";"sylvester";"sylvester";"male";1992-11-19;2007-02-11;1;5

我的数据库表格列为:admission_nofirst_namelast_namegenderdate_of_birthjoin_date,{{1} },form_idstream_id

使用CakeDC Utils插件导入数据,我收到一条flash消息:

  

从file.csv

成功导入了0条记录

我尝试删除标题,更改分隔符,甚至为school_photo列添加NULL,因为它可以为空但似乎没有任何效果。

有人能告诉我出错了吗?

使用Ubuntu libre Office生成csv 导入功能:

school_photo

} //结束导入

视图文件

function import() {
   $modelClass = $this->modelClass;
   if( $this->request->is('POST') ) {
   $records_count = $this->$modelClass->find('count');
    try {
      $this->$modelClass->importCSV($this->request->data[$modelClass]['CsvFile']['tmp_name']);
    }catch (Exception $e) {
        $import_errors = $this->$modelClass->getImportErrors();
       $this->set('import_errors', $import_errors);
       $this->Session->setFlash(__('Error importing')."  ".$this->request->data[$modelClass]['CsvFile']['name']. ",". __('column mismatch'));
       $this->redirect(array('action' => 'import'));
    }
       $new_records_count = $this->$modelClass->find('count') - $records_count;
        $this->Session->setFlash(__('Successfully imported')."  ". $new_records_count . "  ".'records from' . "  ".$this->request->data[$modelClass]['CsvFile']['name']);
            //$this->redirect(array('action' => 'index'));
  }
    $this->set('modelClass', $modelClass);
   $this->render('../Common/import');

>

1 个答案:

答案 0 :(得分:-2)

确保您的行结尾是您的服务器可以阅读的内容。我被这一百万次烧了......特别是如果使用mac从Excel生成CSV。保存为“csv for windows”。

背景:OS X倾向于使用\r(回车)行结尾保存文件,而Windows使用\r\n(回车,换行)。更糟糕的是,所有其他类Unix系统(例如Linux)往往只使用\n。 因此,如果您在OS X上保存文件并在Windows上打开它,Windows认为该文件只是一个大行。

您可以使用一个好的编辑器(一个可以将空格显示为符号的编程编辑器)或查看文件的实际十六进制代码来验证这一点。