diff --git a/pom.xml b/pom.xml
index 2b8382d..13cf78e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,41 @@
5
+
+ org.apache.poi
+ poi
+ 5.2.2
+
+
+ org.apache.poi
+ poi-ooxml
+ 5.2.2
+
+
+ org.apache.poi
+ poi-ooxml-schemas
+ 4.1.2
+
+
+ org.apache.poi
+ poi-scratchpad
+ 5.2.2
+
+
+ org.apache.poi
+ ooxml-schemas
+ 1.1
+
+
+ org.apache.logging.log4j
+ log4j-to-slf4j
+ 2.8.2
+
+
+ org.apache.cassandra
+ cassandra-all
+ 4.0.3
+
mysql
mysql-connector-java
diff --git a/report.xlsx b/report.xlsx
new file mode 100644
index 0000000..b896e32
Binary files /dev/null and b/report.xlsx differ
diff --git a/src/main/java/ru/egspt/DataPane.java b/src/main/java/ru/egspt/DataPane.java
index a7a183d..ccb6d2f 100644
--- a/src/main/java/ru/egspt/DataPane.java
+++ b/src/main/java/ru/egspt/DataPane.java
@@ -43,8 +43,9 @@ public class DataPane extends JPanel{
public void setupControlPane(){
controlPane.add(generateXLSXButton);
controlPane.add(generateTXTButton);
- TitledBorder border = new TitledBorder(new LineBorder(Color.black), "ControlPane", TitledBorder.CENTER, TitledBorder.CENTER);
+ TitledBorder border = new TitledBorder(new LineBorder(Color.black), "data-controls-pane", TitledBorder.CENTER, TitledBorder.CENTER);
controlPane.setBorder(border);
+ controlPane.setVisible(false);
}
/**
* Настройка панели пользователей
diff --git a/src/main/java/ru/egspt/ReportControls.java b/src/main/java/ru/egspt/ReportControls.java
new file mode 100644
index 0000000..72844db
--- /dev/null
+++ b/src/main/java/ru/egspt/ReportControls.java
@@ -0,0 +1,12 @@
+package ru.egspt;
+
+public class ReportControls {
+ public static void getExcellReport(App app){
+ System.out.println("Инициировано событие getExcellReport ...");
+ app.getReportPane().getReportTableModel().toExcell();
+ }
+ public static void implantData(App app){
+ System.out.println("Инициировано событие implantData ...");
+
+ }
+}
diff --git a/src/main/java/ru/egspt/ReportPane.java b/src/main/java/ru/egspt/ReportPane.java
index 1dadb59..6039dec 100644
--- a/src/main/java/ru/egspt/ReportPane.java
+++ b/src/main/java/ru/egspt/ReportPane.java
@@ -3,6 +3,7 @@ package ru.egspt;
import java.awt.Color;
import java.awt.BorderLayout;
+import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
@@ -15,20 +16,36 @@ public class ReportPane extends JPanel {
private ReportTableModel reportTableModel;
private JTable reportTable;
private JPanel reportTextPane = new JPanel();
- private JPanel reportSettingsPane = new JPanel();
+ private JPanel reportControlsPane = new JPanel();
+ private JButton getExcellReportButton = new JButton();
+ private JButton implantDataButton = new JButton();
//панель по данным App
public ReportPane(App app){
setupReportTablePane(app.getData());
+ setupReportControlsPane(app);
}
public void init(){
this.setLayout(new BorderLayout());
this.add(reportTablePane, BorderLayout.CENTER);
- //this.add(reportTablePane, BorderLayout.NORTH);
+ this.add(reportControlsPane, BorderLayout.NORTH);
TitledBorder border = new TitledBorder(new LineBorder(Color.black), "report", TitledBorder.CENTER, TitledBorder.CENTER);
this.setBorder(border);
this.setVisible(true);
}
+ public void setupReportControlsPane(App app){
+ getExcellReportButton.setText("create excell");
+ getExcellReportButton.addActionListener(e -> ReportControls.getExcellReport(app));
+ implantDataButton.setText("implant data");
+ implantDataButton.addActionListener(e -> ReportControls.implantData(app));
+
+ reportControlsPane.add(getExcellReportButton);
+ reportControlsPane.add(implantDataButton);
+ TitledBorder border = new TitledBorder(new LineBorder(Color.black), "report-controls-pane", TitledBorder.CENTER, TitledBorder.CENTER);
+ reportControlsPane.setBorder(border);
+ reportControlsPane.setVisible(true);
+
+ }
public void setupReportTablePane(Data report){
reportTableModel = new ReportTableModel(report);
reportTable = new JTable(reportTableModel);
diff --git a/src/main/java/ru/egspt/ReportTableModel.java b/src/main/java/ru/egspt/ReportTableModel.java
index ce7e794..84ed026 100644
--- a/src/main/java/ru/egspt/ReportTableModel.java
+++ b/src/main/java/ru/egspt/ReportTableModel.java
@@ -1,9 +1,19 @@
package ru.egspt;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.time.LocalTime;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReportTableModel extends AbstractTableModel{
private Object[] header;
@@ -172,6 +182,75 @@ public class ReportTableModel extends AbstractTableModel{
public Object[][] getData() {
return data;
}
+ public void toExcell(){
+ System.out.println("Формирование report.xlsx ...");
+ // создание самого excel файла в памяти
+ XSSFWorkbook book = new XSSFWorkbook();
+ // создание листа
+ XSSFSheet sheet = book.createSheet("Report");
+
+ //пишем названия тестов в заголовки xlsx
+ int row = 0;//строка
+ int col = 0;//столбец
+ Row r = sheet.createRow(row);
+ while (col < getHeader().length){
+ r.createCell(col).setCellValue(getHeader()[col].toString());
+ col++;
+ }
+ System.out.println("Заголовки в report.xlsx сформированы.");
+
+ //построчно пишем данные
+ System.out.println("Построчно пишем данные .... ");
+ row++;
+ int userCurr = 0;
+ while (userCurr < getData().length){
+ col = 0;
+ r = sheet.createRow(row);
+ while(col < getHeader().length){
+ Cell c = r.createCell(col);
+ if (getData()[userCurr][col] == null){
+ c.setCellValue("");
+ }
+ else{
+ c.setCellValue(getData()[userCurr][col].toString());
+ }
+ //
+ col++;
+ }
+ userCurr++;
+ row++;
+ }
+ //пишем книгу в файл
+ String location = System.getProperty("user.dir") + "\\report.xlsx";
+ Path path = Paths.get(location);
+ if (Files.exists(path)) {
+ try (FileOutputStream out = new FileOutputStream(location)) {
+ book.write(out);
+ book.close();
+ out.close();
+ System.out.println("Excel файл успешно перезаписан!");
+ System.out.println(location);
+ }
+ catch (IOException e){
+ e.printStackTrace();
+ }
+ }
+ else {
+ try (FileOutputStream out = new FileOutputStream(new File(location))) {
+ book.write(out);
+ book.close();
+ out.close();
+ System.out.println("Excel файл успешно создан!");
+ System.out.println(location);
+ }
+ catch (IOException e){
+ e.printStackTrace();
+ }
+ }
+ }
+ /*
+ * выводим данные модели в консоль
+ */
public void toConsole(){
//заголовки
int i = 0;
diff --git a/target/classes/ru/egspt/DataPane.class b/target/classes/ru/egspt/DataPane.class
index 4c9c13a..639ab9e 100644
Binary files a/target/classes/ru/egspt/DataPane.class and b/target/classes/ru/egspt/DataPane.class differ
diff --git a/target/classes/ru/egspt/ReportControls.class b/target/classes/ru/egspt/ReportControls.class
new file mode 100644
index 0000000..97de558
Binary files /dev/null and b/target/classes/ru/egspt/ReportControls.class differ
diff --git a/target/classes/ru/egspt/ReportPane.class b/target/classes/ru/egspt/ReportPane.class
index 9c4a3da..26da321 100644
Binary files a/target/classes/ru/egspt/ReportPane.class and b/target/classes/ru/egspt/ReportPane.class differ
diff --git a/target/classes/ru/egspt/ReportTableModel.class b/target/classes/ru/egspt/ReportTableModel.class
index 4b9af58..172bcc8 100644
Binary files a/target/classes/ru/egspt/ReportTableModel.class and b/target/classes/ru/egspt/ReportTableModel.class differ