每个单元格都有不同样式的行.我需要复制它(复制文本,样式,大小).
我正在使用以下功能来执行此操作:
function copyRowFull(&$ws_from, &$ws_to, $row_from, $row_to) {
$ws_to->getRowDimension($row_to)->setRowHeight($ws_from->getRowDimension($row_from)->getRowHeight());
$lastColumn = $ws_from->getHighestColumn();
$rangeFrom = 'A'.$row_from.':'.$lastColumn.$row_from;
// copy text
$ws_to->fromArray($ws_from->rangeToArray($rangeFrom), null, 'A'.$row_to);
// copy style
++$lastColumn;
for ($c = 'A'; $c != $lastColumn; ++$c) {
$ws_to->duplicateStyle($ws_from->getStyle($c.$row_from), $c.$row_to);
}
}
然而它由于循环而非常慢但我需要它很快,因为许多行将被复制.
我也试过这个样式复制:
$rangeTo = 'A'.$row_to.':'.$lastColumn.$row_to;
$ws_to->getStyle($rangeTo)->applyFromArray($ws_from->getStyle($rangeFrom));
但它不起作用 – 抛出错误“传递的样式数组无效”.
有没有更快的方法?