使用 if - PHP - 修改 excel 个单元格

modify excel cells by using if - PHP -

<?php
require('Classes\PHPExcel.php');

$phpExcel = PHPExcel_IOFactory::load('123.xlsx');
$writer = PHPExcel_IOFactory::createWriter($phpExcel, "Excel2007"); 
$sheet = $phpExcel ->getActiveSheet();

 $x=1;
 while ($x<=5){
     if($sheet->getCell('A'.$x)->getValue()=="1"){
     $sheet->SetCellValue('B'.$x, 'Something');
     }
 }
$writer->save('1234.xlsx');
?>

如果我删除 "while" 和 "if" 行...代码运行完美,并在 1 秒内完成。 但是这样,它无法在 60 秒内完成该过程并发生超时。 123.xlsx 只有 A 列和从 1 到 5 的 5 个数字。这只是为了测试,但又花了这么长时间。 我还是不明白我哪里出错了。

在正常的 123.xlsx 文件中大约有 800 行和 20 列,因此需要数年时间:)

请帮忙

你在哪里递增 $i?

您可能需要增加 $i,根据您的代码要求,您可以在 while 循环或内部 if 中增加 $i :

$x=1;
 while ($x<=5){
     if($sheet->getCell('A'.$x)->getValue()=="1")
     {
         $sheet->SetCellValue('B'.$x, 'Something');
         $x++;//Increment here?
     }
     $x++;//orIncrement here?
 }