add main class

This commit is contained in:
hmdrzsharifi 2021-02-15 23:56:47 +03:30
parent 82023cf57a
commit 74c7e4ec19
1 changed files with 21 additions and 0 deletions

View File

@ -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;
}
}