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);
}
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();
}
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();
}
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();
}
}
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();
}
}
Aggregations