Skip to content

Commit

Permalink
[DSC-1234] added cell limit. Now if content of the cell is bigger tha…
Browse files Browse the repository at this point in the history
…n limit it will be truncated and end with "..."
  • Loading branch information
aliaksei.bykau committed Sep 12, 2023
1 parent 8264b30 commit a1b6845
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -107,7 +108,12 @@ public void appendValueOnLastRow(String header, String value, String separator)
throw new IllegalArgumentException("Unknown header '" + header + "'");
}
String cellContent = WorkbookUtils.getCellValue(lastRow, column);
createCell(lastRow, column, isEmpty(cellContent) ? value : cellContent + separator + value);
createCell(lastRow, column,
getValueLimitedByLength(isEmpty(cellContent) ? value : cellContent + separator + value));
}

private String getValueLimitedByLength(String value) {
return StringUtils.length(value) > 32726 ? value.substring(0, 32725) + "…" : value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.OutputStream;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
Expand Down Expand Up @@ -45,7 +46,7 @@ protected void writeRows(List<List<String>> rows, OutputStream out) {
int cellCount = 0;
for (String field : row) {
Cell cell = sheetRow.createCell(cellCount++);
cell.setCellValue(field);
cell.setCellValue(StringUtils.length(field) > 32726 ? field.substring(0, 32725) + "…" : field );
}
}

Expand Down

0 comments on commit a1b6845

Please sign in to comment.