我在excel文档(.xlsx)中有一个表,它用作报告模板。 我想在该模板中,在特定行索引处创建特定数量的新行,并在新行之前复制行的格式/样式。
我尝试了ShiftRows()
方法的各种组合:
sheet.ShiftRows(18, 20, 1); // this inserts one empty line, but doesn't copy the format of the line between 18 and 20.
据我了解此功能,应将第19行(18到20之间)复制并向下移动1次,但不复制第19行的格式。但是,如果我执行以下代码段,则不会创建三个新行:
sheet.ShiftRows(18, 20, 1);
sheet.ShiftRows(18, 20, 1);
sheet.ShiftRows(18, 20, 1);
以下代码段会创建三个新行,但不会复制已移位行的格式:
sheet.ShiftRows(18, 20, 3);
有人知道应如何处理这个问题吗?
答案 0 :(得分:0)
请查看链接How to insert a row between two rows in an existing excel with HSSF (Apache POI)。虽然针对POI库解释了代码,但NPOI和POI的所有功能对于HSSF和XSSF都是常见的。