Archived
0

Удалил ненужный класс

This commit is contained in:
2018-06-04 03:04:28 +03:00
parent 69209dbf63
commit 0d24602c5d

View File

@@ -1,232 +0,0 @@
package ru.dmitriymx.corrector1s;
import lombok.Data;
import lombok.Getter;
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.RegionUtil;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
public class ExcelReader implements Closeable {
public class ExcelRecord {
private String name;
private Double unknownInt;
private Double data;
}
private Workbook workbook;
private Sheet sheet;
public ExcelReader(File file) throws IOException, InvalidFormatException {
workbook = WorkbookFactory.create(file);
sheet = workbook.getSheetAt(0); // берем первый и единственный Лист
}
public List<ExcelRecord> getData() {
List<ExcelRecord> list = new ArrayList<>(18);
for (int c = 10; c < 29; c++) {
ExcelRecord record = new ExcelRecord();
for (int r = 6; r < 9; r++) {
Cell cell = sheet.getRow(r).getCell(c);
if (r == 6) {
record.name = cell.getStringCellValue();
} else if (r == 7) {
record.unknownInt = cell.getNumericCellValue();
} else if (r == 8) {
record.data= cell.getNumericCellValue();
}
}
list.add(record);
}
return list;
}
public void correctStyle() {
// Удаляем сведЕния у ячеек
int x = 0;
while (x < 4) {
for(int m = 0; m < sheet.getNumMergedRegions(); ++m) {
CellRangeAddress cellRangeAddress = sheet.getMergedRegion(m);
if (cellRangeAddress.getFirstRow() == 6 && cellRangeAddress.getFirstColumn() == 23) {
sheet.removeMergedRegion(m);
x++;
break;
}
if (cellRangeAddress.getFirstRow() == 6 && cellRangeAddress.getFirstColumn() == 25) {
sheet.removeMergedRegion(m);
x++;
break;
}
if (cellRangeAddress.getFirstRow() == 6 && cellRangeAddress.getFirstColumn() == 26) {
sheet.removeMergedRegion(m);
x++;
break;
}
if (cellRangeAddress.getFirstRow() == 6 && cellRangeAddress.getFirstColumn() == 27) {
sheet.removeMergedRegion(m);
x++;
break;
}
}
}
sheet.addMergedRegion(new CellRangeAddress(6, 7, 10, 10));
sheet.addMergedRegion(new CellRangeAddress(6, 7, 11, 11));
sheet.addMergedRegion(new CellRangeAddress(6, 7, 14, 14));
sheet.addMergedRegion(new CellRangeAddress(6, 7, 22, 22));
}
private void _set_data(ExcelRecord record, int col) {
sheet.getRow(6).getCell(col).setCellValue(record.name);
sheet.getRow(7).getCell(col).setCellValue(record.unknownInt);
sheet.getRow(8).getCell(col).setCellValue(record.data);
sheet.getRow(9).getCell(col).setCellValue(record.data);
if (record.data == 0.0d) {
sheet.getRow(8).getCell(col).setCellType(CellType.BLANK);
sheet.getRow(9).getCell(col).setCellType(CellType.BLANK);
}
}
public void correctData(List<ExcelRecord> listOfData) {
_set_data(listOfData.get(0), 12);
_set_data(listOfData.get(1), 13);
_set_data(listOfData.get(2), 15);
_set_data(listOfData.get(3), 16);
_set_data(listOfData.get(4), 17);
_set_data(listOfData.get(5), 18);
_set_data(listOfData.get(6), 19);
_set_data(listOfData.get(7), 20);
_set_data(listOfData.get(8), 21);
_set_data(listOfData.get(9), 23);
_set_data(listOfData.get(10), 25);
_set_data(listOfData.get(11), 26);
_set_data(listOfData.get(12), 27);
_set_data(listOfData.get(13), 28);
_set_data(listOfData.get(14), 14);
_set_data(listOfData.get(15), 22);
_set_data(listOfData.get(16), 24);
_set_data(listOfData.get(17), 11);
_set_data(listOfData.get(18), 10);
}
public void insertNewCols() {
Font font = workbook.createFont();
font.setFontName("Arial");
font.setBold(true);
font.setFontHeightInPoints((short) 8);
CellStyle 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);
CellStyle cellStyle2 = workbook.createCellStyle();
cellStyle2.setBorderTop(BorderStyle.THIN);
cellStyle2.setBorderBottom(BorderStyle.THIN);
cellStyle2.setBorderLeft(BorderStyle.THIN);
cellStyle2.setBorderRight(BorderStyle.THIN);
Cell cell = sheet.getRow(6).createCell(29);
cell.setCellType(CellType.STRING);
cell.setCellValue("Страховые взносы + ФСС НС (31%)");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(7).createCell(29);
cell.setCellType(CellType.STRING);
cell.setCellValue("Начислено");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(8).createCell(29);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("(AC9-J9)*31%");
cell = sheet.getRow(9).createCell(29);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("(AC10-J10)*31%");
cell = sheet.getRow(6).createCell(30);
cell.setCellType(CellType.STRING);
cell.setCellValue("БАЗА");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(7).createCell(30);
cell.setCellType(CellType.STRING);
cell.setCellValue("для начисления стоимости услуг");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(8).createCell(30);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("AC9+AD9");
cell = sheet.getRow(9).createCell(30);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("AC10+AD10");
cell = sheet.getRow(6).createCell(31);
cell.setCellType(CellType.STRING);
cell.setCellValue("Гонорар");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(7).createCell(31);
cell.setCellType(CellType.STRING);
cell.setCellValue("9%");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(8).createCell(31);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("AE9*9%");
cell = sheet.getRow(9).createCell(31);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("AE10*9%");
cell = sheet.getRow(6).createCell(32);
cell.setCellType(CellType.STRING);
cell.setCellValue("Итого, для счета");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(7).createCell(32);
cell.setCellType(CellType.STRING);
cell.setCellValue("Результат");
cell.setCellStyle(cellStyle1);
cell = sheet.getRow(8).createCell(32);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("AE9+AF9");
cell = sheet.getRow(9).createCell(32);
cell.setCellStyle(cellStyle2);
cell.setCellType(CellType.FORMULA);
cell.setCellFormula("AE10+AF10");
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
}
public void save(File file) throws IOException {
try (FileOutputStream fos = new FileOutputStream(file)) {
workbook.write(fos);
}
}
@Override
public void close() throws IOException {
workbook.close();
}
}