сохранение файла (+fix заполнения ячеек)
This commit is contained in:
@@ -9,6 +9,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -85,7 +86,13 @@ public class Corrector1S {
|
||||
if (cell == null) break loop;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -120,7 +127,7 @@ public class Corrector1S {
|
||||
}
|
||||
|
||||
cell = sheet.getRow(8).getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
if (record.addition == 0) {
|
||||
if (record.data == 0) {
|
||||
cell.setCellType(CellType.BLANK);
|
||||
} else {
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
@@ -128,7 +135,7 @@ public class Corrector1S {
|
||||
}
|
||||
|
||||
cell = sheet.getRow(9).getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
if (record.addition == 0) {
|
||||
if (record.data == 0) {
|
||||
cell.setCellType(CellType.BLANK);
|
||||
} else {
|
||||
cell.setCellType(CellType.NUMERIC);
|
||||
@@ -158,4 +165,13 @@ public class Corrector1S {
|
||||
setCellRecord(mapRecords.remove("Месячная премия 2018_186"), c++);
|
||||
setCellRecord(mapRecords.remove("Итого начислено"), c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void saveFile() throws IOException {
|
||||
try (FileOutputStream fos = new FileOutputStream(targetFile)) {
|
||||
workbook.write(fos);
|
||||
workbook.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ public class Main {
|
||||
corrector1S.createSnapshotData();
|
||||
corrector1S.removeMergedCells();
|
||||
corrector1S.replaceData();
|
||||
corrector1S.saveFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +122,12 @@ public class MainController {
|
||||
}
|
||||
});
|
||||
|
||||
btnSaveAsFilePath.addEventHandler(ActionEvent.ACTION,
|
||||
event -> buildFileChooser(saveAsFilePath).showSaveDialog(stage));
|
||||
btnSaveAsFilePath.addEventHandler(ActionEvent.ACTION, event -> {
|
||||
File file = buildFileChooser(saveAsFilePath).showSaveDialog(stage);
|
||||
if (file != null) {
|
||||
saveAsFilePath.setText(file.getAbsolutePath());
|
||||
}
|
||||
});
|
||||
|
||||
btnStartCorrect.addEventHandler(ActionEvent.ACTION, event -> {
|
||||
enableInterface(false);
|
||||
@@ -154,7 +158,7 @@ public class MainController {
|
||||
|
||||
try {
|
||||
corrector.createSnapshotData();
|
||||
} catch (IOException | InvalidFormatException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("createSnapshotData", e);
|
||||
buildErrorDialog("Ошибка", "Ошибка при обработке данных", e)
|
||||
.showAndWait();
|
||||
@@ -168,6 +172,17 @@ public class MainController {
|
||||
progressBar.setProgress(0.40d);
|
||||
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);
|
||||
buildInfoDialog("Информация", "Преобразование завершено успешно")
|
||||
.showAndWait();
|
||||
|
||||
Reference in New Issue
Block a user