0

一直在尝试遍历 Excel 文档中的工作表。并删除列中的“,”。然后将结果保存在同一个excel文档中。

<?php     
include'../Classes/PHPExcel.php';
include'../Classes/PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');  
$objReader->setReadDataOnly(false); 
//$xlsxfiles=$_SESSION['file'];  
//echo $xlsxfiles;   
$objPHPExcel = $objReader->load('../upload/Test_0.xlsx'); 
$num=$objPHPExcel->getSheetCount() ; 
$sheetnames=$objPHPExcel->getSheetNames() ;  
$objWorksheet = $objPHPExcel->getActiveSheet();  
$highestRow = $objWorksheet->getHighestRow();  
$sheetnum=$num-1;   

for($sl=0;$sl<$sheetnum;$sl++) {  
    for($cl=0;$cl<$highestRow;$cl++){ 
        $clean= $objPHPExcel->setActiveSheetIndex($sl) 
                   ->getCell('C'.$cl);  
        $cleandone=str_replace(',',' ',$clean); 
        $objWorksheet->setCellValue('C'.$cl,$cleandone); 

        $clcolvalD=$objWorksheet->getCell('D'.$cl);
        $clcolvalD=str_replace(',',' ',$clcolvalD);   
        $objWorksheet->setCellValue('D'.$cl,$clcolvalD);  

        $clcolvalE=$objWorksheet->getCell('E'.$cl);  
        $clcolvalE=str_replace(',',' ',$clcolvalE);  
        $objWorksheet->setCellValue('E'.$cl,$clcolvalE); 

        $clcolvalF=$objWorksheet->getCell('F'.$cl);  
        $clcolvalF=str_replace(',',' ',$clcolvalF); 
        $objWorksheet->setCellValue('F'.$cl,$clcolvalF); 

        $clcolvalG=$objWorksheet->getCell('G'.$cl); 
        $clcolvalG=str_replace(',',' ',$clcolvalG);    
        $objWorksheet->setCellValue('G'.$cl,$clcolvalG);

        $clcolvalH=$objWorksheet->getCell('H'.$cl); 
        $clcolvalH=str_replace(',',' ',$clcolvalH); 
        $objWorksheet->setCellValue('H'.$cl,$clcolvalH); 

        $clcolvalI=$objWorksheet->getCell('I'.$cl); 
        $clcolvalI=str_replace(',',' ',$clcolvalI);
        $objWorksheet->setCellValue('I'.$cl,$clcolvalI); 

        $clcolvalJ=$objWorksheet->getCell('J'.$cl);
        $clcolvalJ=str_replace(',',' ',$clcolvalJ); 
        $objWorksheet->setCellValue('J'.$cl,$clcolvalJ);  

        $clcolvalK=$objWorksheet->getCell('K'.$cl); 
        $clcolvalK=str_replace(',',' ',$clcolvalK); 
        $objWorksheet->setCellValue('K'.$cl,$clcolvalK);

        $clcolvalL=$objWorksheet->getCell('L'.$cl);
        $clcolvalL=str_replace(',',' ',$clcolvalL); 
        $objWorksheet->setCellValue('L'.$cl,$clcolvalL);   

        $clcolvalM=$objWorksheet->getCell('M'.$cl);   
        $clcolvalM=str_replace(',',' ',$clcolvalM);
        $objWorksheet->setCellValue('M'.$cl,$clcolvalM);

        $clcolvalN=$objWorksheet->getCell('N'.$cl);   
        $clcolvalN=str_replace(',',' ',$clcolvalN);   
        $objWorksheet->setCellValue('N'.$cl,$clcolvalN); 
    }  

} 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('../upload/Test_0.xlsx');    
?>
4

0 回答 0