add main class
This commit is contained in:
parent
82023cf57a
commit
74c7e4ec19
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.poi.excel.insert;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class InsertRowHelper {
|
||||
public Workbook insertRowBetweenRows(String fileLocation, int startRow, int rowNumber) throws IOException {
|
||||
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
if (lastRow < startRow) {
|
||||
sheet.createRow(startRow);
|
||||
}
|
||||
sheet.shiftRows(startRow, lastRow, rowNumber, true, true);
|
||||
sheet.createRow(startRow);
|
||||
return workbook;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue