цветное состояние в экселе

This commit is contained in:
2023-12-07 16:25:16 +03:00
parent 2044ff4320
commit 5ed803cda0
3 changed files with 142 additions and 28 deletions

View File

@@ -4,12 +4,14 @@ import Common.Global;
import Common.UI.UI;
import Common.Utils.Files.VDirectoryChooser;
import Common.Utils.Utils;
import GlobalData.Tasks.TaskState;
import TestingSystem.DVM.Tasks.TestRunTask;
import TestingSystem.DVM.TasksPackage.TasksPackage;
import TestingSystem.DVM.TasksPackage.TasksPackageState;
import Visual_DVM_2021.Passes.Pass_2021;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.*;
@@ -24,8 +26,9 @@ public class ExportTasksPackageToExcel extends Pass_2021<TasksPackage> {
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор папки для сохранения таблицы Excel");
//---
final int max_columns = 13;
CellStyle header_style;
CellStyle regular_style;
Vector<CellStyle> styles;
//--
//--
Workbook book = null;
Sheet sheet = null;
//--
@@ -43,8 +46,7 @@ public class ExportTasksPackageToExcel extends Pass_2021<TasksPackage> {
protected boolean canStart(Object... args) throws Exception {
book = null;
sheet = null;
header_style = null;
regular_style = null;
styles = null;
tasks = null;
//--
if (Current.Check(Log, Current.TasksPackage)) {
@@ -79,36 +81,109 @@ public class ExportTasksPackageToExcel extends Pass_2021<TasksPackage> {
Row row = sheet.createRow(row_num);
int i = 0;
for (Object value : values) {
String cell_text = value.toString();
Cell cell = row.createCell(i);
cell.setCellValue(value.toString());
cell.setCellStyle(isHeader ? header_style : regular_style);
int style_index = 0;
if (!isHeader) {
switch (i) {
case 4:
case 5:
TaskState state = (TaskState) value;
cell_text = state.getDescription();
switch (state) {
case FailedToQueue:
case NoSuchTask:
case AbortedByUser:
case AbortedByTimeout:
case DoneWithErrors:
case WrongTestFormat:
case InternalError:
case Canceled:
style_index = 3;
break;
case Queued:
case Running:
style_index = 5;
break;
case Done:
style_index = 2;
break;
case Crushed:
style_index = 4;
break;
case Finished:
style_index = 6;
break;
}
break;
default:
style_index = 1;
break;
}
}
cell.setCellStyle(styles.get(style_index));
cell.setCellValue(cell_text);
//--
++i;
}
return row;
}
protected void setBorder(CellStyle style, short border) {
style.setBorderBottom(border);
style.setBorderLeft(border);
style.setBorderRight(border);
style.setBorderTop(border);
}
@Override
protected void body() throws Exception {
File file = Utils.getTempFileName("table");
//--
book = new HSSFWorkbook();
sheet = book.createSheet("Результаты тестирования");
header_style = book.createCellStyle();
//---
Font font = book.createFont();//Create font
font.setBold(true);
header_style.setFont(font);
//--
header_style.setBorderBottom(CellStyle.BORDER_THICK);
header_style.setBorderLeft(CellStyle.BORDER_THICK);
header_style.setBorderRight(CellStyle.BORDER_THICK);
header_style.setBorderTop(CellStyle.BORDER_THICK);
//--
regular_style = book.createCellStyle();
regular_style.setBorderBottom(CellStyle.BORDER_THIN);
regular_style.setBorderLeft(CellStyle.BORDER_THIN);
regular_style.setBorderRight(CellStyle.BORDER_THIN);
regular_style.setBorderTop(CellStyle.BORDER_THIN);
styles = new Vector<>();
//0 - заголовок
//1 - черный
//2 - зеленый
//3 - красный
//4 - темно красный
//5 - оранжевый
//6 - серый
for (int i = 0; i < 6; ++i) {
CellStyle style = book.createCellStyle();
Font font = book.createFont();
switch (i) {
case 0:
font.setBold(true);
setBorder(style, CellStyle.BORDER_THICK);
break;
default:
setBorder(style, CellStyle.BORDER_THIN);
switch (i) {
case 1:
font.setColor(HSSFColor.BLACK.index);
break;
case 2:
font.setColor(HSSFColor.GREEN.index);
break;
case 3:
font.setColor(HSSFColor.RED.index);
break;
case 4:
font.setColor(HSSFColor.DARK_RED.index);
break;
case 5:
font.setColor(HSSFColor.ORANGE.index);
break;
case 6:
font.setColor(HSSFColor.GREY_40_PERCENT.index);
break;
}
break;
}
style.setFont(font);
styles.add(style);
}
//--
Row header = addRow(0, true,
"Группа",
@@ -132,8 +207,8 @@ public class ExportTasksPackageToExcel extends Pass_2021<TasksPackage> {
task.test_description,
task.language.getDescription(),
task.flags,
task.compilation_state.getDescription(),
task.state.getDescription(),
task.compilation_state,
task.state,
task.compilation_time,
task.matrix,
task.environments,
@@ -168,4 +243,45 @@ public class ExportTasksPackageToExcel extends Pass_2021<TasksPackage> {
}
}
}
/*
short color = HSSFColor.BLACK.index;
String cell_value = null;
switch (i) {
case 4:
case 5:
TaskState state = (TaskState) value;
switch (state) {
case FailedToQueue:
case NoSuchTask:
case AbortedByUser:
case AbortedByTimeout:
case DoneWithErrors:
case WrongTestFormat:
case InternalError:
case Canceled:
color = HSSFColor.RED.index;
break;
case Queued:
case Running:
color = HSSFColor.ORANGE.index;
break;
case Done:
color = HSSFColor.GREEN.index;
break;
case Crushed:
color = HSSFColor.DARK_RED.index;
break;
case Finished:
color = HSSFColor.GREY_40_PERCENT.index;
break;
}
cell_value = state.getDescription();
break;
default:
cell_value = value.toString();
break;
}
font.setColor(color);
regular_style.setFont(font);
*/
}