Index: lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelCell.java =================================================================== diff -u -rcbf95a868252401757c61327b3d9a383119ff9b5 -rd5ff5dd962775f0af34015a7ff47db1edd390237 --- lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelCell.java (.../ExcelCell.java) (revision cbf95a868252401757c61327b3d9a383119ff9b5) +++ lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelCell.java (.../ExcelCell.java) (revision d5ff5dd962775f0af34015a7ff47db1edd390237) @@ -20,7 +20,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.util.excel; import org.apache.poi.ss.usermodel.IndexedColors; @@ -39,22 +38,22 @@ public final static int ALIGN_LEFT = 2; public final static int ALIGN_CENTER = 3; public final static int ALIGN_RIGHT = 4; - + public final static int CELL_FORMAT_DEFAULT = 0; public final static int CELL_FORMAT_DATE = 1; public final static int CELL_FORMAT_TIME = 2; public final static int CELL_FORMAT_PERCENTAGE = 3; - + private Object cellValue; private int dataFormat = ExcelCell.CELL_FORMAT_DEFAULT;//default format is 0 private Boolean isBold = false; private IndexedColors color; - private int borderStyle = 0; + private int[] borderStyle = new int[0]; private int alignment = 0; public ExcelCell() { } - + public ExcelCell(Object cellValue) { this.cellValue = cellValue; } @@ -70,13 +69,13 @@ this.color = color; } - public ExcelCell(Object cellValue, int borderStyle) { + public ExcelCell(Object cellValue, int... borderStyle) { this.cellValue = cellValue; this.isBold = false; this.borderStyle = borderStyle; } - public ExcelCell(Object cellValue, Boolean isBold, int borderStyle) { + public ExcelCell(Object cellValue, Boolean isBold, int... borderStyle) { this.cellValue = cellValue; this.isBold = isBold; this.borderStyle = borderStyle; @@ -89,7 +88,7 @@ public void setCellValue(Object cellValue) { this.cellValue = cellValue; } - + public int getDataFormat() { return dataFormat; } @@ -106,19 +105,19 @@ this.isBold = isBold; } - public IndexedColors getColor() { + public IndexedColors getColor() { return color; } public void setColor(IndexedColors color) { this.color = color; } - public int getBorderStyle() { + public int[] getBorderStyle() { return borderStyle; } - public void setBorderStyle(int borderStyle) { + public void setBorderStyle(int[] borderStyle) { this.borderStyle = borderStyle; } Index: lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelRow.java =================================================================== diff -u -r746369b4989a3ccae7c71d6a07bbb79ab4f47689 -rd5ff5dd962775f0af34015a7ff47db1edd390237 --- lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelRow.java (.../ExcelRow.java) (revision 746369b4989a3ccae7c71d6a07bbb79ab4f47689) +++ lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelRow.java (.../ExcelRow.java) (revision d5ff5dd962775f0af34015a7ff47db1edd390237) @@ -7,33 +7,33 @@ /** * Excel row, containing Excel cells. - * + * * @author Andrey Balan */ public class ExcelRow { private boolean isBold = false; private List cells = new ArrayList<>(); - + /** * Return cell value at the specified position in cells list. - * + * * @param index * @return */ public Object getCell(int index) { return cells.get(index).getCellValue(); } - + public ExcelCell addCell(Object cellValue) { ExcelCell cell = new ExcelCell(cellValue); cells.add(cell); return cell; } - + public ExcelCell addPercentageCell(Double cellValue) { return addPercentageCell(cellValue, false, 0); } - + public ExcelCell addPercentageCell(Double cellValue, Boolean isBold, int borderStyle) { ExcelCell cell = new ExcelCell(cellValue); cell.setDataFormat(ExcelCell.CELL_FORMAT_PERCENTAGE); @@ -52,53 +52,55 @@ cells.add(cell); } - public void addCell(Object cellValue, int borderStyle) { + public void addCell(Object cellValue, int... borderStyle) { ExcelCell cell = new ExcelCell(cellValue, borderStyle); cells.add(cell); } - public ExcelCell addCell(Object cellValue, Boolean isBold, int borderStyle) { + public ExcelCell addCell(Object cellValue, Boolean isBold, int... borderStyle) { ExcelCell cell = new ExcelCell(cellValue, isBold, borderStyle); cells.add(cell); return cell; } - + /** * Add one empty cell */ public void addEmptyCell() { ExcelCell cell = new ExcelCell(""); cells.add(cell); } - + /** * Add specified number of empty cell. - * + * * @param numberEmptyCells */ public void addEmptyCells(int numberEmptyCells) { if (numberEmptyCells < 1) { return; } - + for (int i = 0; i < numberEmptyCells; i++) { ExcelCell cell = new ExcelCell(""); cells.add(cell); } } - + public boolean isBold() { return isBold; } public void setBold(boolean isBold) { this.isBold = isBold; } - + public List getCells() { return cells; } + public void setCells(List cells) { - this.cells = cells;; + this.cells = cells; + ; } } Index: lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelUtil.java =================================================================== diff -u -r8e67b6d0ec8fb3999cdc8861665a34a62ead7646 -rd5ff5dd962775f0af34015a7ff47db1edd390237 --- lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelUtil.java (.../ExcelUtil.java) (revision 8e67b6d0ec8fb3999cdc8861665a34a62ead7646) +++ lams_common/src/java/org/lamsfoundation/lams/util/excel/ExcelUtil.java (.../ExcelUtil.java) (revision d5ff5dd962775f0af34015a7ff47db1edd390237) @@ -66,21 +66,13 @@ private static short percentageFormat; private static CellStyle defaultStyle; - private static CellStyle boldStyle; private static CellStyle greenColor; private static CellStyle blueColor; private static CellStyle redColor; private static CellStyle yellowColor; - private static CellStyle borderStyleLeftThin; - private static CellStyle borderStyleLeftThick; - private static CellStyle borderStyleRightThick; - private static CellStyle borderStyleLeftThinBoldFont; - private static CellStyle borderStyleLeftThickBoldFont; - private static CellStyle borderStyleRightThickBoldFont; - private static CellStyle borderStyleBottomThin; - private static CellStyle borderStyleBottomThinBoldFont; + private static Font boldFont; public final static String DEFAULT_FONT_NAME = "Calibri-Regular"; @@ -157,12 +149,10 @@ defaultStyle = workbook.createCellStyle(); defaultStyle.setFont(defaultFont); - //create bold style - boldStyle = workbook.createCellStyle(); - Font boldFont = workbook.createFont(); + //create bold font + boldFont = workbook.createFont(); boldFont.setBold(true); boldFont.setFontName(DEFAULT_FONT_NAME); - boldStyle.setFont(boldFont); //create color style blueColor = workbook.createCellStyle(); @@ -191,32 +181,6 @@ dateFormat = (short) 14;// built-in 0xe format - "m/d/yy" timeFormat = (short) 19;// built-in 0x13 format - "h:mm:ss AM/PM" percentageFormat = workbook.createDataFormat().getFormat(FORMAT_PERCENTAGE); - - //create border style - borderStyleLeftThin = workbook.createCellStyle(); - borderStyleLeftThin.setBorderLeft(BorderStyle.THIN); - borderStyleLeftThin.setFont(defaultFont); - borderStyleLeftThick = workbook.createCellStyle(); - borderStyleLeftThick.setBorderLeft(BorderStyle.THICK); - borderStyleLeftThick.setFont(defaultFont); - borderStyleRightThick = workbook.createCellStyle(); - borderStyleRightThick.setBorderRight(BorderStyle.THICK); - borderStyleRightThick.setFont(defaultFont); - borderStyleLeftThinBoldFont = workbook.createCellStyle(); - borderStyleLeftThinBoldFont.setBorderLeft(BorderStyle.THIN); - borderStyleLeftThinBoldFont.setFont(boldFont); - borderStyleLeftThickBoldFont = workbook.createCellStyle(); - borderStyleLeftThickBoldFont.setBorderLeft(BorderStyle.THICK); - borderStyleLeftThickBoldFont.setFont(boldFont); - borderStyleRightThickBoldFont = workbook.createCellStyle(); - borderStyleRightThickBoldFont.setBorderRight(BorderStyle.THICK); - borderStyleRightThickBoldFont.setFont(boldFont); - borderStyleBottomThin = workbook.createCellStyle(); - borderStyleBottomThin.setBorderBottom(BorderStyle.THIN); - borderStyleBottomThin.setFont(defaultFont); - borderStyleBottomThinBoldFont = workbook.createCellStyle(); - borderStyleBottomThinBoldFont.setBorderBottom(BorderStyle.THIN); - borderStyleBottomThinBoldFont.setFont(boldFont); } private static void createSheet(Workbook workbook, ExcelSheet excelSheet, String dateHeader, @@ -239,15 +203,15 @@ if (isTitleToBePrinted) { ExcelRow excelRow = new ExcelRow(); excelRow.addCell(excelSheet.getSheetName(), true); - ExcelUtil.createRow(excelRow, 0, sheet); + ExcelUtil.createRow(workbook, excelRow, 0, sheet); } // Print current date, if needed if (StringUtils.isNotBlank(dateHeader)) { ExcelRow excelRow = new ExcelRow(); excelRow.addCell(dateHeader); excelRow.addCell(FileUtil.EXPORT_TO_SPREADSHEET_TITLE_DATE_FORMAT.format(new Date())); - ExcelUtil.createRow(excelRow, 1, sheet); + ExcelUtil.createRow(workbook, excelRow, 1, sheet); } int maxCellsNumber = 0; @@ -258,7 +222,7 @@ // in case there is a sheet title or dateHeader available start from 4th row int rowIndexOffset = !isTitleToBePrinted && StringUtils.isBlank(dateHeader) ? 0 : 4; - ExcelUtil.createRow(excelRow, rowIndex + rowIndexOffset, sheet); + ExcelUtil.createRow(workbook, excelRow, rowIndex + rowIndexOffset, sheet); //calculate max column size int cellsNumber = excelRow.getCells().size(); @@ -278,7 +242,7 @@ } } - private static void createRow(ExcelRow excelRow, int rowIndex, Sheet sheet) { + private static void createRow(Workbook workbook, ExcelRow excelRow, int rowIndex, Sheet sheet) { Row row = sheet.createRow(rowIndex); int columnIndex = 0; @@ -316,62 +280,54 @@ } //figure out cell's style - CellStyle cellStyle = defaultStyle; - if (excelCell.isBold() || excelRow.isBold()) { - cellStyle = boldStyle; - } + CellStyle sourceCellStyle = defaultStyle; + if (excelCell.getColor() != null) { switch (excelCell.getColor()) { case BLUE: - cellStyle = blueColor; + sourceCellStyle = blueColor; break; case GREEN: - cellStyle = greenColor; + sourceCellStyle = greenColor; break; case RED: - cellStyle = redColor; + sourceCellStyle = redColor; break; case YELLOW: - cellStyle = yellowColor; + sourceCellStyle = yellowColor; break; default: break; } } - if (excelCell.getBorderStyle() != 0) { - switch (excelCell.getBorderStyle()) { - case ExcelCell.BORDER_STYLE_LEFT_THIN: - if (excelCell.isBold()) { - cellStyle = borderStyleLeftThinBoldFont; - } else { - cellStyle = borderStyleLeftThin; - } - break; - case ExcelCell.BORDER_STYLE_LEFT_THICK: - if (excelCell.isBold()) { - cellStyle = borderStyleLeftThickBoldFont; - } else { - cellStyle = borderStyleLeftThick; - } - break; - case ExcelCell.BORDER_STYLE_RIGHT_THICK: - if (excelCell.isBold()) { - cellStyle = borderStyleRightThickBoldFont; - } else { - cellStyle = borderStyleRightThick; - } - break; - case ExcelCell.BORDER_STYLE_BOTTOM_THIN: - if (excelCell.isBold()) { - cellStyle = borderStyleBottomThinBoldFont; - } else { - cellStyle = borderStyleBottomThin; - } - break; - default: - break; + + // create a clone that can be modified + CellStyle cellStyle = workbook.createCellStyle(); + cellStyle.cloneStyleFrom(sourceCellStyle); + + if (excelCell.isBold() || excelRow.isBold()) { + cellStyle.setFont(boldFont); + } + + if (excelCell.getBorderStyle() != null) { + for (int borderStyle : excelCell.getBorderStyle()) { + switch (borderStyle) { + case ExcelCell.BORDER_STYLE_LEFT_THIN: + cellStyle.setBorderLeft(BorderStyle.THIN); + break; + case ExcelCell.BORDER_STYLE_LEFT_THICK: + cellStyle.setBorderLeft(BorderStyle.THICK); + break; + case ExcelCell.BORDER_STYLE_RIGHT_THICK: + cellStyle.setBorderRight(BorderStyle.THICK); + break; + case ExcelCell.BORDER_STYLE_BOTTOM_THIN: + cellStyle.setBorderBottom(BorderStyle.THIN); + break; + } } } + cell.setCellStyle(cellStyle); //set data format Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/util/SpreadsheetBuilder.java =================================================================== diff -u -r0c9629a1f72086f6b042733e881fdf05f38494e9 -rd5ff5dd962775f0af34015a7ff47db1edd390237 --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/util/SpreadsheetBuilder.java (.../SpreadsheetBuilder.java) (revision 0c9629a1f72086f6b042733e881fdf05f38494e9) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/util/SpreadsheetBuilder.java (.../SpreadsheetBuilder.java) (revision d5ff5dd962775f0af34015a7ff47db1edd390237) @@ -79,7 +79,8 @@ titleRow.addCell(service.getLocalisedMessage("label.learner", null), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); Map criteriaIndexMap = new HashMap<>(); int countNonCommentCriteria = 0; - + Integer ratingCriteriaGroupId = null; + for (RatingCriteria criteria : criterias) { if (!criteria.isCommentRating()) { titleRow.addCell(criteria.getTitle(), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN);