以文本格式导入codeigniter中的excel文件

时间:2017-10-26 05:23:24

标签: php excel codeigniter phpexcel

我在codeigniter中通过phpxecel导入excel文件中的数据。我想使用以下代码转换文本中的长数字:

公共功能downloadcsvdata()     {

    $this->load->helper('download');
    $this->load->helper(array('form', 'url'));      
    $this->load->library('PHPReport');


            $this->excel->setActiveSheetIndex(0);

            //name the worksheet
            $this->excel->getActiveSheet()->setTitle('Finance Players');

            //set cell A1 content with some text
            $this->excel->getActiveSheet()->setCellValue('A1', 'Transaction Type (N - NFET, R - RTGS)');
            $this->excel->getActiveSheet()->setCellValue('B1', 'Beneficiary Code');
            $this->excel->getActiveSheet()->setCellValue('C1', 'Beneficiary Account Number');
            $this->excel->getActiveSheet()->setCellValue('D1', 'Instrument Amount');
            $this->excel->getActiveSheet()->setCellValue('E1', 'Beneficiary First Name & Last Name');
            $this->excel->getActiveSheet()->setCellValue('F1', 'Drawee Location');
            $this->excel->getActiveSheet()->setCellValue('G1', 'Print Location');
            $this->excel->getActiveSheet()->setCellValue('H1', 'Bene Address 1');
            $this->excel->getActiveSheet()->setCellValue('I1', 'Bene Address 2');
            $this->excel->getActiveSheet()->setCellValue('J1', 'Bene Address 3');
            $this->excel->getActiveSheet()->setCellValue('K1', 'Bene Address 4');
            $this->excel->getActiveSheet()->setCellValue('L1', 'Bene Address 5');
            $this->excel->getActiveSheet()->setCellValue('M1', 'Instruction Reference Number');
            $this->excel->getActiveSheet()->setCellValue('N1', 'Customer Reference Number');
            $this->excel->getActiveSheet()->setCellValue('O1', 'Payment details 1');
            $this->excel->getActiveSheet()->setCellValue('P1', 'Payment details 2');
            $this->excel->getActiveSheet()->setCellValue('Q1', 'Payment details 3');
            $this->excel->getActiveSheet()->setCellValue('R1', 'Payment details 4');
            $this->excel->getActiveSheet()->setCellValue('S1', 'Payment details 5');
            $this->excel->getActiveSheet()->setCellValue('T1', 'Payment details 6');
            $this->excel->getActiveSheet()->setCellValue('U1', 'Payment details 7');
            $this->excel->getActiveSheet()->setCellValue('V1', 'Cheque Number');
            $this->excel->getActiveSheet()->setCellValue('W1', 'Chq / Trn Date');
            $this->excel->getActiveSheet()->setCellValue('X1', 'MICR Number');
            $this->excel->getActiveSheet()->setCellValue('Y1', 'IFSC Code');
            $this->excel->getActiveSheet()->setCellValue('Z1', 'Bene Bank Name');
            $this->excel->getActiveSheet()->setCellValue('AA1', 'Bene Bank Branch Name');
            $this->excel->getActiveSheet()->setCellValue('AB1', 'Beneficiary email id');






            for($col = ord('A'); $col <= ord('C'); $col++){ 

            $this->excel->getActiveSheet()->getStyle('C1:C500')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

            $this->excel->getActiveSheet()->getStyle(chr($col))->getNumberFormat()->setFormatCode(PHPExcel_Cell_DataType::TYPE_STRING);


            }


            $this->db->select('*'); 
            $this->db->where ('status', '4');
            $query = $this->db->get('tickets');
            $data = $query->result();
            $array23 = array(); 

       foreach ($data as $row){

        $first="";
                $data12 = strtoupper($row->bname);                  
                $array = explode(" ",$data12);                 
                if(in_array("HDFC", $array)){

                   $first = "I";


                }else{

                   $first = "N";


               }               

           $exceldata = array();

                 $exceldata[] =   $first;
                 $exceldata[] =   ""; 
                 $exceldata[] =   "".$row->acno ." ";                                                   
                 $exceldata[] =   $row->amount;                  
                 $exceldata[] =   $row->fname ."  ".$row->lname;  
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                
                 $exceldata[] =   "";                                
                 $exceldata[] =   $row->id ."  ".$row->username;
                 $exceldata[] =   "";   
                 $exceldata[] =   "";   
                 $exceldata[] =   "";   
                 $exceldata[] =   "";   
                 $exceldata[] =   "";   
                 $exceldata[] =   "";   
                 $exceldata[] =   "";   
                 $exceldata[] =   "";
                 $exceldata[] =   date('d/m/Y');
                 $exceldata[] =   "";   
                 $exceldata[] =   $row->ifsc;                     
                 $exceldata[] =   $row->bname;
                 $exceldata[] =   $row->branch;
                 $exceldata[] =   "banking@rummypassion.com";

                 $data12 = $exceldata;

                $array23[] = $data12;  
        }

            $data234 = $array23;
            //print_r($data234);


            //Fill data 
          $this->excel->getActiveSheet()->fromArray($data234, null, 'A2');

             //die(); 

            $filename='finance-players.xlsx';
            $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007'); 
            $objWriter->save('php://output');

            header('Content-Type: text/xlsx');          
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: application/force-download");
            header("Content-Type: application/octet-stream");
            header("Content-Type: application/download");
            header("Content-Disposition: attachment;filename=$filename");
            header("Content-Transfer-Encoding: binary ");  




}

现在,以&#39; 0&#39;开头的列正在转换和显示但是以其他数字(1-9)开头的列是文本格式但没有正确显示(显示为5.01001E + 13)。

1 个答案:

答案 0 :(得分:0)

更改格式单元格(custom - 000000)或excel中的科学