-
Notifications
You must be signed in to change notification settings - Fork 63
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
Merged
Merged
Create xlsx Excel file #6174
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.streaming.SXSSFWorkbook; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.json.XML; | ||
|
@@ -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); | ||
SXSSFWorkbook 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); | ||
|
@@ -1587,6 +1585,7 @@ public void generateResultAsPdf(String filter, boolean showClosedProcesses, bool | |
} | ||
|
||
document.close(); | ||
wb.close(); | ||
out.flush(); | ||
facesContext.responseComplete(); | ||
} | ||
|
@@ -1603,12 +1602,13 @@ 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(); | ||
SXSSFWorkbook wb = sr.getResult(); | ||
wb.write(out); | ||
wb.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wb.close() now also deletes temporary files from disk. https://poi.apache.org/changes.html#5.3.0 |
||
out.flush(); | ||
facesContext.responseComplete(); | ||
} | ||
|
@@ -1649,15 +1649,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); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wb.close() now also deletes temporary files from disk. https://poi.apache.org/changes.html#5.3.0