douge3830 2018-08-09 18:30
浏览 166
已采纳

PHPExcel:CSV导入时串行融合

I'm trying to import CSV to a SQL base, i'm using Scriptcase CRM.

The importation process seems to kinda work... it echoes the sql input. The first line its ok, but in the second line, the first one fuses, on the thrid the second and first...etc.

NSERT INTO abonado_table (id_abonado,dn,nip,curp_id,cac_id, modelo_id,modalidad,canal_de_venta,folio_abd,status,envio,icc_virtual,encuesta,contacto_id,monto_probable_recarga,fvc_estimada,sim_fisico,recuperada_mdc,equipo_liberado,creado_usr,modificado_usr,creado_fecha,modificado_fecha) VALUES (DEFAULT,'3149902172','7777','102329','104','2060','Prepago','','','5','','','','16','60','2018-07-31','0','','No','admin','rosa.valenzuela','2018-07-30 13:47:00','2018-07-30 13:47:00');
...
INSERT INTO abonado_table (id_abonado,dn,nip,curp_id,cac_id, modelo_id,modalidad,canal_de_venta,folio_abd,status,envio,icc_virtual,encuesta,contacto_id,monto_probable_recarga,fvc_estimada,sim_fisico,recuperada_mdc,equipo_liberado,creado_usr,modificado_usr,creado_fecha,modificado_fecha) VALUES (DEFAULT,'3149902172','7777','102329','104','2060','Prepago','','','5','','','','16','60','2018-07-31','0','','No','admin','rosa.valenzuela','2018-07-30 13:47:00','2018-07-30 13:47:00''9311251885','8888','102330','104','4389','Prepago','','','5','{null}','','','17','60','2018-07-31','0','','Si','admin','rosa.valenzuela','2018-07-30 13:50:00','2018-07-30 13:50:00');
...
INSERT INTO abonado_table (id_abonado,dn,nip,curp_id,cac_id, modelo_id,modalidad,canal_de_venta,folio_abd,status,envio,icc_virtual,encuesta,contacto_id,monto_probable_recarga,fvc_estimada,sim_fisico,recuperada_mdc,equipo_liberado,creado_usr,modificado_usr,creado_fecha,modificado_fecha) VALUES (DEFAULT,'3149902172','7777','102329','104','2060','Prepago','','','5','','','','16','60','2018-07-31','0','','No','admin','rosa.valenzuela','2018-07-30 13:47:00','2018-07-30 13:47:00''9311251885','8888','102330','104','4389','Prepago','','','5','{null}','','','17','60','2018-07-31','0','','Si','admin','rosa.valenzuela','2018-07-30 13:50:00','2018-07-30 13:50:00''4157165854','7777','102331','253','484','Prepago','Especialista','','4','{null}','','','18','60','2018-07-31','0','','','admin','rosa.valenzuela','2018-07-30 0:00:00','2018-07-30 20:20:00');
...

Here's the code, whats wrong?

    $objReader  = new PHPExcel_Reader_CSV();
    $objReader->setReadDataOnly(true);
    $xslpath = "/opt/NetMake/v9/wwwroot/import_xls/".{xsl_input};
    $objPHPExcel = $objReader->load($xslpath);
    $worksheetData  = $objReader->listWorkSheetInfo($xslpath);
    $totalRows  = $worksheetData[0]['totalRows'];
    $totalColumns = $worksheetData[0]['totalColumns'];
    $lastColumn  = $objPHPExcel->getActiveSheet()->getHighestColumn();
    $sheet   = $objPHPExcel->getSheet(0);
    $rowDate  = "";

    for($row=1;$row<=$totalRows;$row++){
     for($column=0;$column<$totalColumns;$column++){
      if($column==$totalColumns-1){
       $rowDate.="'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($column,$row)->getValue())."'";

      }else{
       $rowDate.="'".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($column,$row)->getValue())."',";
      }
     }

         echo "INSERT INTO abonado_table (id_abonado,dn,nip,curp_id,cac_id, modelo_id,modalidad,canal_de_venta,folio_abd,status,envio,icc_virtual,encuesta,contacto_id,monto_probable_recarga,fvc_estimada,sim_fisico,recuperada_mdc,equipo_liberado,creado_usr,modificado_usr,creado_fecha,modificado_fecha) VALUES (DEFAULT,".$rowDate.");<br />...<br />";
}
sc_alert($totalRows." registros agregados!");
  • 写回答

1条回答 默认 最新

  • doutizha7526 2018-08-09 18:45
    关注

    Simple answer. you got your string declaration in the wrong spot Move

         $rowDate  = "";
    

    between

    for($row=1;$row<=$totalRows;$row++){
     for($column=0;$column<$totalColumns;$column++){
    

    So it looks like

    for($row=1;$row<=$totalRows;$row++){
     $rowDate = ""; 
     for($column=0;$column<$totalColumns;$column++){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务安装失败