A bug of PHPExcel removeColumn

Topics: Developer Forum, Project Management Forum, User Forum
Oct 24, 2012 at 3:39 AM

     当我在使用 $objPHPExcel->getActiveSheet()->removeColumn('C',200)方法移除C列以后的200列时,得到的结果不太理想,我当前的模板共有17行,而直接使用此方法得到的模板是从C17开始,后面的列并没有移除(17行),查看源码发现,在removeColumn方法中调用了insertNewBefore方法,而在insertNewBefore方法中的以下代码中:

// Clear cells if we are removing columns or rows
		$highestColumn	= $pSheet->getHighestColumn();
		$highestRow	= $pSheet->getHighestRow();

		// 1. Clear column strips if we are removing columns
		if ($pNumCols < 0 && PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2 + $pNumCols > 0) {
			for ($i = 1; $i <= $highestRow-1; ++$i) {
				for ($j = PHPExcel_Cell::columnIndexFromString($beforeColumn) - 1 + $pNumCols; $j <= PHPExcel_Cell::columnIndexFromString($beforeColumn) - 2; ++$j) {
					$coordinate = PHPExcel_Cell::stringFromColumnIndex($j) . $i;
					$pSheet->removeConditionalStyles($coordinate);
					if ($pSheet->cellExists($coordinate)) {
						$pSheet->getCell($coordinate)->setValueExplicit('', PHPExcel_Cell_DataType::TYPE_NULL);
						$pSheet->getCell($coordinate)->setXfIndex(0);
					}
				}
			}
		}
 for循环中使用了$highestRow-1,导致最后一行(17行)没有被"移除".
修改$highestRow-1为$highestRow后 ,removeColumn使用正常了.