Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create xlsx Excel file #6174

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.kitodo.data.elasticsearch.index.type.enums.ProcessTypeField;
import org.kitodo.data.exceptions.DataException;
import org.kitodo.production.dto.ProcessDTO;
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 @@ -78,13 +78,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.XML;
Expand Down Expand Up @@ -1561,16 +1559,16 @@ public void generateResultAsPdf(String filter, boolean showClosedProcesses, bool
try (OutputStream out = response.getResponseOutputStream()) {
SearchResultGeneration sr = new SearchResultGeneration(filter, showClosedProcesses,
showInactiveProjects);
HSSFWorkbook wb = sr.getResult();
List<List<HSSFCell>> rowList = new ArrayList<>();
HSSFSheet mySheet = wb.getSheetAt(0);
XSSFWorkbook wb = sr.getResult();
List<List<Cell>> rowList = new ArrayList<>();
Sheet mySheet = wb.getSheetAt(0);
Iterator<Row> rowIter = mySheet.rowIterator();
while (rowIter.hasNext()) {
HSSFRow myRow = (HSSFRow) rowIter.next();
Row myRow = (Row) rowIter.next();
Iterator<Cell> cellIter = myRow.cellIterator();
List<HSSFCell> row = new ArrayList<>();
List<Cell> row = new ArrayList<>();
while (cellIter.hasNext()) {
HSSFCell myCell = (HSSFCell) cellIter.next();
Cell myCell = (Cell) cellIter.next();
row.add(myCell);
}
rowList.add(row);
Expand Down Expand Up @@ -1603,11 +1601,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 Expand Up @@ -1649,15 +1647,15 @@ private ExternalContext prepareHeaderInformation(FacesContext facesContext, Stri
return externalContext;
}

private PdfPTable getPdfTable(List<List<HSSFCell>> rowList) throws DocumentException {
private PdfPTable getPdfTable(List<List<Cell>> rowList) throws DocumentException {
// create formatter for cells with default locale
DataFormatter formatter = new DataFormatter();

PdfPTable table = new PdfPTable(8);
table.setSpacingBefore(20);
table.setWidths(new int[] {4, 1, 2, 1, 1, 1, 2, 2 });
for (List<HSSFCell> row : rowList) {
for (HSSFCell hssfCell : row) {
for (List<Cell> row : rowList) {
for (Cell hssfCell : row) {
String stringCellValue = formatter.formatCellValue(hssfCell);
table.addCell(stringCellValue);
}
Expand Down
Loading