Skip to content

Commit

Permalink
SAK-33346 Signup .xlsx (sakaiproject#4788)
Browse files Browse the repository at this point in the history
  • Loading branch information
axxter99 authored and ottenhoff committed Sep 19, 2017
1 parent 2017d07 commit 37df506
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 50 deletions.
5 changes: 5 additions & 0 deletions signup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
<version>${sakai.poi.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${sakai.poi.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions signup/tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class DownloadEventBean extends SignupMeetingsBean {

private static final String FROM_ORGANIZER_EVENT_PAGE = "orgSignupMeeting";

private static final String DOWNLOAD_EVENT_DETAILS_XLS_FILE_NAME = "EventsWorksheet.xls";
private static final String DOWNLOAD_EVENT_DETAILS_XLS_FILE_NAME = "EventsWorksheet.xlsx";

private static final String DOWNLOAD_EVENT_DETAILS_CSV_FILE_NAME = "EventsWorksheet.csv";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,27 @@

package org.sakaiproject.signup.tool.downloadEvents;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.signup.logic.SakaiFacade;
import org.sakaiproject.signup.model.MeetingTypes;
Expand All @@ -47,24 +64,14 @@
import org.sakaiproject.signup.model.SignupMeeting;
import org.sakaiproject.signup.model.SignupSite;
import org.sakaiproject.signup.model.SignupTimeslot;
import org.sakaiproject.signup.tool.jsf.HtmlSortHeaderRenderer;
import org.sakaiproject.signup.tool.jsf.SignupMeetingWrapper;
import org.sakaiproject.signup.tool.util.SignupBeanConstants;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.time.api.Time;

import org.sakaiproject.user.api.User;
import org.sakaiproject.util.ResourceLoader;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
* <p> This class will provides formatting data to Excel style functionality.
Expand All @@ -76,6 +83,8 @@ public class EventWorksheet implements MeetingTypes, SignupBeanConstants {

private ResourceLoader rb = new ResourceLoader("messages");

private static Logger log = LoggerFactory.getLogger(EventWorksheet.class);

private String[] tabTitles_Organizor;

private String[] tabTitles_Participant;
Expand Down Expand Up @@ -104,8 +113,9 @@ public class EventWorksheet implements MeetingTypes, SignupBeanConstants {
*/
public EventWorksheet(SakaiFacade sakaiFacade) {
this.sakaiFacade = sakaiFacade;
wb = new HSSFWorkbook();
/* could also define wb = new XSSFWorkbook(); */

wb = new XSSFWorkbook();


styles = WorksheetStyleClass.createStyles(wb);

Expand Down Expand Up @@ -425,7 +435,7 @@ private Workbook createShortVersonWorksheet(List<SignupMeetingWrapper> wrappers)
cell = row.getCell(0);
cell.setCellStyle(styles.get("item_left_wrap"));
cell.setCellValue(wrp.getMeeting().getTitle());
Hyperlink sheetLink = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
Hyperlink sheetLink = createHelper.createHyperlink(HyperlinkType.FILE);
String validSheetName = CreateValidWorksheetName(wrp.getMeeting().getTitle(), seqNum, true);
String hlinkAddr = "'" + validSheetName + "'" + "!A1";
sheetLink.setAddress(hlinkAddr);
Expand Down Expand Up @@ -503,13 +513,15 @@ private void createWorksheet(SignupMeetingWrapper wrapper, int serialNum, boolea
// timezone row
Row timezoneRow = sheet.createRow(1);
timezoneRow.setHeightInPoints(16);
log.info("timezoneRow");
for (int i = 1; i <= 7; i++) {
log.info("timezone: " + i);
timezoneRow.createCell(i).setCellStyle(styles.get("tabItem_fields"));
}
Cell timezoneCell = timezoneRow.getCell(2);
timezoneCell.setCellValue("(" + rb.getString("event_timezone") + " " + sakaiFacade.getTimeService().getLocalTimeZone().getID() + ")");
timezoneCell.setCellValue("(" + rb.getString("event_timezone") + " " + sakaiFacade.getTimeService().getLocalTimeZone().getID() + ")");
sheet.addMergedRegion(CellRangeAddress.valueOf("$C$2:$H$2"));

// owner row
Row row = sheet.createRow(2);
row.setHeightInPoints(rowHigh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;

/**
Expand All @@ -52,64 +56,66 @@ public class WorksheetStyleClass {
public static Map<String, CellStyle> createStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style;

//Title
Font titleFont = wb.createFont();
titleFont.setFontHeightInPoints((short) 18);
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
titleFont.setBold(true);
titleFont.setColor(IndexedColors.DARK_BLUE.getIndex());
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(titleFont);
styles.put("title", style);

Font commentTitleFont = wb.createFont();
commentTitleFont.setFontHeightInPoints((short) 12);
commentTitleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
commentTitleFont.setBold(true);
commentTitleFont.setColor(IndexedColors.DARK_BLUE.getIndex());
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(commentTitleFont);
styles.put("commentTitle", style);

Font itemFont = wb.createFont();
itemFont.setFontHeightInPoints((short) 10);
itemFont.setFontName("Trebuchet MS");
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setAlignment(HorizontalAlignment.LEFT);
style.setFont(itemFont);
styles.put("item_left", style);

style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style = wb.createCellStyle();;
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(itemFont);
style.setWrapText(true);
styles.put("item_left_wrap", style);

style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setVerticalAlignment(CellStyle.VERTICAL_TOP);
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.TOP);
style.setFont(itemFont);
style.setWrapText(true);
styles.put("item_left_wrap_top", style);

itemFont.setFontHeightInPoints((short) 10);
itemFont.setFontName("Trebuchet MS");
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(itemFont);
styles.put("tabItem_fields", style);

style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_RIGHT);
style.setAlignment(HorizontalAlignment.RIGHT);
style.setFont(itemFont);
styles.put("item_right", style);

style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(itemFont);
style.setWrapText(true);
styles.put("attendee_layout", style);
Expand All @@ -119,31 +125,31 @@ public static Map<String, CellStyle> createStyles(Workbook wb) {
itemBoldFont.setFontName("Trebuchet MS");
itemBoldFont.setColor(IndexedColors.DARK_BLUE.getIndex());
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setVerticalAlignment(CellStyle.VERTICAL_TOP);
itemBoldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.TOP);
itemBoldFont.setBold(true);
style.setFont(itemBoldFont);
styles.put("item_leftBold", style);

Font tableFont = wb.createFont();
tableFont.setFontHeightInPoints((short) 12);
tableFont.setColor(IndexedColors.WHITE.getIndex());
tableFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
tableFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(tableFont);
styles.put("tabColNames", style);

tableFont.setFontHeightInPoints((short) 10);
tableFont.setColor(IndexedColors.WHITE.getIndex());
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(tableFont);
style.setWrapText(true);
styles.put("header", style);
Expand All @@ -153,13 +159,13 @@ public static Map<String, CellStyle> createStyles(Workbook wb) {
linkFont.setColor(IndexedColors.BLUE.getIndex());
linkFont.setUnderline(Font.U_SINGLE);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(linkFont);
styles.put("hyperLink", style);

style = wb.createCellStyle();
style.setBorderTop(CellStyle.BORDER_THICK);
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.DARK_BLUE.getIndex());
styles.put("tab_endline", style);

Expand Down

0 comments on commit 37df506

Please sign in to comment.