2017-06-08 11 views

答えて

0
function stack(){ 
    Include 'PHPExcel_IOFactory'; 
    include 'PHPExcel/IOFactory.php'; 
    $inputFileName = '/example1.xls'; 

    // Read your Excel workbook 
    try { 
     $inputFileType = PHPExcel_IOFactory::identify($inputFileName); 
     $objReader = PHPExcel_IOFactory::createReader($inputFileType); 
     $objPHPExcelOri = $objReader->load($inputFileName); 
    } catch(Exception $e) { 
     die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); 
    } 

    // Get worksheet dimensions 
    $sheet = $objPHPExcelOri->getSheet(0); 
    $highestRow = $sheet->getHighestRow(); 
    $highestColumn = $sheet->getHighestColumn(); 

    // Loop through each row of the worksheet in turn 
    for ($row = 1; $row <= $highestRow; $row++){ 
     // Read a row of data into an array 
     $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, 
             NULL, 
             TRUE, 
             FALSE); 
     // Save data in Array 
     $dataOri[$row]=$rowData[0]; 
    } 


    //NEW EXCEL 
    self::$objPHPExcel->createSheet(); 
    self::$objPHPExcel->setActiveSheetIndex(); 

    $rowNew = 1; 
    foreach ($dataOri as $key => $data) { 
      self::$objPHPExcel->getActiveSheet()->setCellValue( 'A' . $rowNew , $data[1]); 
      self::$objPHPExcel->getActiveSheet()->setCellValue( 'B' . $rowNew , $data[0]); 
      self::$objPHPExcel->getActiveSheet()->setCellValue( 'C' . $rowNew++ , $data[2]); 
    } 

    //Download EXCEL 
    $filename = 'ExcelNew'; 
    $format = 'Excel2007'; 
    $this->saveExcelDownload($format, $filename); 

} 
関連する問題