简体   繁体   中英

Importing excel file in codeigniter in text format

Im importing data in excel file by phpxecel in codeigniter. I want to convert the long numbers in text for which im using the code as follows:

public function 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 ");  




}

Now, columns starting with '0' are converting and displaying properly but the columns starting with other digits (1-9) are in text format but not displaying properly (displaying as 5.01001E+13).

更改格式单元格(自定义 - 000000 )或 Excel 中的科学

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM