mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +00:00
Merge pull request #245 from rcordovano/master
Added column auto-sizing to spreadsheet table report module (ReportExcel class)
This commit is contained in:
commit
daaf6f345f
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2012 Basis Technology Corp.
|
* Copyright 2013 Basis Technology Corp.
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -22,8 +22,6 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.apache.poi.hssf.util.HSSFColor;
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
@ -34,7 +32,6 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
|||||||
public class ReportExcel implements TableReportModule {
|
public class ReportExcel implements TableReportModule {
|
||||||
private static final Logger logger = Logger.getLogger(ReportExcel.class.getName());
|
private static final Logger logger = Logger.getLogger(ReportExcel.class.getName());
|
||||||
private static ReportExcel instance;
|
private static ReportExcel instance;
|
||||||
private Case currentCase;
|
|
||||||
|
|
||||||
private Workbook wb;
|
private Workbook wb;
|
||||||
private Sheet sheet;
|
private Sheet sheet;
|
||||||
@ -42,8 +39,7 @@ public class ReportExcel implements TableReportModule {
|
|||||||
private CellStyle setStyle;
|
private CellStyle setStyle;
|
||||||
private CellStyle elementStyle;
|
private CellStyle elementStyle;
|
||||||
private int rowCount = 2;
|
private int rowCount = 2;
|
||||||
|
private int sheetColCount = 0;
|
||||||
private Map<String, Integer> dataTypes;
|
|
||||||
private String currentDataType;
|
private String currentDataType;
|
||||||
private String reportPath;
|
private String reportPath;
|
||||||
|
|
||||||
@ -66,32 +62,40 @@ public class ReportExcel implements TableReportModule {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void startReport(String path) {
|
public void startReport(String path) {
|
||||||
currentCase = Case.getCurrentCase();
|
|
||||||
|
|
||||||
wb = new XSSFWorkbook();
|
wb = new XSSFWorkbook();
|
||||||
|
|
||||||
|
// TODO: The commented out cell style settings below do not work as desired when
|
||||||
|
// the output file is loaded by MS Excel or OfficeLibre. The font height and weight
|
||||||
|
// settings only work as expected when the output file is loaded by OfficeLibre.
|
||||||
|
// The alignment and text wrap settings appear to have no effect.
|
||||||
titleStyle = wb.createCellStyle();
|
titleStyle = wb.createCellStyle();
|
||||||
titleStyle.setBorderBottom((short) 1);
|
// titleStyle.setBorderBottom((short) 1);
|
||||||
Font titleFont = wb.createFont();
|
Font titleFont = wb.createFont();
|
||||||
titleFont.setFontHeightInPoints((short) 12);
|
titleFont.setFontHeightInPoints((short) 12);
|
||||||
titleStyle.setFont(titleFont);
|
titleStyle.setFont(titleFont);
|
||||||
|
titleStyle.setAlignment(CellStyle.ALIGN_LEFT);
|
||||||
|
titleStyle.setWrapText(true);
|
||||||
|
|
||||||
setStyle = wb.createCellStyle();
|
setStyle = wb.createCellStyle();
|
||||||
Font setFont = wb.createFont();
|
Font setFont = wb.createFont();
|
||||||
setFont.setFontHeightInPoints((short) 14);
|
setFont.setFontHeightInPoints((short) 14);
|
||||||
setFont.setBoldweight((short) 10);
|
setFont.setBoldweight((short) 10);
|
||||||
setStyle.setFont(setFont);
|
setStyle.setFont(setFont);
|
||||||
|
setStyle.setAlignment(CellStyle.ALIGN_LEFT);
|
||||||
|
setStyle.setWrapText(true);
|
||||||
|
|
||||||
elementStyle = wb.createCellStyle();
|
elementStyle = wb.createCellStyle();
|
||||||
elementStyle.setFillBackgroundColor(HSSFColor.LIGHT_YELLOW.index);
|
// elementStyle.setF illBackgroundColor(HSSFColor.LIGHT_YELLOW.index);
|
||||||
Font elementFont = wb.createFont();
|
Font elementFont = wb.createFont();
|
||||||
elementFont.setFontHeightInPoints((short) 14);
|
elementFont.setFontHeightInPoints((short) 14);
|
||||||
elementStyle.setFont(elementFont);
|
elementStyle.setFont(elementFont);
|
||||||
|
elementStyle.setAlignment(CellStyle.ALIGN_LEFT);
|
||||||
|
elementStyle.setWrapText(true);
|
||||||
|
|
||||||
dataTypes = new TreeMap<String, Integer>();
|
|
||||||
this.reportPath = path + getFilePath();
|
this.reportPath = path + getFilePath();
|
||||||
|
|
||||||
// Write the summary
|
// Write the summary
|
||||||
|
Case currentCase = Case.getCurrentCase();
|
||||||
sheet = wb.createSheet("Summary");
|
sheet = wb.createSheet("Summary");
|
||||||
sheet.createRow(0).createCell(0).setCellValue("Case Name:");
|
sheet.createRow(0).createCell(0).setCellValue("Case Name:");
|
||||||
sheet.getRow(0).createCell(1).setCellValue(currentCase.getName());
|
sheet.getRow(0).createCell(1).setCellValue(currentCase.getName());
|
||||||
@ -101,6 +105,8 @@ public class ReportExcel implements TableReportModule {
|
|||||||
sheet.getRow(2).createCell(1).setCellValue(currentCase.getExaminer());
|
sheet.getRow(2).createCell(1).setCellValue(currentCase.getExaminer());
|
||||||
sheet.createRow(3).createCell(0).setCellValue("# of Images:");
|
sheet.createRow(3).createCell(0).setCellValue("# of Images:");
|
||||||
sheet.getRow(3).createCell(1).setCellValue(currentCase.getImageIDs().length);
|
sheet.getRow(3).createCell(1).setCellValue(currentCase.getImageIDs().length);
|
||||||
|
sheet.autoSizeColumn(0);
|
||||||
|
sheet.autoSizeColumn(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,6 +141,8 @@ public class ReportExcel implements TableReportModule {
|
|||||||
sheet = wb.createSheet(title);
|
sheet = wb.createSheet(title);
|
||||||
sheet.setAutobreaks(true);
|
sheet.setAutobreaks(true);
|
||||||
currentDataType = title;
|
currentDataType = title;
|
||||||
|
rowCount = 2;
|
||||||
|
sheetColCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,12 +150,14 @@ public class ReportExcel implements TableReportModule {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void endDataType() {
|
public void endDataType() {
|
||||||
Row temp = sheet.createRow(0);
|
Row row = sheet.createRow(0);
|
||||||
temp.createCell(0).setCellValue("Number of " + currentDataType + " artifacts:");
|
row.createCell(0).setCellValue("Number of " + currentDataType + " artifacts:");
|
||||||
temp.createCell(1).setCellValue(rowCount);
|
row.createCell(1).setCellValue(rowCount);
|
||||||
|
|
||||||
dataTypes.put(currentDataType, rowCount);
|
// Now that the sheet is complete, size the columns to the content.
|
||||||
rowCount = 2;
|
for (int i = 0; i < sheetColCount; ++i) {
|
||||||
|
sheet.autoSizeColumn(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,9 +167,9 @@ public class ReportExcel implements TableReportModule {
|
|||||||
@Override
|
@Override
|
||||||
public void startSet(String setName) {
|
public void startSet(String setName) {
|
||||||
setName = escapeForExcel(setName);
|
setName = escapeForExcel(setName);
|
||||||
Row temp = sheet.createRow(rowCount);
|
Row row = sheet.createRow(rowCount);
|
||||||
temp.setRowStyle(setStyle);
|
row.setRowStyle(setStyle);
|
||||||
temp.createCell(0).setCellValue(setName);
|
row.createCell(0).setCellValue(setName);
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,12 +178,14 @@ public class ReportExcel implements TableReportModule {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void endSet() {
|
public void endSet() {
|
||||||
rowCount++; // Put a space between the sets
|
// Add an empty row as a separator.
|
||||||
|
sheet.createRow(rowCount);
|
||||||
|
rowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignored in Excel Report
|
|
||||||
@Override
|
@Override
|
||||||
public void addSetIndex(List<String> sets) {
|
public void addSetIndex(List<String> sets) {
|
||||||
|
// Ignored in Excel Report
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,9 +195,9 @@ public class ReportExcel implements TableReportModule {
|
|||||||
@Override
|
@Override
|
||||||
public void addSetElement(String elementName) {
|
public void addSetElement(String elementName) {
|
||||||
elementName = escapeForExcel(elementName);
|
elementName = escapeForExcel(elementName);
|
||||||
Row temp = sheet.createRow(rowCount);
|
Row row = sheet.createRow(rowCount);
|
||||||
temp.setRowStyle(elementStyle);
|
row.setRowStyle(elementStyle);
|
||||||
temp.createCell(0).setCellValue(elementName);
|
row.createCell(0).setCellValue(elementName);
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,17 +207,25 @@ public class ReportExcel implements TableReportModule {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void startTable(List<String> titles) {
|
public void startTable(List<String> titles) {
|
||||||
Row temp = sheet.createRow(rowCount);
|
int tableColCount = 0;
|
||||||
temp.setRowStyle(titleStyle);
|
Row row = sheet.createRow(rowCount);
|
||||||
|
row.setRowStyle(titleStyle);
|
||||||
for (int i=0; i<titles.size(); i++) {
|
for (int i=0; i<titles.size(); i++) {
|
||||||
temp.createCell(i).setCellValue(titles.get(i));
|
row.createCell(i).setCellValue(titles.get(i));
|
||||||
|
++tableColCount;
|
||||||
}
|
}
|
||||||
rowCount++;
|
rowCount++;
|
||||||
|
|
||||||
|
if (tableColCount > sheetColCount) {
|
||||||
|
sheetColCount = tableColCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do nothing on end table
|
|
||||||
@Override
|
@Override
|
||||||
public void endTable() {
|
public void endTable() {
|
||||||
|
// Add an empty row as a separator.
|
||||||
|
sheet.createRow(rowCount);
|
||||||
|
rowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user