php PhpExcel - 如何在第 N 行之后插入同一行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12069986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PhpExcel - How insert the same row after row N?
提问by Luciuz
I have php template. this is a empty table (T0 rows) with some footer at the bottom. From php i try to fill the table, but if i had T1 rows (T1 > T0) then trouble appers.
我有php模板。这是一个空表(T0 行),底部有一些页脚。我尝试从 php 填充表格,但如果我有 T1 行(T1 > T0),那么麻烦就出现了。
I beleve that empty table should contains one empty row. And we know this row number. Then we copy this row (insert the same rows) T1 times and fill empty table. Footer goes down. And everything will be ok
我相信空表应该包含一个空行。我们知道这个行号。然后我们复制这一行(插入相同的行)T1 次并填充空表。页脚下降。一切都会好的
Give me an example, how i can do this. Thank you.
给我一个例子,我怎么能做到这一点。谢谢你。
PhpExcel 1.7.6
PHPExcel 1.7.6
回答by sergioviniciuss
Just copying what @markBaker said (so that we can set the solution as an answer):
只需复制@markBaker 所说的(以便我们可以将解决方案设置为答案):
//Insert 10 new rows between rows 1 and 2
$objPHPExcel->getActiveSheet()->insertNewRowBefore(2,10);
Now applying the style of the row 2 to the inserted rows:
现在将第 2 行的样式应用于插入的行:
$objPHPExcel->getActiveSheet()->duplicateStyle($objPHPExcel->getActiveSheet()->getStyle('A1'),'A2:A10');

