phpexcel保存修改所有工作表

时间:2017-04-03 10:59:08

标签: php phpexcel

我有一个excel文件,大约有40张,其中一些单元格由公式定义。 我阅读了单页的内容并在UI上显示。用户修改后,我使用phpExcel保存将其保存回excel。 但是,当我保存PHPExcel时,save会修改所有带有一些垃圾值的工作表,其中有一个公式单元格。

for ($row = 2; $row <= $highestRow; $row++) {       
        //echo "row=".$row;
        if((sizeof($convertedArr)-1) > $row){
            $jsonRow = $convertedArr[$row];
            $type = PHPExcel_Cell_DataType::TYPE_STRING;                
            $colWrite = 0;              
            for ($col = 0; $col <= $highestColumnIndex; ++$col) {       
                if($sheet->getCellByColumnAndRow($col, $row)->getValue() != 'xxxxx'){
                    //$sheet->setCellValueByColumnAndRow($col, $row,$jsonRow[$col]);
                    $sheet->getCellByColumnAndRow($col, $row)->setValueExplicit($jsonRow[$colWrite], $type);
                    $colWrite++;
                }
            }
        }else{
            break;
        }
    }
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    if(is_writable($siteName)){
        $objWriter->setPreCalculateFormulas(FALSE);
        $objWriter->save($siteName);
    }else{
        echo "File is not Writable";
    }

我该如何处理这种情况。 PHPExcel如何只保存有问题的工作表而不是所有工作表。 我甚至没有遍历所有的床单。

另外,还有一个问题是在保存背景颜色等格式化后!

0 个答案:

没有答案