Archived
0

Первый версия, прототип

This commit is contained in:
2018-05-26 17:52:54 +03:00
parent aa9337c4d2
commit 94f5a6df04
4 changed files with 356 additions and 0 deletions

90
pom.xml Normal file
View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.dmitriymx</groupId>
<artifactId>corrector-1s</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<slf4j.version>1.7.21</slf4j.version>
<log4j.version>2.5</log4j.version>
</properties>
<dependencies>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- COMPONENTS -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
<!-- Fat jar -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<archive>
<manifest>
<mainClass>ru.dmitriymx.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,232 @@
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();
}
}

View File

@@ -0,0 +1,21 @@
package ru.dmitriymx.corrector1s;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.util.List;
@Slf4j
public class Main {
public static void main(String[] args) throws Exception {
File file = new File(args[0]);
File file1 = new File(args[1]);
ExcelReader excelReader = new ExcelReader(file);
List<ExcelReader.ExcelRecord> data = excelReader.getData();
excelReader.correctStyle();
excelReader.correctData(data);
excelReader.insertNewCols();
excelReader.save(file1);
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%-5level] (%t) \{%logger{36}\} %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>