Вставка новых колонок
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -33,6 +34,9 @@ public class Corrector1S {
|
||||
private Map<String, ExcelRecord> mapRecords;
|
||||
private Workbook workbook;
|
||||
private Sheet sheet;
|
||||
private int cellNumSum = 0;
|
||||
private int lastColumn = 0;
|
||||
private CellStyle cellStyle1, cellStyle2;
|
||||
|
||||
private String getFileExtension(File file) {
|
||||
int i = file.getAbsolutePath().lastIndexOf('.');
|
||||
@@ -163,10 +167,110 @@ public class Corrector1S {
|
||||
setCellRecord(mapRecords.remove("сверхурочные 2_181"), c++);
|
||||
setCellRecord(mapRecords.remove("Компенсация за неиспользованный отпуск (с декабря 2017)_184"), c++);
|
||||
setCellRecord(mapRecords.remove("Месячная премия 2018_186"), c++);
|
||||
setCellRecord(mapRecords.remove("Итого начислено"), c);
|
||||
setCellRecord(mapRecords.remove("Итого начислено"), c++);
|
||||
cellNumSum = c-1;
|
||||
|
||||
if (mapRecords.size() > 0) {
|
||||
for (ExcelRecord record : mapRecords.values()) {
|
||||
setCellRecord(record, c++);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastColumn = c;
|
||||
}
|
||||
|
||||
private void initStyle() {
|
||||
Font font = workbook.createFont();
|
||||
font.setFontName("Arial");
|
||||
font.setBold(true);
|
||||
font.setFontHeightInPoints((short) 8);
|
||||
|
||||
cellStyle1 = workbook.createCellStyle();
|
||||
cellStyle1.setAlignment(HorizontalAlignment.CENTER);
|
||||
cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
cellStyle1.setFont(font);
|
||||
cellStyle1.setWrapText(true);
|
||||
cellStyle1.setBorderTop(BorderStyle.THIN);
|
||||
cellStyle1.setBorderBottom(BorderStyle.THIN);
|
||||
cellStyle1.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle1.setBorderRight(BorderStyle.THIN);
|
||||
|
||||
cellStyle2 = workbook.createCellStyle();
|
||||
cellStyle2.setBorderTop(BorderStyle.THIN);
|
||||
cellStyle2.setBorderBottom(BorderStyle.THIN);
|
||||
cellStyle2.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle2.setBorderRight(BorderStyle.THIN);
|
||||
}
|
||||
|
||||
private void insertCell(String title, String addition, String formula1, String formula2, int columnNumber) {
|
||||
Cell cell = sheet.getRow(6).createCell(columnNumber);
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue(title);
|
||||
cell.setCellStyle(cellStyle1);
|
||||
|
||||
cell = sheet.getRow(7).createCell(columnNumber);
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue(addition);
|
||||
cell.setCellStyle(cellStyle1);
|
||||
|
||||
cell = sheet.getRow(8).createCell(columnNumber);
|
||||
cell.setCellStyle(cellStyle2);
|
||||
cell.setCellType(CellType.FORMULA);
|
||||
cell.setCellFormula(formula1);
|
||||
|
||||
cell = sheet.getRow(9).createCell(columnNumber);
|
||||
cell.setCellStyle(cellStyle2);
|
||||
cell.setCellType(CellType.FORMULA);
|
||||
cell.setCellFormula(formula2);
|
||||
}
|
||||
|
||||
public void insertNewCols() {
|
||||
initStyle();
|
||||
|
||||
int column = lastColumn;
|
||||
insertCell(
|
||||
"Страховые взносы + ФСС НС (31%)",
|
||||
"Начислено",
|
||||
String.format("(%s9-J9)*31%%", CellReference.convertNumToColString(cellNumSum)),
|
||||
String.format("(%s10-J10)*31%%", CellReference.convertNumToColString(cellNumSum)),
|
||||
column++
|
||||
);
|
||||
insertCell(
|
||||
"БАЗА",
|
||||
"для начисления стоимости услуг",
|
||||
String.format("%s9+%s9",
|
||||
CellReference.convertNumToColString(cellNumSum),
|
||||
CellReference.convertNumToColString(column-1)),
|
||||
String.format("%s10+%s10",
|
||||
CellReference.convertNumToColString(cellNumSum),
|
||||
CellReference.convertNumToColString(column-1)),
|
||||
column++
|
||||
);
|
||||
insertCell(
|
||||
"Гонорар",
|
||||
(int)this.honorarium + "%",
|
||||
String.format("%s9*%d%%",
|
||||
CellReference.convertNumToColString(column-1),
|
||||
(int)this.honorarium),
|
||||
String.format("%s10*%d%%",
|
||||
CellReference.convertNumToColString(column-1),
|
||||
(int)this.honorarium),
|
||||
column++
|
||||
);
|
||||
insertCell(
|
||||
"Итого, для счета",
|
||||
"Результат",
|
||||
String.format("%s9+%s9",
|
||||
CellReference.convertNumToColString(column-2),
|
||||
CellReference.convertNumToColString(column-1)),
|
||||
String.format("%s10+%s10",
|
||||
CellReference.convertNumToColString(column-2),
|
||||
CellReference.convertNumToColString(column-1)),
|
||||
column
|
||||
);
|
||||
|
||||
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
||||
}
|
||||
|
||||
public void saveFile() throws IOException {
|
||||
try (FileOutputStream fos = new FileOutputStream(targetFile)) {
|
||||
|
||||
@@ -82,6 +82,7 @@ public class Main {
|
||||
corrector1S.createSnapshotData();
|
||||
corrector1S.removeMergedCells();
|
||||
corrector1S.replaceData();
|
||||
corrector1S.insertNewCols();
|
||||
corrector1S.saveFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class MainController {
|
||||
}
|
||||
corrector.setHonorarium(gonorar.getValue());
|
||||
|
||||
progressBar.setProgress(0.10d);
|
||||
progressBar.setProgress(0.14d);
|
||||
|
||||
try {
|
||||
corrector.check();
|
||||
@@ -154,7 +154,7 @@ public class MainController {
|
||||
return;
|
||||
}
|
||||
|
||||
progressBar.setProgress(0.20d);
|
||||
progressBar.setProgress(0.28d);
|
||||
|
||||
try {
|
||||
corrector.createSnapshotData();
|
||||
@@ -166,12 +166,15 @@ public class MainController {
|
||||
return;
|
||||
}
|
||||
|
||||
progressBar.setProgress(0.30d);
|
||||
progressBar.setProgress(0.42d);
|
||||
corrector.removeMergedCells();
|
||||
|
||||
progressBar.setProgress(0.40d);
|
||||
progressBar.setProgress(0.56d);
|
||||
corrector.replaceData();
|
||||
|
||||
progressBar.setProgress(0.70d);
|
||||
corrector.insertNewCols();
|
||||
|
||||
progressBar.setProgress(0.99d);
|
||||
try {
|
||||
corrector.saveFile();
|
||||
|
||||
Reference in New Issue
Block a user