Skip to content

Commit

Permalink
SAK-33372 Poi 3.17, Removal of deprecated classes and methods (sakaip…
Browse files Browse the repository at this point in the history
  • Loading branch information
axxter99 authored and ern committed Sep 19, 2017
1 parent b93494a commit b29c120
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.sakaiproject.util.Validator;

Expand Down Expand Up @@ -133,7 +135,7 @@ private HSSFCellStyle createHeaderStyle(){
HSSFFont font = gradesWorkbook.createFont();
font.setFontName(HSSFFont.FONT_ARIAL);
font.setColor(IndexedColors.PLUM.getIndex());
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setBold(true);
HSSFCellStyle cellStyle = gradesWorkbook.createCellStyle();
cellStyle.setFont(font);
return cellStyle;
Expand All @@ -156,7 +158,7 @@ public SpreadsheetExporter addRow(String... values) {
HSSFRow dataRow = dataSheet.createRow(rowCount++);
for (int i = 0; i < values.length; i++) {
HSSFCell cell = dataRow.createCell(i);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellType(CellType.STRING);
cell.setCellValue(values[i]);
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
Expand Down Expand Up @@ -67,32 +68,31 @@ public void writeDataToResponse(List<List<Object>> spreadsheetData, String fileN
}
}

private HSSFWorkbook getAsWorkbook(List<List<Object>> spreadsheetData) {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFCellStyle headerCs = wb.createCellStyle();
private Workbook getAsWorkbook(List<List<Object>> spreadsheetData) {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
CellStyle headerCs = wb.createCellStyle();
Iterator<List<Object>> dataIter = spreadsheetData.iterator();

// Set the header style
headerCs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
headerCs.setBorderBottom(BorderStyle.THICK);
headerCs.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);

// Set the font
HSSFCellStyle cellStyle = null;
CellStyle cellStyle = null;
String fontName = ServerConfigurationService.getString("spreadsheet.font");
if (fontName != null) {
HSSFFont font = wb.createFont();
Font font = wb.createFont();
font.setFontName(fontName);
headerCs.setFont(font);
cellStyle = wb.createCellStyle();
cellStyle.setFont(font);
}

// By convention, the first list in the list contains column headers.
HSSFRow headerRow = sheet.createRow((short)0);
Row headerRow = sheet.createRow((short)0);
List<Object> headerList = dataIter.next();
for (short i = 0; i < headerList.size(); i++) {
HSSFCell headerCell = createCell(headerRow, i);
Cell headerCell = createCell(headerRow, i);
headerCell.setCellValue((String)headerList.get(i));
headerCell.setCellStyle(headerCs);
sheet.autoSizeColumn(i);
Expand All @@ -101,9 +101,9 @@ private HSSFWorkbook getAsWorkbook(List<List<Object>> spreadsheetData) {
short rowPos = 1;
while (dataIter.hasNext()) {
List<Object> rowData = dataIter.next();
HSSFRow row = sheet.createRow(rowPos++);
Row row = sheet.createRow(rowPos++);
for (short i = 0; i < rowData.size(); i++) {
HSSFCell cell = createCell(row, i);
Cell cell = createCell(row, i);
Object data = rowData.get(i);
if (data != null) {
if (data instanceof Double) {
Expand All @@ -121,8 +121,8 @@ private HSSFWorkbook getAsWorkbook(List<List<Object>> spreadsheetData) {
return wb;
}

private HSSFCell createCell(HSSFRow row, short column) {
HSSFCell cell = row.createCell(Integer.valueOf(column).intValue());
private Cell createCell(Row row, short column) {
Cell cell = row.createCell(Integer.valueOf(column).intValue());
return cell;
}

Expand Down
2 changes: 1 addition & 1 deletion master/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<sakai.xerces.api.version>2.6.2</sakai.xerces.api.version>
<sakai.log4j.version>1.2.17</sakai.log4j.version>
<sakai.slf4j.version>1.7.21</sakai.slf4j.version>
<sakai.poi.version>3.16</sakai.poi.version>
<sakai.poi.version>3.17</sakai.poi.version>
<sakai.mockito.version>2.7.22</sakai.mockito.version>
<sakai.powermock.version>1.7.0RC4</sakai.powermock.version>
<sakai.okiosid.version>2.0</sakai.okiosid.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public Workbook getAsWorkbook(List<List<Object>> spreadsheetData) {

CellStyle boldStyle = wb.createCellStyle();
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setBold(true);
String fontName = ServerConfigurationService.getString("spreadsheet.font");
if (fontName != null) {
font.setFontName(fontName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,7 @@ public Workbook getAsWorkbook(List<List<Object>> spreadsheetData) {

CellStyle boldStyle = wb.createCellStyle();
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setBold(true);
boldStyle.setFont(font);
CellStyle headerStyle = boldStyle;

Expand Down

0 comments on commit b29c120

Please sign in to comment.