Bug fix for dates in Excel file

This commit is contained in:
Eugene Livis 2021-08-05 17:26:32 -04:00
parent da1ec9bef6
commit 1a9f8bd888
5 changed files with 16 additions and 5 deletions

View File

@ -15,4 +15,3 @@ ExportRecentFiles_col_header_path=Path
ExportRecentFiles_col_header_sender=Sender ExportRecentFiles_col_header_sender=Sender
ExportRecentFiles_docsTable_tabName=Recently Opened Documents ExportRecentFiles_docsTable_tabName=Recently Opened Documents
ExportRecentFiles_downloadsTable_tabName=Recently Downloads ExportRecentFiles_downloadsTable_tabName=Recently Downloads
ExportRecentFiles_emailParserModuleName=Email Parser

View File

@ -82,4 +82,10 @@ interface CellModel {
* @return The horizontal alignment for the text in the cell. * @return The horizontal alignment for the text in the cell.
*/ */
HorizontalAlign getHorizontalAlignment(); HorizontalAlign getHorizontalAlignment();
/**
* @return The format string to be used with Apache POI during excel
* export or null if none necessary.
*/
String getExcelFormatString();
} }

View File

@ -27,6 +27,7 @@ class DefaultCellModel<T> implements CellModel {
private final T data; private final T data;
private final String text; private final String text;
private CellModel.HorizontalAlign horizontalAlignment; private CellModel.HorizontalAlign horizontalAlignment;
private final String excelFormatString;
/** /**
* Main constructor. * Main constructor.
@ -62,6 +63,7 @@ class DefaultCellModel<T> implements CellModel {
*/ */
DefaultCellModel(T data, Function<T, String> stringConverter, String excelFormatString) { DefaultCellModel(T data, Function<T, String> stringConverter, String excelFormatString) {
this.data = data; this.data = data;
this.excelFormatString = excelFormatString;
if (stringConverter == null) { if (stringConverter == null) {
text = this.data == null ? "" : this.data.toString(); text = this.data == null ? "" : this.data.toString();
@ -85,6 +87,11 @@ class DefaultCellModel<T> implements CellModel {
return horizontalAlignment; return horizontalAlignment;
} }
@Override
public String getExcelFormatString() {
return this.excelFormatString;
}
/** /**
* Sets the horizontal alignment for this cell model. * Sets the horizontal alignment for this cell model.
* *

View File

@ -324,8 +324,8 @@ class ExcelExport {
static Cell createCell(WorksheetEnv env, Row row, int colNum, CellModel cellModel, Optional<CellStyle> cellStyle) { static Cell createCell(WorksheetEnv env, Row row, int colNum, CellModel cellModel, Optional<CellStyle> cellStyle) {
CellStyle cellStyleToUse = cellStyle.orElse(env.getDefaultCellStyle()); CellStyle cellStyleToUse = cellStyle.orElse(env.getDefaultCellStyle());
if (cellModel.getText() != null || cellModel.getHorizontalAlignment() != null) { if (cellModel.getExcelFormatString() != null || cellModel.getHorizontalAlignment() != null) {
cellStyleToUse = env.getCellStyle(new CellStyleKey(cellModel.getText(), cellStyleToUse, cellModel.getHorizontalAlignment())); cellStyleToUse = env.getCellStyle(new CellStyleKey(cellModel.getExcelFormatString(), cellStyleToUse, cellModel.getHorizontalAlignment()));
} }
Object cellData = cellModel.getData(); Object cellData = cellModel.getData();

View File

@ -44,8 +44,7 @@ import org.sleuthkit.datamodel.DataSource;
"ExportRecentFiles_col_head_date=Date", "ExportRecentFiles_col_head_date=Date",
"ExportRecentFiles_col_header_domain=Domain", "ExportRecentFiles_col_header_domain=Domain",
"ExportRecentFiles_col_header_path=Path", "ExportRecentFiles_col_header_path=Path",
"ExportRecentFiles_col_header_sender=Sender", "ExportRecentFiles_col_header_sender=Sender"
"ExportRecentFiles_emailParserModuleName=Email Parser"
}) })
final class ExportRecentFiles { final class ExportRecentFiles {