Copy selection and paste rowset from one location to another in Excel sheet using PHPExcel
I am trying to cut and copy a series of rows from my excel sheet (about 2346 rows) and paste it down at the bottom of the sheet. I would like to cut and copy 6-80 lines, 331-354 lines and then paste them at the bottom,
I would like to know a good way to accomplish this operation using PHPexcel methods. Please give me some advice.
thank
source to share
Ok, I had almost the same problem (I just wanted to copy and paste the values and style without cutting anything). The solution doesn't seem to be able to be solved here, or anywhere I could find, sooo, this is what I did:
//Copy & paste values of range of cells
$cellValues = $objPHPExcel->getActiveSheet()->rangeToArray('C25:AN26');
$objPHPExcel->getActiveSheet()->fromArray($cellValues, null, 'C89');
(I got the same error Call to undefined method PHPExcel_Worksheet::rangeToArray()
as Maggi above, using Mark, the above code, but for some reason splits it into 2 lines);
and then this silly bit of code to copy and paste the style of the same range:
$i = 2;
while ($i < 55) {
$j = num2char($i);
$k = num2char($i+1);
$objPHPExcel->getActiveSheet()->duplicateStyle($objPHPExcel->getActiveSheet()->getStyle($j.'26:'.$k.'26'), $j.'90:'.$k.'90');
$i++;
}
function num2char($num) {
$numeric = $num % 26;
$letter = chr(65 + $numeric);
$num2 = intval($num / 26);
if ($num2 > 0) {
return num2char($num2 - 1) . $letter;
} else {
return $letter;
}
}
(num2char function taken directly from here )
And then, if you need to cut the original cells, use the function removeRow()
.
source to share