Search in sources :

Example 96 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project titan.EclipsePlug-ins by eclipse.

the class XlsProblemExporter method createTimeSheet.

/**
 * Create the summary sheet in the exported document.
 *
 * @param workbook the workbook to work in.
 */
private void createTimeSheet(final HSSFWorkbook workbook) {
    final HSSFSheet timeSheet = workbook.createSheet("Repair times");
    workbook.setSheetOrder("Repair times", 1);
    final Row headerRow = timeSheet.createRow(0);
    headerRow.createCell(1).setCellValue("Minimal repair time");
    headerRow.createCell(2).setCellValue("Average repair time");
    headerRow.createCell(3).setCellValue("Maximal repair time");
    int summaryRow = 4;
    Cell label;
    for (final TaskType t : TaskType.values()) {
        final Row row2 = timeSheet.createRow(summaryRow);
        label = row2.createCell(0);
        label.setCellValue(t.getHumanReadableName());
        final Cell minTimeCell = row2.createCell(1);
        minTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        minTimeCell.setCellFormula(t.getMinRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell avgTimeCell = row2.createCell(2);
        avgTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        avgTimeCell.setCellFormula(t.getAvgRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell maxTimeCell = row2.createCell(3);
        maxTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        maxTimeCell.setCellFormula(t.getMaxRepairTime() + "*Summary!$B" + (++summaryRow));
    }
    for (final CodeSmellType t : CodeSmellType.values()) {
        final Row row2 = timeSheet.createRow(summaryRow);
        label = row2.createCell(0);
        label.setCellValue(t.getHumanReadableName());
        final Cell minTimeCell = row2.createCell(1);
        minTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        minTimeCell.setCellFormula(t.getMinRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell avgTimeCell = row2.createCell(2);
        avgTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        avgTimeCell.setCellFormula(t.getAvgRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell maxTimeCell = row2.createCell(3);
        maxTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        maxTimeCell.setCellFormula(t.getMaxRepairTime() + "*Summary!$B" + (++summaryRow));
    }
    final Row totalRow = timeSheet.createRow(1);
    totalRow.createCell(0).setCellValue("Total");
    final Cell cell1 = totalRow.createCell(1);
    cell1.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    cell1.setCellFormula("SUM($B4:$B" + summaryRow + ")");
    final Cell cell2 = totalRow.createCell(2);
    cell2.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    cell2.setCellFormula("SUM($C4:$C" + summaryRow + ")");
    final Cell cell3 = totalRow.createCell(3);
    cell3.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    cell3.setCellFormula("SUM($D4:$D" + summaryRow + ")");
    timeSheet.autoSizeColumn(0);
    timeSheet.autoSizeColumn(1);
    timeSheet.autoSizeColumn(2);
    timeSheet.autoSizeColumn(3);
}
Also used : CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) TaskType(org.eclipse.titanium.markers.types.TaskType) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Row(org.apache.poi.ss.usermodel.Row) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell)

Example 97 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project nextprot-api by calipho-sib.

the class EntryIsoformXLSWriterTest method assertXLSEquals.

private static void assertXLSEquals(ByteArrayOutputStream baos, String[] headers, Object[]... expectedRows) throws IOException {
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    HSSFWorkbook workbook = new HSSFWorkbook(is);
    HSSFSheet worksheet = workbook.getSheet("Isoforms");
    HSSFRow headerRow = worksheet.getRow(0);
    for (int rowIndex = 0; rowIndex < expectedRows.length; rowIndex++) {
        Object[] expectedRow = expectedRows[rowIndex];
        HSSFRow valuesRow = worksheet.getRow(rowIndex + 1);
        for (int i = 0; i < headers.length; i++) {
            Assert.assertEquals(headers[i], headerRow.getCell(i).getStringCellValue());
            if (i > 2)
                Assert.assertEquals(expectedRow[i], valuesRow.getCell(i).getNumericCellValue());
            else
                Assert.assertEquals(expectedRow[i], valuesRow.getCell(i).getStringCellValue());
        }
    }
    workbook.close();
}
Also used : HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 98 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project nextprot-api by calipho-sib.

the class EntryOverviewXLSWriterTest method assertXLSEquals.

private static void assertXLSEquals(ByteArrayOutputStream baos, String[] headers, Object[] values) throws IOException {
    InputStream is = new ByteArrayInputStream(baos.toByteArray());
    HSSFWorkbook workbook = new HSSFWorkbook(is);
    HSSFSheet worksheet = workbook.getSheet("Proteins");
    HSSFRow headerRow = worksheet.getRow(0);
    HSSFRow valuesRow = worksheet.getRow(1);
    for (int i = 0; i < headers.length; i++) {
        Assert.assertEquals(headers[i], headerRow.getCell(i).getStringCellValue());
        if (i >= 7 && i <= 9)
            Assert.assertEquals(values[i], valuesRow.getCell(i).getNumericCellValue());
        else
            Assert.assertEquals(values[i], valuesRow.getCell(i).getStringCellValue());
    }
    workbook.close();
}
Also used : HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 99 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project zoj by licheng.

the class ShowRankListAction method exportToExcel.

private byte[] exportToExcel(AbstractContest contest, List<Problem> problems, RankList ranklist) throws Exception {
    List<RankListEntry> entries = ranklist.getEntries();
    long time = this.getTimeEscaped(contest);
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue(contest.getTitle());
    if (ranklist.getRole() != null) {
        row = sheet.createRow(1);
        cell = row.createCell((short) 0);
        cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        cell.setCellValue(ranklist.getRole().getDescription());
    }
    row = sheet.createRow(2);
    cell = row.createCell((short) 0);
    cell.setCellValue("Length");
    cell = row.createCell((short) 1);
    cell.setCellValue(Utility.toTime(contest.getLength() / 1000));
    row = sheet.createRow(3);
    cell = row.createCell((short) 0);
    cell.setCellValue("Time Escaped");
    cell = row.createCell((short) 1);
    cell.setCellValue(Utility.toTime(time / 1000));
    row = sheet.createRow(5);
    row.createCell((short) 0).setCellValue("Rank");
    row.createCell((short) 1).setCellValue("Handle");
    row.createCell((short) 2).setCellValue("Nickname");
    row.createCell((short) 3).setCellValue("Solved");
    short columnIndex = 4;
    for (Problem problem2 : problems) {
        Problem problem = problem2;
        row.createCell(columnIndex).setCellValue(problem.getCode());
        columnIndex++;
    }
    row.createCell(columnIndex).setCellValue("Penalty");
    int rowIndex = 6;
    for (RankListEntry rankListEntry : entries) {
        RankListEntry entry = rankListEntry;
        row = sheet.createRow(rowIndex);
        row.createCell((short) 0).setCellValue(rowIndex - 5);
        row.createCell((short) 1).setCellValue(entry.getUserProfile().getHandle());
        String nick = entry.getUserProfile().getHandle();
        if (entry.getUserProfile().getNickName() != null) {
            nick = entry.getUserProfile().getNickName();
        }
        cell = row.createCell((short) 2);
        cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        cell.setCellValue(nick);
        row.createCell((short) 3).setCellValue(entry.getSolved());
        for (short i = 0; i < problems.size(); ++i) {
            String score = entry.getAcceptTime(i) > 0 ? entry.getAcceptTime(i) + "(" + entry.getSubmitNumber(i) + ")" : "" + entry.getSubmitNumber(i);
            row.createCell((short) (4 + i)).setCellValue(score);
        }
        row.createCell((short) (4 + problems.size())).setCellValue(entry.getPenalty());
        rowIndex++;
    }
    // output to stream
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        wb.write(out);
        return out.toByteArray();
    } finally {
        out.close();
    }
}
Also used : RankListEntry(cn.edu.zju.acm.onlinejudge.util.RankListEntry) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 100 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project zoj by licheng.

the class UserSearchAction method exportToExcel.

private byte[] exportToExcel(UserCriteria criteria, List<UserProfile> users) throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    short rowId = 0;
    for (Object user : users) {
        HSSFRow row = sheet.createRow(rowId);
        rowId++;
        HSSFCell cell = row.createCell((short) 0);
        cell.setCellValue(((UserProfile) user).getHandle());
    }
    // output to stream
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        wb.write(out);
        return out.toByteArray();
    } finally {
        out.close();
    }
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)213 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)172 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)97 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)84 Test (org.junit.Test)67 FileOutputStream (java.io.FileOutputStream)34 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)27 IOException (java.io.IOException)25 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)25 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)25 File (java.io.File)21 ArrayList (java.util.ArrayList)20 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)20 Row (org.apache.poi.ss.usermodel.Row)18 FileInputStream (java.io.FileInputStream)17 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)15 OutputStream (java.io.OutputStream)14 HashMap (java.util.HashMap)14 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)13 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)12