Skip to content

Commit

Permalink
Create xslx Excel file
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Aug 7, 2024
1 parent 9f5468c commit 70c0e68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.sort.SortOrder;
Expand Down Expand Up @@ -56,7 +56,7 @@ public SearchResultGeneration(String filter, boolean showClosedProcesses, boolea
*
* @return HSSFWorkbook
*/
public HSSFWorkbook getResult() {
public XSSFWorkbook getResult() {
return getWorkbook();
}

Expand Down Expand Up @@ -96,11 +96,11 @@ public BoolQueryBuilder getQueryForFilter(ObjectType objectType) {
return query;
}

private HSSFWorkbook getWorkbook() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Search results");
private XSSFWorkbook getWorkbook() {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Search results");

HSSFRow title = sheet.createRow(0);
Row title = sheet.createRow(0);
title.createCell(0).setCellValue(this.filter);
for (int i = 1; i < 8; i++) {
title.createCell(i).setCellValue("");
Expand All @@ -113,7 +113,7 @@ private HSSFWorkbook getWorkbook() {
return workbook;
}

private void insertRowData(HSSFSheet sheet) {
private void insertRowData(Sheet sheet) {
int rowCounter = 2;
long numberOfProcessedProcesses = 0;
int elasticsearchLimit = 9999;
Expand Down Expand Up @@ -149,8 +149,8 @@ private void insertRowData(HSSFSheet sheet) {
}
}

private void setRowHeader(HSSFSheet sheet) {
HSSFRow rowHeader = sheet.createRow(1);
private void setRowHeader(Sheet sheet) {
Row rowHeader = sheet.createRow(1);
rowHeader.createCell(0).setCellValue(Helper.getTranslation("title"));
rowHeader.createCell(1).setCellValue(Helper.getTranslation("ID"));
rowHeader.createCell(2).setCellValue(Helper.getTranslation("Datum"));
Expand All @@ -161,8 +161,8 @@ private void setRowHeader(HSSFSheet sheet) {
rowHeader.createCell(7).setCellValue(Helper.getTranslation("Status"));
}

private void prepareRow(int rowCounter, HSSFSheet sheet, ProcessDTO processDTO) {
HSSFRow row = sheet.createRow(rowCounter);
private void prepareRow(int rowCounter, Sheet sheet, ProcessDTO processDTO) {
Row row = sheet.createRow(rowCounter);
row.createCell(0).setCellValue(processDTO.getTitle());
row.createCell(1).setCellValue(processDTO.getId());
row.createCell(2).setCellValue(processDTO.getCreationDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
import org.apache.lucene.search.join.ScoreMode;
import org.apache.poi.hssf.usermodel.HSSFCell;
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.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
Expand Down Expand Up @@ -1554,9 +1554,9 @@ public void generateResultAsPdf(String filter, boolean showClosedProcesses, bool
try (OutputStream out = response.getResponseOutputStream()) {
SearchResultGeneration sr = new SearchResultGeneration(filter, showClosedProcesses,
showInactiveProjects);
HSSFWorkbook wb = sr.getResult();
XSSFWorkbook wb = sr.getResult();
List<List<HSSFCell>> rowList = new ArrayList<>();
HSSFSheet mySheet = wb.getSheetAt(0);
Sheet mySheet = wb.getSheetAt(0);
Iterator<Row> rowIter = mySheet.rowIterator();
while (rowIter.hasNext()) {
HSSFRow myRow = (HSSFRow) rowIter.next();
Expand Down Expand Up @@ -1596,11 +1596,11 @@ public void generateResult(String filter, boolean showClosedProcesses, boolean s
throws IOException {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (!facesContext.getResponseComplete()) {
ExternalContext response = prepareHeaderInformation(facesContext, "search.xls");
ExternalContext response = prepareHeaderInformation(facesContext, "search.xlsx");
try (OutputStream out = response.getResponseOutputStream()) {
SearchResultGeneration sr = new SearchResultGeneration(filter, showClosedProcesses,
showInactiveProjects);
HSSFWorkbook wb = sr.getResult();
XSSFWorkbook wb = sr.getResult();
wb.write(out);
out.flush();
facesContext.responseComplete();
Expand Down

0 comments on commit 70c0e68

Please sign in to comment.