Skip to content

Commit c11d07d

Browse files
committed
add main class
1 parent 0f20715 commit c11d07d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.poi.excel.insert;
2+
3+
import org.apache.poi.ss.usermodel.Sheet;
4+
import org.apache.poi.ss.usermodel.Workbook;
5+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
6+
7+
import java.io.IOException;
8+
9+
public class InsertRowHelper {
10+
public Workbook insertRowBetweenRows(String fileLocation, int startRow, int rowNumber) throws IOException {
11+
Workbook workbook = new XSSFWorkbook(fileLocation);
12+
Sheet sheet = workbook.getSheetAt(0);
13+
int lastRow = sheet.getLastRowNum();
14+
if (lastRow < startRow) {
15+
sheet.createRow(startRow);
16+
}
17+
sheet.shiftRows(startRow, lastRow, rowNumber, true, true);
18+
sheet.createRow(startRow);
19+
return workbook;
20+
}
21+
}

0 commit comments

Comments
 (0)