Archived
0

сохранение файла (+fix заполнения ячеек)

This commit is contained in:
2018-06-04 02:19:32 +03:00
parent 0d8df6c849
commit 24c2906053
3 changed files with 38 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -85,7 +86,13 @@ public class Corrector1S {
if (cell == null) break loop; if (cell == null) break loop;
if (r == 6) record.name = cell.getStringCellValue(); if (r == 6) record.name = cell.getStringCellValue();
else if (r == 7) record.addition = (int) cell.getNumericCellValue(); else if (r == 7) {
if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
record.addition = (int) cell.getNumericCellValue();
} else {
record.addition = 0;
}
}
else record.data = cell.getNumericCellValue(); else record.data = cell.getNumericCellValue();
} }
@@ -120,7 +127,7 @@ public class Corrector1S {
} }
cell = sheet.getRow(8).getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); cell = sheet.getRow(8).getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
if (record.addition == 0) { if (record.data == 0) {
cell.setCellType(CellType.BLANK); cell.setCellType(CellType.BLANK);
} else { } else {
cell.setCellType(CellType.NUMERIC); cell.setCellType(CellType.NUMERIC);
@@ -128,7 +135,7 @@ public class Corrector1S {
} }
cell = sheet.getRow(9).getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); cell = sheet.getRow(9).getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
if (record.addition == 0) { if (record.data == 0) {
cell.setCellType(CellType.BLANK); cell.setCellType(CellType.BLANK);
} else { } else {
cell.setCellType(CellType.NUMERIC); cell.setCellType(CellType.NUMERIC);
@@ -158,4 +165,13 @@ public class Corrector1S {
setCellRecord(mapRecords.remove("Месячная премия 2018_186"), c++); setCellRecord(mapRecords.remove("Месячная премия 2018_186"), c++);
setCellRecord(mapRecords.remove("Итого начислено"), c); setCellRecord(mapRecords.remove("Итого начислено"), c);
} }
public void saveFile() throws IOException {
try (FileOutputStream fos = new FileOutputStream(targetFile)) {
workbook.write(fos);
workbook.close();
}
}
} }

View File

@@ -82,6 +82,7 @@ public class Main {
corrector1S.createSnapshotData(); corrector1S.createSnapshotData();
corrector1S.removeMergedCells(); corrector1S.removeMergedCells();
corrector1S.replaceData(); corrector1S.replaceData();
corrector1S.saveFile();
} }
} }
} }

View File

@@ -122,8 +122,12 @@ public class MainController {
} }
}); });
btnSaveAsFilePath.addEventHandler(ActionEvent.ACTION, btnSaveAsFilePath.addEventHandler(ActionEvent.ACTION, event -> {
event -> buildFileChooser(saveAsFilePath).showSaveDialog(stage)); File file = buildFileChooser(saveAsFilePath).showSaveDialog(stage);
if (file != null) {
saveAsFilePath.setText(file.getAbsolutePath());
}
});
btnStartCorrect.addEventHandler(ActionEvent.ACTION, event -> { btnStartCorrect.addEventHandler(ActionEvent.ACTION, event -> {
enableInterface(false); enableInterface(false);
@@ -154,7 +158,7 @@ public class MainController {
try { try {
corrector.createSnapshotData(); corrector.createSnapshotData();
} catch (IOException | InvalidFormatException e) { } catch (Exception e) {
log.error("createSnapshotData", e); log.error("createSnapshotData", e);
buildErrorDialog("Ошибка", "Ошибка при обработке данных", e) buildErrorDialog("Ошибка", "Ошибка при обработке данных", e)
.showAndWait(); .showAndWait();
@@ -168,6 +172,17 @@ public class MainController {
progressBar.setProgress(0.40d); progressBar.setProgress(0.40d);
corrector.replaceData(); corrector.replaceData();
progressBar.setProgress(0.99d);
try {
corrector.saveFile();
} catch (IOException e) {
log.error("saveFile", e);
buildErrorDialog("Ошибка", "Ошибка при сохранении файла", e)
.showAndWait();
enableInterface(true);
return;
}
progressBar.setProgress(1.0d); progressBar.setProgress(1.0d);
buildInfoDialog("Информация", "Преобразование завершено успешно") buildInfoDialog("Информация", "Преобразование завершено успешно")
.showAndWait(); .showAndWait();